Skip to content

[WIP] Add scoping rules for type variables to PEP 484 #63

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 4 commits into from
Jul 29, 2016

Conversation

ilevkivskyi
Copy link
Member

Fixes python/typing#249
@gvanrossum please review

@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

Unfortunately we couldn't find an account corresponding to your GitHub username at bugs.python.org (b.p.o). If you don't already have an account at b.p.o, please create one and make sure to add your GitHub username. If you do already have an account at b.p.o then please go there and under "Your Details" add your GitHub username.

And in case you haven't already, please make sure to sign the PSF contributor agreement (CLA); we can't legally look at your contribution until you have signed the CLA.

Once you have done everything that's needed, please reply here and someone will verify everything is in order.

@ilevkivskyi
Copy link
Member Author

@the-knights-who-say-ni I have added my github username on bugs.python.org

Type variables follow normal name resolution rules.
However, there are some special cases in the static typechecking context:

* A type variable could be inferred to be equal to different types in a block,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section feels unclear, though I'm not sure how to say it right myself.

The key point is that the occurrence of a type variable in a method signature can mean one of two things:

  1. a generic function;
  2. a method of a generic class.

The disambiguating rule is that if the class of which this is a method is generic over a type variable, then the type variable refers to the class's type parameter; if not, it is a "free" type variable, making the function generic. (I'm making up the term "free" here.)

The other rule, which you are describing in this same section, is that free type variables occurring in different functions are unconnected. (I think the example showing this should be shown first, separately, before discussing type variables belonging to a generic class.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to reformulate this by splitting it into three separate rules. Please check if it is more clear now.

@ilevkivskyi
Copy link
Member Author

@gvanrossum The new version is ready for review now

y = x.method(0, "abc") # inferred type of y is str

* Unbound type variables should not appear in the bodies of generic functions,
and in the class bodies appart from method definitions::
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"or". Also, "apart".

@gvanrossum
Copy link
Member

That's all I have!

@ilevkivskyi
Copy link
Member Author

@gvanrossum I implemented all the comments from the second review in the new version.

@gvanrossum gvanrossum merged commit 78478bc into python:master Jul 29, 2016
lukpueh added a commit to lukpueh/peps that referenced this pull request Nov 21, 2019
Revise target file related terminology
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants