Skip to content

Conversation

@hongweipeng
Copy link
Contributor

@hongweipenghongweipeng commented Feb 15, 2022

Copy link
Member

@sobolevnsobolevn left a comment

Choose a reason for hiding this comment

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

Isn't it the same as #29901 ?

@hongweipeng
Copy link
ContributorAuthor

Isn't it the same as #29901 ?

I think this is a good example of using inspect.getmembers_static.

@hongweipeng
Copy link
ContributorAuthor

Isn't it the same as #29901 ?

No, it only skip property in #29901 .

@hongweipeng
Copy link
ContributorAuthor

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.

forattrindir(spec):
ifiscoroutinefunction(getattr(spec, attr, None)):
_spec_asyncs.append(attr)
forattr, _ininspect.getmembers_static(spec, iscoroutinefunction):
Copy link
Member

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?

@carljm
Copy link
Member

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.

@carljmcarljm closed this May 5, 2023
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@hongweipeng@carljm@JelleZijlstra@sobolevn@the-knights-who-say-ni@ezio-melotti@bedevere-bot