Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion graalpython/com.oracle.graal.python.test/src/tests/test_repr.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2018, 2026, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# The Universal Permissive License (UPL), Version 1.0
Expand Down Expand Up @@ -66,3 +66,15 @@ def a_func():
assert_not_raises(lambda: repr(a_func))
assert_not_raises(lambda: repr(object()))
assert_not_raises(lambda: repr(x))


def test_repr_type_error_includes_returned_value():
class ReprReturnsInt:
def __repr__(self):
return 42

try:
repr(ReprReturnsInt())
assert False
except TypeError as e:
assert str(e) == "__repr__ returned non-string (type int)"
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
Expand Down Expand Up @@ -108,7 +108,7 @@ static Object repr(VirtualFrame frame, Node inliningTarget, Object obj,
if (checkNode.execute(inliningTarget, result)) {
return result;
} else {
throw raiseTypeError(inliningTarget, obj, raiseNode);
throw raiseTypeError(inliningTarget, result, raiseNode);
}
}

Expand Down
Loading