Repository navigation
Improve type checking of generic function bodies - #1580
Merged
Merged
Conversation
| T = TypeVar('T') | ||
| def f(a: T) -> None: | ||
| l = [] # type: List[T] | ||
| l.append(a) |
Collaborator
There was a problem hiding this comment.
Test also appending something invalid, such as an integer.
Collaborator
There was a problem hiding this comment.
Maybe also test a case where we have two type variables?
Collaborator
|
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. |
Contributor
Author
|
@JukkaL, I think this should be ready to go then. |
Collaborator
|
@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.
rwbarton
force-pushed
the
rwbarton-metavar
branch
from
June 14, 2016 19:31
f8b9fd6 to
e04eb73
Compare
This was referenced Jun 24, 2016
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.