Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stubtest mishandles overloads where param is pos-only in one overload #17023

Open
JelleZijlstra opened this issue Mar 14, 2024 · 0 comments · May be fixed by #18287
Open

stubtest mishandles overloads where param is pos-only in one overload #17023

JelleZijlstra opened this issue Mar 14, 2024 · 0 comments · May be fixed by #18287
Labels
bug mypy got something wrong topic-stubtest

Comments

@JelleZijlstra
Copy link
Member

JelleZijlstra commented Mar 14, 2024

The following test case:

diff --git a/mypy/test/teststubtest.py b/mypy/test/teststubtest.py
index 418308e2e..51d222a5c 100644
--- a/mypy/test/teststubtest.py
+++ b/mypy/test/teststubtest.py
@@ -788,6 +788,18 @@ class StubtestUnit(unittest.TestCase):
             """,
             error=None,
         )
+        yield Case(
+            stub="""
+            @overload
+            def f(a: int) -> int: ...
+            @overload
+            def f(a: int, b: str, /) -> str: ...
+            """,
+            runtime="""
+            def f(a, *args): ...
+            """,
+            error=None,
+        )
 
     @collect_cases
     def test_property(self) -> Iterator[Case]:

fails with:

E           AssertionError: error: test_module.f is inconsistent, stub argument "a" has a default value but runtime argument does not
E             Stub: in file test_module.pyi:74
E             Overload(def (a: builtins.int) -> builtins.int, def (builtins.int, builtins.str) -> builtins.str)
E             Inferred signature: def (a: builtins.int = ..., a: builtins.int = ..., b: builtins.str = ...)
E             Runtime: in file test_module.py:26
E             def (a, *args)

I think this should produce no errors. In any case, stubtest's inferred signature is wrong (it repeats the a parameter).

Came up in python/typeshed#11595 where I am dealing with collections.ChainMap.fromkeys.

@JelleZijlstra JelleZijlstra added bug mypy got something wrong topic-stubtest labels Mar 14, 2024
tungol added a commit to tungol/mypy that referenced this issue Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-stubtest
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant