-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
Closed
Labels
3.13bugs and security fixesbugs and security fixes3.14bugs and security fixesbugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
Using one of the FORCE_COLOR, NO_COLOR or TERM=dumb environment variables is ignored when you use Python with -E.
-E means:
Ignore all
PYTHON*environment variables, e.g. PYTHONPATH and PYTHONHOME, that might be set.
The -E is stored in sys.flags.ignore_environment.
sys.flags.ignore_environment is used to ignore PYTHON_COLORS (correct) but it's also ignoring these other env vars (incorrect).
For example, this is not colourised, as expected:
❯ NO_COLOR=1 python3.13 -c 1/0
Traceback (most recent call last):
File "<string>", line 1, in <module>
1/0
~^~
ZeroDivisionError: division by zero
However, NO_COLOR=1 is ignored when passing -E and the output has colour when it should not:
❯ NO_COLOR=1 python3.13 -E -c 1/0
Traceback (most recent call last):
File "<string>", line 1, in <module>
1/0
~^~
ZeroDivisionError: division by zero
This bit needs updating:
Lines 43 to 56 in 487fdbe
| if not sys.flags.ignore_environment: | |
| if os.environ.get("PYTHON_COLORS") == "0": | |
| return False | |
| if os.environ.get("PYTHON_COLORS") == "1": | |
| return True | |
| if "NO_COLOR" in os.environ: | |
| return False | |
| if not COLORIZE: | |
| return False | |
| if not sys.flags.ignore_environment: | |
| if "FORCE_COLOR" in os.environ: | |
| return True | |
| if os.environ.get("TERM") == "dumb": | |
| return False |
CPython versions tested on:
3.13, 3.14
Operating systems tested on:
Linux, macOS, Windows
Linked PRs
Metadata
Metadata
Assignees
Labels
3.13bugs and security fixesbugs and security fixes3.14bugs and security fixesbugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

