-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Fix incorrect name lookup for decorated methods #8175
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Generally looks good, I have few minor comments.
oops, I made some stupid mistakes And seems like the @overload case does not apply to this fix |
I add new logic in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updates! Here are couple more comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still not ready, I have few more comments.
Good catch and thanks for the careful review! I check the logic again and indeed there are some mistakes, here's the update:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost ready now, just couple small comments.
To address that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! (assuming the tests pass)
Resolves #8161
According to comments of
lookup
inmypy/semanal.py
, when we look up a class attribute, we require that it is defined textually before the reference statement, thus line number is used for comparison.When function has decorators, its line number is determined by the top decorator instead of the
def
. That's why #8161's code fails because on line 8, theA
inType[A]
has the line number of 8 while the @staticmethod functionA
has the line number of 7 due to the decorator.Thus we need to properly handle this by introducing the number of decorators when deciding textural precedence.