-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
bpo-38026: fix inspect.getattr_static #15676
Conversation
It should avoid dynamic lookup including `isinstance`. This is regression caused by pythonGH-5351.
@@ -1580,7 +1580,7 @@ def getattr_static(obj, attr, default=_sentinel): | |||
klass = type(obj) | |||
dict_attr = _shadowed_dict(klass) | |||
if (dict_attr is _sentinel or | |||
isinstance(dict_attr, types.MemberDescriptorType)): | |||
type(dict_attr) is types.MemberDescriptorType): |
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.
I think It helps to comment on why we use type here.
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.
If it is required, every line in this function should have same comment. It will be too noisy...
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.
Maybe a link to the issue?
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.
Note that I merged because I didn't read the comment / docstring so I didn't notice dynamic lookup should be avoided. It's totally my mistake.
But note that It is not because I didn't notice isinstance cause dynamic lookup.
If we want to avoid this type of regression by adding comment, we need to add
# to avoid dynamic lookup
comment on every line. It's nonsense...
Would be nice to add tests. |
Of course, but I am not metaprogramming expert so I don't know how to override |
Thanks @methane for the PR 🌮🎉.. I'm working now to backport this PR to: 3.8. |
GH-15692 is a backport of this pull request to the 3.8 branch. |
It should avoid dynamic lookup including `isinstance`. This is a regression caused by pythonGH-5351. (cherry picked from commit 8f9cc87) Co-authored-by: Inada Naoki <songofacandy@gmail.com>
It should avoid dynamic lookup including `isinstance`. This is a regression caused by pythonGH-5351.
It should avoid dynamic lookup including `isinstance`. This is a regression caused by pythonGH-5351.
It should avoid dynamic lookup including `isinstance`. This is a regression caused by pythonGH-5351.
It should avoid dynamic lookup including
isinstance
.This is a regression caused by #5351.
https://bugs.python.org/issue38026