Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Lib/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,10 @@ def getmembers(object, predicate=None):
# like calling their __get__ (see bug #1785), so fall back to
# looking in the __dict__.
try:
value = getattr_static(object, key)
if isinstance(getattr_static(object, key), property):
Copy link
Member

Choose a reason for hiding this comment

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

Why can't we always use getattr_static? If there's a reason for not using it always, please describe that in a comment.

Copy link
Author

Choose a reason for hiding this comment

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

This is related to my latest comment. Sorry, I didn't make this clear:

getattr_static(...,'__class__') returns <attribute '__class__' of 'object' objects> whereas getattr would return <class '__main__.Foo'>. What should getmembers return? Using getattr_static for every attribute doesn't seem to be the solution. It works fine with methods, functions and properties, but some edge cases seem to require getattr (such as __class__). It is not clear what the expected behaviour is.

Copy link
Member

Choose a reason for hiding this comment

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

Got it, well, describe this in a comment :)

value = getattr_static(object, key)
else:
value = getattr(object, key)
# handle the duplicate key
if key in processed:
raise AttributeError
Expand Down