Skip to content

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

Merged
merged 7 commits into from
Jun 15, 2016

Conversation

rwbarton
Copy link
Contributor

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.

T = TypeVar('T')
def f(a: T) -> None:
l = [] # type: List[T]
l.append(a)
Copy link
Collaborator

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.

Copy link
Collaborator

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?

@JukkaL
Copy link
Collaborator

JukkaL commented May 25, 2016

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.

@rwbarton
Copy link
Contributor Author

@JukkaL, I think this should be ready to go then.

@JukkaL
Copy link
Collaborator

JukkaL commented Jun 10, 2016

@rwbarton Once you've fixed the conflicts, feel free to merge this to master if tests still pass.

rwbarton added 7 commits June 14, 2016 12:25
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Type inference problem in generic function
2 participants