You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When the environment is modified outside Python, os.environ is not updated. I propose adding a new os.environ.refresh() method to manually update os.environ.
I think that @ncoghlan's idea about a module level os.reload_environment() function addresses most of concerns about os.environ.refresh(). But the discussion did not stop here, so not all see it so.
Somebody need to put a period here. Either reimplement this feature as a module level function, or keep all as is, -- these are two most probable options.
You should ask @zooba, the author of the discussion. According to the results of the poll, the majority prefers a module level function. Voting is not binding, and not only core developers voted, but this should still be taken into account. I do not see a vote of @zooba. Is he satisfied with proposed variants and what does he propose?
I posted on the discussion, but the majority liked the module-level function instead of putting it on the object, and I personally think reload_environ() is slightly more accurate than reload_environment(), since it is environ that is being reloaded. (There was no poll option for other module-level functions, so I'm assuming people liked os.reload... and disliked os.environ.....)
So as much as anyone wants to keep me happy, os.reload_environ() is probably the best option. Documentation will have to deal with people who read the name and misunderstand what it's for, but that is basically documentation's job.
I think @zooba's point was that this function doesn't reload the system wide environment variable settings into the running application process, which os.reload_environment() could be taken to mean.
That misreading doesn't seem particularly likely to me though, and the fact this operation reloads both os.environandos.environb (not just os.environ) makes me wary of the shorter os.reload_environ() name (it feels misleading to me in the same way that the os.environ.refresh() spelling is misleading).
I can't reasonably see os.reload_environ() implying that os.environb wouldn't also be reloaded. Certainly not as much as I can see someone thinking that os.reload_environment() implies something other than "os.environ will be reloaded".
Whereas os.environ.refresh() could quite reasonably be assumed to have no impact on os.environb. So I think that's another argument in favour of the module-level function.
Perhaps os.reload_environs() feels more comfortable for covering both os.environ and os.environb? I don't have a strong preference about the s. My main concern is still the same as at the start - this function doesn't impact the (generic) environment of the process at all, it only affects what is contained in Python's cache of the environment, otherwise known as os.environ.
I created PR gh-126268 to replace the os.environ.refresh() method with a new os.reload_environ() function.
IMO reload_environ() is a good name since it reminds os.environ. I don't think that we should bother with the fact that os.environb is also reloaded to name the function. And reload_environment() is too long :-)
Activity
WolfDWyc commentedon Jun 11, 2024
I've elaborated on this concern here: https://discuss.python.org/t/method-to-refresh-os-environ/54774/24
pythongh-120057: Add os.get_user_default_environ()
pythongh-120057: Add os.get_user_default_environ() function
Revert "pythongh-120057: Add os.environ.refresh() method (python#120059…
pythongh-120057: Rename os.environ.refresh() to invalidate_cache()
pythongh-120057: Add os.environ.refresh() method (python#120059)
pythongh-120057: Add os.environ.refresh() method (python#120059)
pythongh-120057: Add os.environ.refresh() method (python#120059)
picnixz commentedon Sep 1, 2024
Since we had a bunch of closed PRs, should this issue be closed for now? or are there other pending discussions?
serhiy-storchaka commentedon Sep 2, 2024
There was other ongoing discussion: https://discuss.python.org/t/bikeshedding-a-method-to-refresh-os-environ/57628/22
I think that @ncoghlan's idea about a module level
os.reload_environment()function addresses most of concerns aboutos.environ.refresh(). But the discussion did not stop here, so not all see it so.Somebody need to put a period here. Either reimplement this feature as a module level function, or keep all as is, -- these are two most probable options.
vstinner commentedon Oct 25, 2024
Python 3.14 alpha 1 was released with
os.environ.refresh()method. What's the status of this issue?erlend-aasland commentedon Oct 25, 2024
You tell me; you created the issue :)
vstinner commentedon Oct 26, 2024
I closed the issue, I'm not the one who reopened it.
vstinner commentedon Oct 29, 2024
@serhiy-storchaka: What's the status of this issue?
serhiy-storchaka commentedon Oct 30, 2024
You should ask @zooba, the author of the discussion. According to the results of the poll, the majority prefers a module level function. Voting is not binding, and not only core developers voted, but this should still be taken into account. I do not see a vote of @zooba. Is he satisfied with proposed variants and what does he propose?
vstinner commentedon Oct 30, 2024
@zooba: What's the status of this issue?
vstinner commentedon Oct 30, 2024
I would suggest to close the issue and keep the os.environ.refresh() method.
WolfDWyc commentedon Oct 30, 2024
I think if reload_environment is preferred by more people we should go with that.
zooba commentedon Oct 30, 2024
I posted on the discussion, but the majority liked the module-level function instead of putting it on the object, and I personally think
reload_environ()is slightly more accurate thanreload_environment(), since it isenvironthat is being reloaded. (There was no poll option for other module-level functions, so I'm assuming people likedos.reload...and dislikedos.environ.....)So as much as anyone wants to keep me happy,
os.reload_environ()is probably the best option. Documentation will have to deal with people who read the name and misunderstand what it's for, but that is basically documentation's job.serhiy-storchaka commentedon Oct 31, 2024
On other hand, it reloads the process environment to the
os.environandos.environbmappings.ncoghlan commentedon Oct 31, 2024
I think @zooba's point was that this function doesn't reload the system wide environment variable settings into the running application process, which
os.reload_environment()could be taken to mean.That misreading doesn't seem particularly likely to me though, and the fact this operation reloads both
os.environandos.environb(not justos.environ) makes me wary of the shorteros.reload_environ()name (it feels misleading to me in the same way that theos.environ.refresh()spelling is misleading).zooba commentedon Oct 31, 2024
I can't reasonably see
os.reload_environ()implying thatos.environbwouldn't also be reloaded. Certainly not as much as I can see someone thinking thatos.reload_environment()implies something other than "os.environwill be reloaded".Whereas
os.environ.refresh()could quite reasonably be assumed to have no impact onos.environb. So I think that's another argument in favour of the module-level function.Perhaps
os.reload_environs()feels more comfortable for covering bothos.environandos.environb? I don't have a strong preference about thes. My main concern is still the same as at the start - this function doesn't impact the (generic) environment of the process at all, it only affects what is contained in Python's cache of the environment, otherwise known asos.environ.pythongh-120057: Add os.reload_environ() function
vstinner commentedon Nov 1, 2024
I created PR gh-126268 to replace the
os.environ.refresh()method with a newos.reload_environ()function.IMO
reload_environ()is a good name since it remindsos.environ. I don't think that we should bother with the fact thatos.environbis also reloaded to name the function. Andreload_environment()is too long :-)gh-120057: Add os.reload_environ() function (#126268)
[-]Add os.environ.refresh() method[/-][+]Add os.reload_environ() function[/+]vstinner commentedon Nov 5, 2024
Done: I merged the PR. I close the issue.
pythongh-120057: Add os.reload_environ() function (python#126268)
pythongh-120057: Add os.reload_environ() function (python#126268)
gh-120057: add `os.reload_environ` to `__all__` (#140763)
pythongh-120057: add `os.reload_environ` to `__all__` (pythonGH-140763)
[3.14] gh-120057: add `os.reload_environ` to `__all__` (GH-140763) (#…
pythongh-120057: add `os.reload_environ` to `__all__` (python#140763)