GeezerVison is showing github.com — bpo-45756: Fix mock triggers dynamic lookup via the descriptor protocol. by hongweipeng · Pull Request #31348 · python/cpython
Conversation
hongweipeng
commented
Feb 15, 2022
•
edited by bedevere-bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Isn't it the same as #29901 ?
I think this is a good example of using inspect.getmembers_static.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Isn't it the same as #29901 ?
No, it only skip property in #29901 .
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
This PR is similar to #22209 .
I check the difference between inspect.getmembers_static(obj) and for k in dir(obj) ... inspect.getattr_static(obj, k) .
I found that they behave differently when __dir__ is defined and the attribute is not exist.
class A:
def __dir__(self):
return ['__class__', 'no_member']
obj = A()
inspect.getmembers_static(obj) # ['__class__']
[(k, inspect.getattr_static(obj, k)) for k in dir(obj)] # AttributeError
I don't know which behavior is more reasonable.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
for attr in dir(spec):
|
|
|
if iscoroutinefunction(getattr(spec, attr, None)):
|
|
|
_spec_asyncs.append(attr)
|
|
|
for attr, _ in inspect.getmembers_static(spec, iscoroutinefunction):
|
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.
What about async classmethods? Would those still get recognized as coroutines?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Thanks for the PR! I think we should consolidate the discussion to #22209. If we do this, we should prefer continuing to use dir and using getattr_static (as done in #22209), rather than switching to getmembers_static, because switching away from dir causes extra avoidable backward-incompatibility.
Also, I think the async-classmethod case is not fixable using getmembers_static, but is fixable via getattr_static.
Closing as duplicate of #22209.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
cjw296
Awaiting requested review from cjw296
cjw296 is a code owner
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|