-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Aliases for generic class applications get type Any #2349
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
Ouch! |
It would be worth investigating whether special type checking of aliases can be removed completely. Special processing is still needed in semantic analysis so that the alias can be used in a type annotation, but I'm not aware of a situation where the type checker still needs to treat the type alias definition specially. |
@gvanrossum @rwbarton This issue could be closed now. It was fixed by #2378 |
Concerning whether we need special treatment: It looks like the way they are treated now is left from times when there was no |
It's still not obvious to me why any special logic is required at all. (Even before Consider these three program fragments, where x = C[int]()
reveal_type(x) c = C[int]
x = c()
reveal_type(x) (c,) = (C[int],)
x = c()
reveal_type(x) The first produces So, at least in this case, the logic added in 57ff82b seems to be somehow redundant, in the sense that if the type checker did not treat type alias definition RHSs specially at all, it would have already gotten the correct result. |
@rwbarton Concerning the third example, I am not sure what do you mean by "always". Before #2302 generic type application was prohibited in runtime context (this has nothing to do with aliases), so that first example and most probably two other would simply give you an error and Probably you wanted to say that Anyway, my first attempt to allow generic type aliases was actually exactly like you suggested: just re-using type application (this is the thing that makes mypy "smart enough to understand how to type check it"), but I didn't manage to do this. I have nothing against someone refactoring type aliases either using |
I'm not sure exactly when the third fragment started working, but it was many commits before 57ff82b. I am quite sure that I am talking about these three program fragments, and not any other. |
As of #2302 mypy accepts use of a type application of a generic class as an expression anywhere. Previously, such applications were only allowed in type aliases (i.e., on the RHS of a simple assignment). But there is still special logic for such aliases, and it creates unexpected
Any
types. (They were there before too, but now there's clearly no reason for them.)The text was updated successfully, but these errors were encountered: