Skip to content

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

@calestyo

Description

@calestyo

Feature or enhancement

As described in #72367 (comment) 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 #72367 (comment) .

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions