Page MenuHomePhabricator

Use sys.excepthook to print exception notes for Python 3.10 and below
Closed, DeclinedPublic

Description

Exception notes are already implemented for older Pythons with T416566 but these should only be printed when an Exception is raised and not be given with str(). The idea is to patch the sys.excepthook accordingly for older Pythons like:

original_excepthook = sys.excepthook

def excepthook_with_notes(exc_type, exc_value, exc_traceback):
    # normal traceback
    original_excepthook(exc_type, exc_value, exc_traceback)

    # notes
    notes = getattr(exc_value, '__notes__', [])
    for note in notes:
        print(note)

sys.excepthook = excepthook_with_notes

Event Timeline

Change #1237571 had a related patch set uploaded (by Anotida Expected; author: Anotida Expected):

[pywikibot/core@master] [exceptions] Use sys.excepthook to display backported notes

https://gerrit.wikimedia.org/r/1237571

Hi @JJMC89, I noticed you dislike this task. Since I really value your technical judgement, I’d like to understand your concerns better. Could you share what you think is problematic about it. This also affects T416566.

Change #1237674 had a related patch set uploaded (by Anotida Expected; author: Anotida Expected):

[pywikibot/core@master] [exceptions] Use sys.excepthook to display backported notes

https://gerrit.wikimedia.org/r/1237674

Change #1237571 abandoned by Xqt:

[pywikibot/core@master] [exceptions] Use sys.excepthook to display backported notes

Reason:

https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1237674

https://gerrit.wikimedia.org/r/1237571

Xqt changed the task status from Open to Stalled.Feb 8 2026, 8:20 AM
Xqt changed the task status from Stalled to Open.
Xqt added a project: Pywikibot-RfCs.

Generally, I'm not a fan of backporting python features in the library, especially without a use case that can't wait until the library's minimum python version is 3.11. (Nether this task or T416566 specify a specific use case for this feature in the library.)

Declined per JJMC89`s comment

Change #1237674 abandoned by Xqt:

[pywikibot/core@master] [exceptions] Use sys.excepthook to display backported notes

Reason:

Tasks were declined

https://gerrit.wikimedia.org/r/1237674