-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Improve type checking of generic function bodies #1580
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
Conversation
T = TypeVar('T') | ||
def f(a: T) -> None: | ||
l = [] # type: List[T] | ||
l.append(a) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test also appending something invalid, such as an integer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe also test a case where we have two type variables?
Let's see if we can get this to 0.4.2. Did a quick pass other than the above questions looks good to me. |
@JukkaL, I think this should be ready to go then. |
@rwbarton Once you've fixed the conflicts, feel free to merge this to master if tests still pass. |
This will be needed for python#1261, which will make type variable ids unpredictable.
Places that still use int ids are in construction of TypeVarDefs and (de)serialization of TypeVarDef and TypeVarType.
Remove the unused function replace_type_vars, and move the function replace_func_type_vars to erasetype to share implementation with erase_typevars.
We no longer need to renumber generic class type variables into the function type variable id range, because the class/function type variable distinction is no longer used.
f8b9fd6
to
e04eb73
Compare
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.