Title: Stubtest crashes on a stub with an overloaded method where the first overload is decorated with `@final` · Issue #14950 · python/mypy · GitHub
Open Graph Title: Stubtest crashes on a stub with an overloaded method where the first overload is decorated with `@final` · Issue #14950 · python/mypy
X Title: Stubtest crashes on a stub with an overloaded method where the first overload is decorated with `@final` · Issue #14950 · python/mypy
Description: Optional static typing for Python. Contribute to python/mypy development by creating an account on GitHub.
Open Graph Description: Optional static typing for Python. Contribute to python/mypy development by creating an account on GitHub.
X Description: Optional static typing for Python. Contribute to python/mypy development by creating an account on GitHub.
Opengraph URL: https://github.com/python/mypy
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Stubtest crashes on a stub with an overloaded method where the first overload is decorated with `@final`","articleBody":"**Crash Report**\r\n\r\nIf you run stubtest on a stub with a method like this, stubtest will crash:\r\n\r\n```python\r\nfrom typing import final, overload\r\n\r\nclass C:\r\n @overload\r\n @final\r\n def foo(self, obj: str) -> int: ...\r\n @overload\r\n def foo(self, obj: int) -> str: ...\r\n```\r\n\r\nThe crash occurs regardless of the order in which you stack the `@final` and `@overload` decorator on the first overload. (PEP 591 specifies that for overloaded definitions in stubs, the `@final` decorator should be placed on the first overload, but doesn't specify which order they should be stacked in.)\r\n\r\n**Traceback**\r\n\r\n```pytb\r\nTraceback (most recent call last):\r\n File \"\u003cfrozen runpy>\", line 198, in _run_module_as_main\r\n File \"\u003cfrozen runpy>\", line 88, in _run_code\r\n File \"C:\\Users\\alexw\\AppData\\Local\\Temp\\tmp_p_nrkoa\\Lib\\site-packages\\mypy\\stubtest.py\", line 1823, in \u003cmodule>\r\n sys.exit(main())\r\n ^^^^^^\r\n File \"C:\\Users\\alexw\\AppData\\Local\\Temp\\tmp_p_nrkoa\\Lib\\site-packages\\mypy\\stubtest.py\", line 1819, in main\r\n return test_stubs(parse_options(sys.argv[1:]))\r\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n File \"C:\\Users\\alexw\\AppData\\Local\\Temp\\tmp_p_nrkoa\\Lib\\site-packages\\mypy\\stubtest.py\", line 1692, in test_stubs\r\n for error in test_module(module):\r\n File \"C:\\Users\\alexw\\AppData\\Local\\Temp\\tmp_p_nrkoa\\Lib\\site-packages\\mypy\\stubtest.py\", line 218, in test_module\r\n yield from verify(stub, runtime, [module_name])\r\n File \"C:\\Users\\alexw\\AppData\\Local\\Temp\\tmp_p_nrkoa\\Lib\\site-packages\\mypy\\stubtest.py\", line 396, in verify_mypyfile\r\n yield from verify(stub_entry, runtime_entry, object_path + [entry])\r\n File \"C:\\Users\\alexw\\AppData\\Local\\Temp\\tmp_p_nrkoa\\Lib\\site-packages\\mypy\\stubtest.py\", line 517, in verify_typeinfo\r\n yield from verify(stub_to_verify, runtime_attr, object_path + [entry])\r\n File \"C:\\Users\\alexw\\AppData\\Local\\Temp\\tmp_p_nrkoa\\Lib\\site-packages\\mypy\\stubtest.py\", line 1050, in verify_overloadedfuncdef\r\n stub_sig = Signature.from_overloadedfuncdef(stub)\r\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n File \"C:\\Users\\alexw\\AppData\\Local\\Temp\\tmp_p_nrkoa\\Lib\\site-packages\\mypy\\stubtest.py\", line 756, in from_overloadedfuncdef\r\n assert func is not None\r\n ^^^^^^^^^^^^^^^^\r\nAssertionError\r\n```\r\n\r\n**To Reproduce**\r\n\r\nTwo ways to reproduce:\r\n\r\n**(1) Apply this diff, and then run `pytest mypy/test/teststubtest.py`:**\r\n\r\n```diff\r\ndiff --git a/mypy/test/teststubtest.py b/mypy/test/teststubtest.py\r\nindex d39812b5f..b7f114b5e 100644\r\n--- a/mypy/test/teststubtest.py\r\n+++ b/mypy/test/teststubtest.py\r\n@@ -1177,6 +1177,24 @@ class StubtestUnit(unittest.TestCase):\r\n \"\"\",\r\n error=\"C\",\r\n )\r\n+ yield Case(\r\n+ stub=\"\"\"\r\n+ from typing import overload\r\n+ from typing_extensions import final\r\n+ class D:\r\n+ @overload\r\n+ @final\r\n+ def foo(self, obj: int) -> str: ...\r\n+ @overload\r\n+ def foo(self, obj: str) -> int: ...\r\n+ \"\"\",\r\n+ runtime=\"\"\"\r\n+ class D:\r\n+ def foo(self, obj):\r\n+ return 42 if isinstance(obj, str) else \"foo\"\r\n+ \"\"\",\r\n+ error=None\r\n+ )\r\n```\r\n\r\n**(2) With a typeshed clone checked out, apply this diff, then run `python tests/stubtest_stdlib.py`:**\r\n\r\n```diff\r\ndiff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi\r\nindex 2c21cd95d..8cdcd3b6a 100644\r\n--- a/stdlib/builtins.pyi\r\n+++ b/stdlib/builtins.pyi\r\n@@ -189,6 +189,7 @@ class type:\r\n\r\n class super:\r\n @overload\r\n+ @final\r\n def __init__(self, __t: Any, __obj: Any) -> None: ...\r\n @overload\r\n def __init__(self, __t: Any) -> None: ...\r\n```\r\n\r\n**Your Environment**\r\n\r\nReproduced with mypy 1.1.1 and mypy @ bfa9eacedb0554e1a6fe9245dbd5ccdbbc555fae\r\n","author":{"url":"https://github.com/AlexWaygood","@type":"Person","name":"AlexWaygood"},"datePublished":"2023-03-23T23:13:36Z","url":"https://github.com/python/mypy/issues/14950"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/issues/:id(.:format) |
| route-controller | issues |
| route-action | show |
| fetch-nonce | v2:fdfa3267-7538-c109-71fe-13ecddf87643 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D1DC:1A3D7F:1C3D04E:245864C:6AFFC31E |
| html-safe-nonce | 291c3ff79f43eb9992211a036a24fe27499d69a7f4f1c3772168b4ab75181a7c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMURDOjFBM0Q3RjoxQzNEMDRFOjI0NTg2NEM6NkFGRkMzMUUiLCJ2aXNpdG9yX2lkIjoiNDY4MzUzNjczNDI3NTc0ODYzOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | db54c4a2b638779d1733a3be7550ceb8c86a05fff9fe145b5887242683c2bdc5 |
| hovercard-subject-tag | repository:7053637 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python/mypy/issues/14950 |
| twitter:image | https://opengraph.githubassets.com/850ce2019117db99c166b712132547c2dade118d4084179fa6a2ee39e584b4de/python/mypy |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/850ce2019117db99c166b712132547c2dade118d4084179fa6a2ee39e584b4de/python/mypy |
| og:image:alt | Optional static typing for Python. Contribute to python/mypy development by creating an account on GitHub. |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 1e805b832df235bb21305db712c3b6432920019dfc12cb25b9cb8d3b0c9403cf |
| turbo-cache-control | no-cache |
| go-import | github.com/python/mypy git https://github.com/python/mypy.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 7053637 |
| octolytics-dimension-repository_nwo | python/mypy |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 7053637 |
| octolytics-dimension-repository_network_root_nwo | python/mypy |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8fa4a54e6871c7908eda1c246ad5972982c0b59d |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width