Use color to highlight error locations · Issue #112730 · python/cpython (original) (raw)
Navigation Menu
- GitHub Copilot Write better code with AI
- GitHub Models New Manage and compare prompts
- GitHub Advanced Security Find and fix vulnerabilities
- Actions Automate any workflow
- Codespaces Instant dev environments
- Issues Plan and track work
- Code Review Manage code changes
- Discussions Collaborate outside of code
- Code Search Find more, search less
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Appearance settings
Description
This has several advantages:
- Will help a lot with readability as parsing the error lines is easier if color highlights the error ranges.
- In the future we can optionally (via config) drop the ranges and only use color, recovering back the extra lines that the carets are taking.
- All the cool kids are doing it: This feature has already been successfully implemented in various tools. It has proven to be an effective aid for developers in quickly identifying the source and location of errors.
Control features:
- The feature will use 16 ANSI color scapes so the actual color is configured via the terminal emulator.
- Users can set the following env vars to control it (in the following order):
PY_COLORS=1
activates the feature (used by pytest: https://github.com/pytest-dev/pytest/blob/022f1b4de546c8b3529e071965555888ecf01cb4/src/_pytest/_io/terminalwriter.py#L28)PY_COLORS=0
deactivates the featureNO_COLOR=1
deactivates the featureFORCE_COLOR=1
activates the feature- Feature is deactivated if terminal is not a tty or if
TERM
is set todumb
.
Linked PRs
- gh-112730: Use color to highlight error locations #112732
- gh-112730: Update docs for colour env vars #112837
- gh-112730: Make the test suite resilient to color-activation environment variables #117672
- gh-112730: use keyword only argument for colorize #118086
- gh-112730: Respect tests that require environment variables with no-colorize fixes #118288