Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Stubtest crashes on a stub with an overloaded method where the first overload is decorated with@final #14950

Closed
@AlexWaygood

Description

@AlexWaygood

Crash Report

If you run stubtest on a stub with a method like this, stubtest will crash:

fromtypingimportfinal,overloadclassC:@overload@finaldeffoo(self,obj:str)->int: ...@overloaddeffoo(self,obj:int)->str: ...

The 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.)

Traceback

Traceback (most recent call last):  File"<frozen runpy>", line198, in_run_module_as_main  File"<frozen runpy>", line88, in_run_code  File"C:\Users\alexw\AppData\Local\Temp\tmp_p_nrkoa\Lib\site-packages\mypy\stubtest.py", line1823, in<module>    sys.exit(main())^^^^^^  File"C:\Users\alexw\AppData\Local\Temp\tmp_p_nrkoa\Lib\site-packages\mypy\stubtest.py", line1819, inmainreturn test_stubs(parse_options(sys.argv[1:]))^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  File"C:\Users\alexw\AppData\Local\Temp\tmp_p_nrkoa\Lib\site-packages\mypy\stubtest.py", line1692, intest_stubsfor errorin test_module(module):  File"C:\Users\alexw\AppData\Local\Temp\tmp_p_nrkoa\Lib\site-packages\mypy\stubtest.py", line218, intest_moduleyield from verify(stub, runtime, [module_name])  File"C:\Users\alexw\AppData\Local\Temp\tmp_p_nrkoa\Lib\site-packages\mypy\stubtest.py", line396, inverify_mypyfileyield from verify(stub_entry, runtime_entry, object_path+ [entry])  File"C:\Users\alexw\AppData\Local\Temp\tmp_p_nrkoa\Lib\site-packages\mypy\stubtest.py", line517, inverify_typeinfoyield from verify(stub_to_verify, runtime_attr, object_path+ [entry])  File"C:\Users\alexw\AppData\Local\Temp\tmp_p_nrkoa\Lib\site-packages\mypy\stubtest.py", line1050, inverify_overloadedfuncdef    stub_sig= Signature.from_overloadedfuncdef(stub)^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  File"C:\Users\alexw\AppData\Local\Temp\tmp_p_nrkoa\Lib\site-packages\mypy\stubtest.py", line756, infrom_overloadedfuncdefassert funcisnotNone^^^^^^^^^^^^^^^^AssertionError

To Reproduce

Two ways to reproduce:

(1) Apply this diff, and then runpytest mypy/test/teststubtest.py:

diff --git a/mypy/test/teststubtest.py b/mypy/test/teststubtest.pyindex d39812b5f..b7f114b5e 100644--- a/mypy/test/teststubtest.py+++ b/mypy/test/teststubtest.py@@ -1177,6 +1177,24 @@ class StubtestUnit(unittest.TestCase):             """,             error="C",         )+        yield Case(+            stub="""+            from typing import overload+            from typing_extensions import final+            class D:+                @overload+                @final+                def foo(self, obj: int) -> str: ...+                @overload+                def foo(self, obj: str) -> int: ...+            """,+            runtime="""+            class D:+                def foo(self, obj):+                    return 42 if isinstance(obj, str) else "foo"+            """,+            error=None+        )

(2) With a typeshed clone checked out, apply this diff, then runpython tests/stubtest_stdlib.py:

diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyiindex 2c21cd95d..8cdcd3b6a 100644--- a/stdlib/builtins.pyi+++ b/stdlib/builtins.pyi@@ -189,6 +189,7 @@ class type: class super:     @overload+    @final     def __init__(self, __t: Any, __obj: Any) -> None: ...     @overload     def __init__(self, __t: Any) -> None: ...

Your Environment

Reproduced with mypy 1.1.1 and mypy @bfa9eac

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp