-
-
Notifications
You must be signed in to change notification settings - Fork 33.3k
Open
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
inspect.getmembers_static is documented as not triggering __getattribute__, but it can trigger it via dir. For example the following hits the recursion limit:
class A:
def __getattribute__(self, name: str) -> Any:
getmembers_static(self)
return "all attrs exist!"
A().anything(A workaround for examples like this one is to add the base cases required by dir to __getattribute__:
if name in ("__dict__", "__class__"):
return object.__getattribute__(self, name)(The __dict__ case is not always needed depending on the __dir__ implementation.))
Switching getmembers_static to use dir_static (gh-55979) would fix this problem, I believe. getmembers_static already documents that it can't find the dynamically created attributes, etc. that getattr_static can't find, so I don't think such a change would be breaking.
Your environment
- CPython versions tested on: 3.11.0
- Operating system and architecture: Linux-based, x86_64
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error