python / python/cpython

Unify interpretation of values of environment variables and CLI options

Open
#116,907 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type-feature
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

There is inconsistency in interpreting values of different environment variables that have equivalent of CLI options.

  • For some environment variables, defining them with any values (even empty) is interpreted as true.
  • For some environment variables, any values except 0 (including non-numbers and empty value) are interpreted as true. Only 0 is interpreted as false. For some of these variables it makes sense to set integer value > 1, but for other they are just booleans.
  • PYTHONUTF8 and PYTHON_GIL only accept "1" and "0". All other values are errors. Although the code for these two variables is very different.
  • PYTHON_FROZEN_MODULES only accepts "on" and "off". All other values are errors.
  • PYTHONCOERCECLOCALE has three state: "0", "warn" and... anything other.
  • Some environment variables has "0" as a special value, but PYTHON_CPU_COUNT uses "default".

There are similar things for corresponding CLI options which accept optional arguments.

Such diversity makes it difficult to document and use environment variables and CLI options. It can lead to subtle bugs if "0" is interpreted differently. An empty value of the environment variable can be the result of a hidden bug, but in most cases it is currently silently accepted and interpreted as true value.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Begin by inventorying the environment variables and equivalent CLI options described in the issue, comparing their current handling of empty, numeric, boolean, and invalid values. This needs an agreed interpretation policy before implementation. Done means the listed environment variables and corresponding CLI options follow consistent rules, including consistent handling of invalid values.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.