Skip to content

Improve type checking of generic function bodies - #1580

Merged
rwbarton merged 7 commits into
python:masterfrom
rwbarton:rwbarton-metavar
Jun 15, 2016
Merged

rwbarton merged 7 commits into
python:masterfrom
rwbarton:rwbarton-metavar

Conversation

@rwbarton

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

JukkaL commented May 25, 2016

Copy link
Copy Markdown
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.

@rwbarton

Copy link
Copy Markdown
Contributor Author

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

@JukkaL

JukkaL commented Jun 10, 2016

Copy link
Copy Markdown
Collaborator

@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