[X] I have searched the Issue Tracker that this hasn't already been reported. (comment there if it has.)
What version of OpTree are you using?
0.9.2
System information
Install from source
Python version: 3.11.5
Problem description
The treespec representation calls repr / hash for the node metadata for each node. When the node metadata references the treespec itself, this will cause infinite recursion of calling repr(treespec) / hash(treespec).
Note that this situation is almost impossible to happen in the real world.
Traceback (most recent call last):
File "/Users/PanXuehai/Projects/optree/test.py", line 27, in <module>
print(treespec) # -> RecursionError
^^^^^^^^^^^^^^^
File "/Users/PanXuehai/Projects/optree/test.py", line 15, in __repr__
return f'Holder({self.value!r})'
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/PanXuehai/Projects/optree/test.py", line 15, in __repr__
return f'Holder({self.value!r})'
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/PanXuehai/Projects/optree/test.py", line 15, in __repr__
return f'Holder({self.value!r})'
^^^^^^^^^^^^^^^^^^^^^^^^^
[Previous line repeated 246 more times]
RecursionError: maximum recursion depth exceeded while getting the repr of an object
Traceback (most recent call last):
File "/Users/PanXuehai/Projects/optree/test.py", line 27, in <module>
print(hash(treespec)) # -> RecursionError
^^^^^^^^^^^^^^
File "/Users/PanXuehai/Projects/optree/test.py", line 12, in __hash__
return hash(self.value)
^^^^^^^^^^^^^^^^
File "/Users/PanXuehai/Projects/optree/test.py", line 12, in __hash__
return hash(self.value)
^^^^^^^^^^^^^^^^
File "/Users/PanXuehai/Projects/optree/test.py", line 12, in __hash__
return hash(self.value)
^^^^^^^^^^^^^^^^
[Previous line repeated 330 more times]
RecursionError: maximum recursion depth exceeded while calling a Python object
Required prerequisites
What version of OpTree are you using?
0.9.2
System information
Problem description
The
treespec
representation callsrepr
/hash
for the node metadata for each node. When the node metadata references thetreespec
itself, this will cause infinite recursion of callingrepr(treespec)
/hash(treespec)
.Note that this situation is almost impossible to happen in the real world.
Reproducible example code
The Python snippets:
Traceback
Expected behavior
No response
Additional context
No response