using inspect.unwrap on `maurix.types.Obj` places the object into a state where serializing raises a RecursionError
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 45/100
Research direction
Start in mautrix/types/util/obj.py, especially getattr and serialize(), and reproduce the inspect.unwrap(mautrix.types.Obj()) example from the issue. Check that missing dunder or sunder names are not created dynamically, while normal missing attributes retain their existing behavior. Done means the example no longer leaves the object recursively serializable and raises only the expected unwrap error.
Written by the indexing model from the issue text.
Description
>>> import mautrix.types
>>> import inspect
>>> inspect.unwrap(mautrix.types.Obj())
Traceback (most recent call last):
File "<python-input-2>", line 1, in <module>
inspect.unwrap(mautrix.types.Obj())
~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
File "/home/lily/.pyenv/versions/3.13.2/lib/python3.13/inspect.py", line 791, in unwrap
raise ValueError('wrapper loop when unwrapping {!r}'.format(f))
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
File "/home/lily/Documents/matrix-codecrimes/.venv/lib/python3.13/site-packages/mautrix/types/util/obj.py", line 36, in __repr__
return repr(self.serialize())
~~~~~~~~~~~~~~^^
File "/home/lily/Documents/matrix-codecrimes/.venv/lib/python3.13/site-packages/mautrix/types/util/obj.py", line 62, in serialize
k: v.serialize() if isinstance(v, Serializable) else v
~~~~~~~~~~~^^
File "/home/lily/Documents/matrix-codecrimes/.venv/lib/python3.13/site-packages/mautrix/types/util/obj.py", line 62, in serialize
k: v.serialize() if isinstance(v, Serializable) else v
~~~~~~~~~~~^^
File "/home/lily/Documents/matrix-codecrimes/.venv/lib/python3.13/site-packages/mautrix/types/util/obj.py", line 62, in serialize
k: v.serialize() if isinstance(v, Serializable) else v
~~~~~~~~~~~^^
[Previous line repeated 986 more times]
RecursionError: maximum recursion depth exceeded
this appears to be caused because inspect.wrapper attempts to access .__wrapped__ which causes the __getattr__ to create it, which is bad.
maybe it would be a good idea not to create __dunder__ and _sunder_ names? so something like:
def __getattr__(self, name):
if name.startswith("_") and name.endswith("_"):
raise AttributeError(name)
...
just to prevent brainfarts: this wont prevent access to defined dunders since __getattr__ is only called when the name cannot be found through other means.
- Dominant language
- Python
- Stars
- 249
- Forks
- 84
- PR merge metrics
- No merged PRs in 30d
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.
More from mautrix/python
-
Difficulty 5/5 Over a week Newbie friendliness 30/100
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
Difficulty 4/5 3-5 days Newbie friendliness 30/100
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
Difficulty 4/5 3-5 days Newbie friendliness 38/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100