provide a way to access the unmodified environment (variables) of a Python script

Open
#93,446 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

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

Research direction

No implementation files or tests are named. Start with PEP 538 and the linked discussion in issue 72367 to understand the environment mutation and proposed API; the work is done when a specific design and corresponding coverage are agreed.

Written by the indexing model from the issue text.

Description

interpreter-core type-feature

Feature or enhancement

As described in https://github.com/python/cpython/issues/72367#issuecomment-1140355246 and the following comments, the implementation of PEP 538 makes it impossible to access the original unmodified environment (variables) with which a process have been invoked.

I have no problem with the goal of PEP 538 itself or the locale coercion, but this is a problem for any use-case the wants to act on the original locale.

Using PYTHONCOERCECLOCALE=0 is no solution either, as then this modifies the original locale and one couldn't decide whether it's just there to prevent Python's setting of LC_CTYPE=C or whether it was really intended to be in the environment suo jure.

Neither is it obviously a solution to use build-time options.

A solution could be to add another os.original_environment or something like that, which gives the true original environment, without any changes that Python itself may have made.

If Python would ever only modify (by itself) the environment with respect to LC_CTYPE and locale coercion, it could also be enough to simply give the program a way to find out whether that was done, and what the original value (or unset) of LC_CTYPE was.

Pitch

Example use cases are given in the previous discussion mentioned below.

In short, pretty much anything that is intended to serve as a wrapper could require the true original environment.
Imagine one would want to implement the POSIX env utility in Python.

Previous discussion

See https://github.com/python/cpython/issues/72367#issuecomment-1140355246 .

Dominant language
Python
Stars
77.2k
Forks
36k
Avg merge
1d 9h
Merged PRs (30d)
558

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.

More from python/cpython

All issues in python/cpython

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.