Skip to content

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

Open
@JelleZijlstra

Description

@JelleZijlstra

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions