-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Type inference problem in generic function #603
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
I took a quick look at this bug first because it seems pretty fundamental to some of the inference problems involving type variables. Indeed as Jukka says the problem is that function type variables get "erased" from the type of the context when checking a call to a generic callable, making them not valid solutions for the type arguments of that call. The reason is that in a nested call like
we first try to figure out what type By erasing the type variable Turning to the program in this ticket, the problem is that we also erase the type This ought to be enough for now since when relabeling type variables of a generic call, we can mark them as "erasable", and erase only those type variables in context type variable erasure. But since this isn't trivial to do, I'm going to investigate some related bugs before deciding whether to go down that path. |
This commit series gives type variable ids their own type and replaces the class/function type variable distinction with a plain/metavariable distinction. The main goal is to fix #603, but it's also progress towards #1261 and other bugs involving type variable inference. Metavariables (or unification variables) are variables introduced during type inference to represent the types that will be substituted for generic class or function type parameters. They only exist during type inference and should never escape into the inferred type of identifiers. Fixes #603.
Mypy complains about the following code:
The reason for the error seems to be that the type variable type
T
inList[T]
is erased so that it won't conflict with the type variables used for inferring the type of the list expression. Both type variables should be able to coexist during type inference.The text was updated successfully, but these errors were encountered: