`inspect.getmembers_static` triggers `__getattribute__`
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 36k
- PR merge metrics
- PR metrics pending
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the implementation of inspect.getmembers_static and the dir_static work referenced as gh-55979. Reproduce the recursion example, then verify that member inspection no longer triggers getattribute through dir; done means the reported behavior is fixed without changing the documented limits on dynamically created attributes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100