8000 Fix inference for overloaded __call__ with generic self by hauntsaninja · Pull Request #16053 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Fix inference for overloaded __call__ with generic self #16053

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

Merged
merged 15 commits into from
Sep 19, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
new, bad test
  • Loading branch information
hauntsaninja committed Sep 15, 2023
commit c36efdda7434d351cdf0ff9221789a7549cba9ff
15 changes: 15 additions & 0 deletions test-data/unit/check-tuples.test
Original file line number Diff line number Diff line change
Expand Up @@ -1434,7 +1434,22 @@ def foo(o: CallableTuple) -> int:
class CallableTuple(Tuple[str, int]):
def __call__(self, n: int, m: int) -> int:
return n
[builtins fixtures/tuple.pyi]

[case testTypeTupleGenericCall]
from typing import Generic, Tuple, TypeVar

T = TypeVar('T')

def foo(o: CallableTuple[int]) -> int:
reveal_type(o) # N: Revealed type is "Tuple[builtins.str, builtins.int, fallback=__main__.CallableTuple[builtins.int]]"
reveal_type(o.count(3)) # N: Revealed type is "builtins.int"
# TODO: incorrect error below
return o(1, 2) # E: Invalid self argument "CallableTuple[int]" to attribute function "__call__" with type "Callable[[CallableTuple[T], int, int], int]"

class CallableTuple(Tuple[str, T]):
def __call__(self, n: int, m: int) -> int:
return n
[builtins fixtures/tuple.pyi]

[case testTupleCompatibleWithSequence]
Expand Down
0