-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
implement the mypy/checkexpr.py TODO: Specialize the callable for the type arguments ... so e.g. reveal_type(tuple[int, int]) gives expected def (p0: tuple[builtins.int, builtins.int]) -> tuple[builtins.int, builtins.int] ... rather than def [_T_co] (typing.Iterable[_T_co`1] =) -> builtins.tuple[_T_co`1, ...] Fixes #16935
- Loading branch information
Showing
3 changed files
with
57 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
[case testInferTupleType] | ||
# flags: --python-version 3.9 | ||
from typing import TypeVar, Generic, Type | ||
from abc import abstractmethod | ||
|
||
T = TypeVar('T') | ||
class E(Generic[T]): | ||
@abstractmethod | ||
def e(self, t: T) -> str: | ||
... | ||
|
||
class F: | ||
@abstractmethod | ||
def f(self, tp: Type[T]) -> E[T]: | ||
... | ||
|
||
def g(f: F): | ||
f.f(int).e(7) | ||
f.f(tuple[int,str]) | ||
f.f(tuple[int,str]).e('x') # E: Argument 1 to "e" of "E" has incompatible type "str"; expected "Tuple[int, str]" | ||
f.f(tuple[int,str]).e( (7,8) ) # E: Argument 1 to "e" of "E" has incompatible type "Tuple[int, int]"; expected "Tuple[int, str]" | ||
f.f(tuple[int,str]).e( (7,'x') ) # OK | ||
reveal_type(f.f(tuple[int,str]).e) # N: Revealed type is "def (t: Tuple[builtins.int, builtins.str]) -> builtins.str" | ||
|
||
def h(f: F): | ||
f.f(int).e(7) | ||
f.f(tuple) | ||
f.f(tuple).e('y') # E: Argument 1 to "e" of "E" has incompatible type "str"; expected "Tuple[Any, ...]" | ||
f.f(tuple).e( (8,'y') ) # OK | ||
reveal_type(f.f(tuple).e) # N: Revealed type is "def (t: builtins.tuple[Any, ...]) -> builtins.str" | ||
|
||
def i(f: F): | ||
f.f(tuple[int,tuple[int,str]]) | ||
f.f(tuple[int,tuple[int,str]]).e('z') # E: Argument 1 to "e" of "E" has incompatible type "str"; expected "Tuple[int, Tuple[int, str]]" | ||
f.f(tuple[int,tuple[int,str]]).e( (8,9) ) # E: Argument 1 to "e" of "E" has incompatible type "Tuple[int, int]"; expected "Tuple[int, Tuple[int, str]]" | ||
f.f(tuple[int,tuple[int,str]]).e( (17, (28, 29)) ) # E: Argument 1 to "e" of "E" has incompatible type "Tuple[int, Tuple[int, int]]"; expected "Tuple[int, Tuple[int, str]]" | ||
f.f(tuple[int,tuple[int,str]]).e( (27,(28,'z')) ) # OK | ||
reveal_type(f.f(tuple[int,tuple[int,str]]).e) # N: Revealed type is "def (t: Tuple[builtins.int, Tuple[builtins.int, builtins.str]]) -> builtins.str" | ||
|
||
x = tuple[int,str][str] # E: The type "Type[Tuple[Any, ...]]" is not generic and not indexable | ||
[builtins fixtures/tuple.pyi] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters