Skip to content

Push correct enclosing class while deferring a method #4073

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 5 commits into from
Oct 12, 2017

Conversation

ilevkivskyi
Copy link
Member

Fixes #4069

This pushes the correct enclosing class while deferring a method instead of just the top class.

A related comment: the name active_class is a bit misleading, it returns None from within methods, I think it would be more consistent if active_class behave the same way as self.type in semantic analysis, but it is too late to change this, it is already used in several other places with this semantics.

@elazarg
Copy link
Contributor

elazarg commented Oct 8, 2017

I think I am to blame for the name active_class, and I agree it's not the best. But the intention is that active is active scope, and inside a method there is no active class scope. I don't think it's the same as "the current type".

Can't the issue be resolved by freezing the entire scope, as suggested by the TODO?

Anyway, if you are leaving the method active_class(), and assigning enclosing_scope() to a variable, I think it can't be called active_class; it will be confusing.

@ilevkivskyi
Copy link
Member Author

Can't the issue be resolved by freezing the entire scope, as suggested by the TODO?

It is unnecessary, and will only make solution more complex.

Anyway, if you are leaving the method active_class(), and assigning enclosing_scope() to a variable, I think it can't be called active_class; it will be confusing.

OK, I renamed this variable, I keep however the named tuple attribute name, active_typeinfo, it makes sense, since the enclosing class for a method becomes the active class when the deferred node rechecking starts.

@JukkaL JukkaL self-assigned this Oct 11, 2017
@JukkaL
Copy link
Collaborator

JukkaL commented Oct 11, 2017

Can you fix the merge conflict?

@ilevkivskyi
Copy link
Member Author

@JukkaL

Can you fix the merge conflict?

Fixed.

@JukkaL
Copy link
Collaborator

JukkaL commented Oct 11, 2017

This generates unexpected errors when run against an internal Dropbox codebase. Here is a simplified example:

class A:
    def f(self) -> None:
        def g(x: int) -> int:  # Self argument missing for a non-static method 
                               # (or an invalid type for self)
            return y

y = int()

@ilevkivskyi
Copy link
Member Author

This generates unexpected errors when run against an internal Dropbox codebase. Here is a simplified example: ...

Indeed, since the active_typeinfo is only used by bind_self and friends, we should only push the immediate enclosing class. Will push a fix in a second.

@ilevkivskyi
Copy link
Member Author

@JukkaL Fixed.

Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the PR!

@JukkaL JukkaL merged commit ed5a057 into python:master Oct 12, 2017
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.

3 participants