Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

can_colorize() ignoresFORCE_COLOR/NO_COLOR/TERM when-E is set #127873

Closed
Labels
3.13bugs and security fixes3.14bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error
@hugovk

Description

@hugovk

Bug report

Bug description:

Using one of theFORCE_COLOR,NO_COLOR orTERM=dumb environment variables is ignored when you use Python with-E.

-E means:

Ignore allPYTHON* environment variables, e.g.PYTHONPATH andPYTHONHOME, that might be set.

The-E is stored insys.flags.ignore_environment.

sys.flags.ignore_environment is used to ignorePYTHON_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/0Traceback (most recent call last):  File "<string>", line 1, in <module>    1/0    ~^~ZeroDivisionError: division by zero

image

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/0Traceback (most recent call last):  File "<string>", line 1, in <module>    1/0    ~^~ZeroDivisionError: division by zero

image

This bit needs updating:

ifnotsys.flags.ignore_environment:
ifos.environ.get("PYTHON_COLORS")=="0":
returnFalse
ifos.environ.get("PYTHON_COLORS")=="1":
returnTrue
if"NO_COLOR"inos.environ:
returnFalse
ifnotCOLORIZE:
returnFalse
ifnotsys.flags.ignore_environment:
if"FORCE_COLOR"inos.environ:
returnTrue
ifos.environ.get("TERM")=="dumb":
returnFalse

CPython versions tested on:

3.13, 3.14

Operating systems tested on:

Linux, macOS, Windows

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp