-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Bug - Type aliases in closure does not work #8273
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
Comments
Here is a simplified example that shows the root cause of the unexpected behavior: from typing import TypeVar, Callable
T = TypeVar('T')
F = Callable[[T], T]
def f() -> F[T]: ...
def g() -> Callable[[T], T]: ...
reveal_type(f) # def [T] () -> def (T`-1) -> T`-1
reveal_type(g) # def () -> def [T] (T`-1) -> T`-1 The scope (?) of the type variable is wrong when using a type alias. The type of |
I've investigated this for a little while. For case like from typing import TypeVar, Sequence
T = TypeVar('T')
S = Sequence[T]
def f() -> S[T]: ...
def g() -> Sequence[T]: ... T gets bound to the function after
That's all I've gone so far and some insights, either high-level abstraction or low-level details would help a lot on fixing this @JukkaL |
Definitely been feeling the pain of this one lately. Long type annotations (that could otherwise be broken up type aliases) are really inhibiting code readability. Anyone know of good workarounds for this? |
Closing as a duplicate of #3924 |
This may be a known limitation of the type system, but it would be nice if it were possible to write the following without the commented error:
In order for this to work correctly I have to replace the type alias
Decorator
with the explicitCallable[[F], F]
. This is trivial to change in this case, but for more complex types this would inhibit readability greatly.Details:
What version of MyPy: 0.761
Have you tried on master: no
Are there any flags engaged: no
The text was updated successfully, but these errors were encountered: