Skip to content

Monochrome Rich traceback rendering w/ ConsoleRenderer(colors=False)#794

Open
funkyfuture wants to merge 2 commits intohynek:mainfrom
funkyfuture:rich-traceback
Open

Monochrome Rich traceback rendering w/ ConsoleRenderer(colors=False)#794
funkyfuture wants to merge 2 commits intohynek:mainfrom
funkyfuture:rich-traceback

Conversation

@funkyfuture
Copy link

Summary

As addressed in this SO question, exceptions are logged with colours when using the ConsoleRenderer with the default rich exception formatter even when the renderer was initialized w/ colors=False.

This patch selects monochrome output for that formatter when it's used as default.

Pull Request Check List

  • I acknowledge this project's AI policy.
  • This pull requests is not from my main branch.
  • There's tests for all new and changed code.
  • New APIs are added to our typing tests in api.py.
  • Updated documentation for changed code.
    • New functions/classes have to be added to docs/api.rst by hand.
    • Changed/added classes/methods/functions have appropriate versionadded, versionchanged, or deprecated directives.
      • The next version is the second number in the current release + 1. The first number represents the current year. So if the current version on PyPI is 26.1.0, the next version is gonna be 26.2.0. If the next version is the first in the new year, it'll be 27.1.0.
  • Documentation in .rst and .md files is written using semantic newlines.
  • Changes (and possible deprecations) are documented in the changelog.

@funkyfuture funkyfuture force-pushed the rich-traceback branch 4 times, most recently from d210f4e to 1924e3e Compare March 14, 2026 16:23
@funkyfuture
Copy link
Author

if this is of interest for you, i could use some advice. the test i added executes unreliably within the tox environments locally. and i have no clue why.

@hynek
Copy link
Owner

hynek commented Mar 15, 2026

on a brief look your conceptual problem seems to be that setting colors does nothing on ConsoleRenderer. It's only an argument to the constructor that sets up columns a certain way. You're also modifying a global shared object so it's to be expected that you get weird side-effects. You probably want to create something like default_exception_formatter_no_colors and use that if colors are False and exception_formatter is default_exception_formatter

@funkyfuture
Copy link
Author

thanks for the hint! improperly fiddling w/ global objects was the cause.

…e output

The None isn't specified as Literal, b/c ruff tells us how to express this.
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