Skip to content

Accept BaseException instances in format and show - #77

Draft
AlexXuz wants to merge 1 commit into
cknd:masterfrom
AlexXuz:fix-direct-baseexception-formatting
Draft

AlexXuz wants to merge 1 commit into
cknd:masterfrom
AlexXuz:fix-direct-baseexception-formatting

Conversation

@AlexXuz

@AlexXuz AlexXuz commented Oct 28, 2026

Copy link
Copy Markdown

Summary

format() documents accepting an exception instance, but its direct-instance dispatch only recognizes Exception. Consequently, an explicitly passed KeyboardInterrupt, SystemExit, or GeneratorExit raises ValueError, even though formatting the equivalent sys.exc_info()-style tuple already works:

exc = KeyboardInterrupt('message')
stackprinter.format(exc)  # ValueError before this change
stackprinter.format((type(exc), exc, exc.__traceback__))
# 'KeyboardInterrupt: message'

Use BaseException in the existing dispatch check so direct instances follow the same path as exception tuples. show() benefits through its existing call to format(). This does not change exception catching or traceback rendering.

The regressions cover instances with and without tracebacks, plaintext and colored output, suppression options, show() output, ordinary exceptions, and rejection of unrelated inputs/classes.

Validation

  • New tests on the unchanged base: 16 failed, 15 passed; after the fix: 31 passed.
  • Full suite: 39 passed on Python 3.12.14 and 3.13.5; 38 passed, 1 existing interpreter-specific skip on Python 3.10.22.
  • CI critical flake8 check: passed. Warning-only lint is unchanged from the baseline.
  • Built the wheel and sdist; an isolated wheel installation passed direct-instance/tuple and show() smoke checks.

AI-assisted implementation and review; no claim of production use. Existing exception-group rendering limitations are outside this change.

Align direct exception-instance dispatch with the existing exc_info tuple path and cover formatting, show output, traceback states, styles, and invalid inputs.

@cknd cknd left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for the contribution!

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.

2 participants