Skip to content

Conversation

Locked-chess-official
Copy link

@Locked-chess-official Locked-chess-official commented Oct 11, 2025

image

effect:

Python 3.15.0a0 (heads/main-dirty:5776d0d2e08, Oct 12 2025, 00:07:14) [MSC v.1944 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> class WrongException1(Exception):
...     def __str__(self):
...         raise WrongException2()
...     __repr__ = __str__
...
>>> class WrongException2(Exception):
...     def __str__(self):
...         raise WrongException1()
...     __repr__ = __str__
...
>>> a = WrongException1()
>>> a.__notes__ = WrongException2()
>>> b = a.__notes__
>>> raise a
Traceback (most recent call last):
  File "<python-input-5>", line 1, in <module>
    raise a
WrongException1: <exception str() failed>
<__notes__ repr() failed>

Exception ignored in exception str():
Traceback (most recent call last):
  File "C:\Users\hh180\my_python\handle_keyerror\Lib\traceback.py", line 288, in _safe_string
    return func(value)
  File "<python-input-0>", line 3, in __str__
    raise WrongException2()
WrongException2: <exception str() failed>

Exception ignored in exception str():
Traceback (most recent call last):
  File "C:\Users\hh180\my_python\handle_keyerror\Lib\traceback.py", line 288, in _safe_string
    return func(value)
  File "<python-input-1>", line 3, in __str__
    raise WrongException1()
WrongException1: <exception str() failed>

Exception ignored in __notes__ repr():
Traceback (most recent call last):
  File "C:\Users\hh180\my_python\handle_keyerror\Lib\traceback.py", line 288, in _safe_string
    return func(value)
  File "<python-input-1>", line 3, in __str__
    raise WrongException1()
WrongException1: <exception str() failed>

Exception ignored in exception str():
Traceback (most recent call last):
  File "C:\Users\hh180\my_python\handle_keyerror\Lib\traceback.py", line 288, in _safe_string
    return func(value)
  File "<python-input-0>", line 3, in __str__
    raise WrongException2()
WrongException2: <exception str() failed>
>>> assert b is a.__notes__
>>>

If the change break some test, I will try to fix it.
This is the attempt for add the note in handling.
If it is success, we then can use "exception_target" to print the exception from handling as warnings.

@Locked-chess-official
Copy link
Author

Now it seems that the test for traceback._safe_str need to be update. However, I'll have a sleep now.

Copy link
Member

@StanFromIreland StanFromIreland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR has hundreds of cosmetic changes (I assume you linted the code with black or the like?), resulting in a diff of +663/-244, please revert them all.

@Locked-chess-official Locked-chess-official marked this pull request as ready for review October 11, 2025 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants