Title: `can_colorize()` ignores `FORCE_COLOR`/`NO_COLOR`/`TERM` when `-E` is set · Issue #127873 · python/cpython · GitHub
Open Graph Title: `can_colorize()` ignores `FORCE_COLOR`/`NO_COLOR`/`TERM` when `-E` is set · Issue #127873 · python/cpython
X Title: `can_colorize()` ignores `FORCE_COLOR`/`NO_COLOR`/`TERM` when `-E` is set · Issue #127873 · python/cpython
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. https://docs.python.org/3/using/cmdline.html#using-on-controlling-color -E means: Ignore all PY...
Open Graph 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. https://docs.python.org/3/using/cmdline.html#using-on-c...
X 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. https://docs.python.org/3/using/cmdline.html#using-on-c...
Opengraph URL: https://github.com/python/cpython/issues/127873
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`can_colorize()` ignores `FORCE_COLOR`/`NO_COLOR`/`TERM` when `-E` is set","articleBody":"# Bug report\r\n\r\n### Bug description:\r\n\r\nUsing one of the `FORCE_COLOR`, `NO_COLOR` or `TERM=dumb` environment variables is ignored when you use Python with `-E`.\r\n\r\n* https://docs.python.org/3/using/cmdline.html#using-on-controlling-color\r\n\r\n`-E` means:\r\n\r\n\u003e Ignore all `PYTHON*` environment variables, e.g. [PYTHONPATH](https://docs.python.org/3/using/cmdline.html#envvar-PYTHONPATH) and [PYTHONHOME](https://docs.python.org/3/using/cmdline.html#envvar-PYTHONHOME), that might be set.\r\n\r\n* https://docs.python.org/3/using/cmdline.html#cmdoption-E\r\n\r\nThe `-E` is stored in `sys.flags.ignore_environment`.\r\n\r\n* https://docs.python.org/3/library/sys.html#sys.flags.ignore_environment\r\n\r\n`sys.flags.ignore_environment` is used to ignore `PYTHON_COLORS` (correct) but it's also ignoring these other env vars (incorrect).\r\n\r\nFor example, this is not colourised, as expected:\r\n\r\n```\r\n❯ NO_COLOR=1 python3.13 -c 1/0\r\nTraceback (most recent call last):\r\n File \"\u003cstring\u003e\", line 1, in \u003cmodule\u003e\r\n 1/0\r\n ~^~\r\nZeroDivisionError: division by zero\r\n```\r\n\r\n\r\n\r\nHowever, `NO_COLOR=1` is ignored when passing `-E` and the output has colour when it should not:\r\n\r\n```\r\n❯ NO_COLOR=1 python3.13 -E -c 1/0\r\nTraceback (most recent call last):\r\n File \"\u003cstring\u003e\", line 1, in \u003cmodule\u003e\r\n 1/0\r\n ~^~\r\nZeroDivisionError: division by zero\r\n```\r\n\r\n\r\n\r\n\r\nThis bit needs updating:\r\n\r\nhttps://github.com/python/cpython/blob/487fdbed40734fd7721457c6f6ffeca03da0b0e7/Lib/_colorize.py#L43-L56\r\n\r\n\r\n### CPython versions tested on:\r\n\r\n3.13, 3.14\r\n\r\n### Operating systems tested on:\r\n\r\nLinux, macOS, Windows\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-127877\n* gh-129138\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/hugovk","@type":"Person","name":"hugovk"},"datePublished":"2024-12-12T16:23:38.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/127873/cpython/issues/127873"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:dff73bdf-ca33-5f98-b387-f45f48cc43a8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DC34:3E375C:1039BAF:160E799:6A50774D |
| html-safe-nonce | 050142f56b5f775f1eb16eecbda679085d76d66dcebc99fa7759705323e2df99 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQzM0OjNFMzc1QzoxMDM5QkFGOjE2MEU3OTk6NkE1MDc3NEQiLCJ2aXNpdG9yX2lkIjoiNzczNzQ4ODU1MDIzMzQwNTI2MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 3db4065e8f8730487d56f4fe065db5c2f7f2c5ae550ac3d8c2987cc664a562b4 |
| hovercard-subject-tag | issue:2736356144 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/127873/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c0554920e9b88e07627c8853b6f4379b2606fddfad539e2eff6270e984457021/python/cpython/issues/127873 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c0554920e9b88e07627c8853b6f4379b2606fddfad539e2eff6270e984457021/python/cpython/issues/127873 |
| og:image:alt | 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. https://docs.python.org/3/using/cmdline.html#using-on-c... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | hugovk |
| hostname | github.com |
| expected-hostname | github.com |
| None | d6dc8294eb500fa36bbc57472d61fe87c522f9c3c1d64f70f4926f66a66a7efb |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7ac0ad2f2c7e4b9056617355fd9e33e22b0c8df9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width