Skip to content

Conversation

@ZeroIntensity
Copy link
Member

@ZeroIntensity ZeroIntensity commented May 18, 2025

It's pretty now:

image

I don't think it's worth it/possible to add a test for this.


📚 Documentation preview 📚: https://cpython-previews--134183.org.readthedocs.build/

Copy link
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

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

Let's this by raising an unraisable exception inside the hook itself and check that we don't crash. I don't know if we can recursively call sys.unraisablehook because of that, but if we can, we should check that we don't segfault for whatever reason.

@ZeroIntensity
Copy link
Member Author

Sorry, forgot about this PR!

Let's this by raising an unraisable exception inside the hook itself and check that we don't crash. I don't know if we can recursively call sys.unraisablehook because of that, but if we can, we should check that we don't segfault for whatever reason.

I think this makes sense for a follow-up, because it'll apply to the current implementation as well, right? Ideally, that test would get backported.

In general, we shouldn't have to worry too much about breaking things here, because we're just adding execution of Python code to a path where you could already execute arbitrary Python code.

@picnixz
Copy link
Member

picnixz commented Jun 2, 2025

I think this makes sense for a follow-up, because it'll apply to the current implementation as well, right? Ideally, that test would get backported.

Yes.

@ZeroIntensity ZeroIntensity requested a review from picnixz August 3, 2025 18:03
Python/errors.c Outdated
Comment on lines 1497 to 1498
Py_XDECREF(result);
if (result != NULL) {
Copy link
Member

Choose a reason for hiding this comment

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

Let's avoid checking dangling pointers. Let's do int ok = result != NULL; Py_XDECREF(result); and compare ok afterwards.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Copy link
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

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

Sorry last nitpicks.

ZeroIntensity and others added 2 commits August 4, 2025 09:05
Co-authored-by: Victor Stinner <[email protected]>
Co-authored-by: Victor Stinner <[email protected]>
Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM

@ZeroIntensity ZeroIntensity enabled auto-merge (squash) August 4, 2025 14:10
@ZeroIntensity ZeroIntensity merged commit e8251dc into python:main Aug 4, 2025
41 checks passed
@ZeroIntensity ZeroIntensity deleted the unraisable-color branch August 4, 2025 14:41
Agent-Hellboy pushed a commit to Agent-Hellboy/cpython that referenced this pull request Aug 19, 2025
…4183)

Default implementation of sys.unraisablehook() now uses traceback._print_exception_bltin() to print exceptions with colorized text.

Co-authored-by: Bénédikt Tran <[email protected]>
Co-authored-by: Victor Stinner <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants