-
Notifications
You must be signed in to change notification settings - Fork 146
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Description
When __repr__ returns a non-string value, the TypeError message incorrectly reports the type of the object being repr'd, instead of the type of the invalid return value. This is a CPython compatibility issue.
Root Cause
In PyObjectReprAsObjectNode.java#L111, raiseTypeError is called with obj (the object being repr'd) instead of result (the return value of __repr__), so the error message prints the wrong type name. Note that the equivalent __str__ path in PyObjectStrAsObjectNode.java#L128 already correctly passes result.
CPython reference:
Objects/object.c#L579-L581
Fix
Pass the __repr__ return value (result) instead of the original object (obj) to raiseTypeError, matching CPython's behavior.
Reproduction
class A:
def __repr__(self):
return True
repr(A())Output
GraalPy:
Traceback (most recent call last):
File "/tmp/test.py", line 5, in <module>
repr(A())
TypeError: __repr__ returned non-string (type A)
CPython:
Traceback (most recent call last):
File "/tmp/test.py", line 5, in <module>
repr(A())
TypeError: __repr__ returned non-string (type NoneType)
Environment
- GraalPy 25.0.2 (Python 3.12.8)
- CPython 3.12.13
- OS: Debian 12
- CPU: arm64
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working