-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Generic inner classes sees type variable from outer class #3144
Comments
I looks like the method Anyway, I think this is confusing and worth prohibiting. One can just use another type variable to create a generic method. |
So is my understanding below correct? According to PEP 484:
I understand that rule as saying |
No, PEP has an explicit example showing what is prohibited. |
Ahh I see, even though the variables are out of scope, they can be used to define a new generic function. That makes sense, and I no longer think it's a problem (although I agree it's slightly confusing). |
The PEP is ambiguous about this exact example. When you're defining an inner class, it specifically blacklists the outer class's parameters as valid parameters for the inner one, but semantically the outer class's parameters are out of scope -- the inner class doesn't have an instance context for the outer class. In a method in the inner class, there's no guidance. It's still semantically outside the scope of the outer class, but the reasons for blacklisting it have not gone away. In #3113 I may be changing this behavior to be more like the one you describe as less confusing, @pkch, I'll import your test there and see. |
Ok, no #3113 does not change this behavior. But if we want to, I have the code loaded into my head for exactly how, now. |
@sixolet I would prohibit it both in the PEP and in mypy. I can propose the edit to the PEP. |
Sure. I'll see if adding it to my current PR simplifies; if so I'll do that. If not I'll make a follow-on PR.
… On Apr 14, 2017, at 10:32 AM, Max ***@***.***> wrote:
@sixolet I would prohibit it both in the PEP and in mypy. I can propose the edit to the PEP.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
#3113 now fixes this. |
Source
The text was updated successfully, but these errors were encountered: