GeezerVison is showing github.com — Add os.reload_environ() function · Issue #120057 · python/cpython
Add os.reload_environ() function #120057DescriptionReacted by Agriya Khetarpal, Kirill Podoprigora and W. H. Wang Reacted by Noam Cohen and sigma67 Reacted by EDM115 Activityeryksun commented on Jun 4, 2024 Note that on Windows the C runtime's Unicode and multibyte environments -- _wenviron and _environ -- can get out of sync with the process environment -- GetEnvironmentStringsW() -- due to code that directly calls WinAPI SetEnvironmentVariableW(). It's possible to implement a function to fresh the C environment on Windows, which unsets the variables in _wenviron and sets the variables from GetEnvironmentStringsW(), but that's probably not something that the Python runtime needs to worry about. vstinner commented on Jun 5, 2024
but that's probably not something that the Python runtime needs to worry about
As soon as there are different "caches", it's hard to keep everything in sync and consistent :-( erlend-aasland commented on Jun 5, 2024 I'm not sure if this is a good idea. I suspect it will be a hard feature to get right, and as noted in the forum discussion, most beginners will misunderstand the feature. vstinner commented on Jun 5, 2024
I suspect it will be a hard feature to get right
Would you mind to elaborate? vstinner commented on Jun 5, 2024 Reacted by Erlend E. Aasland picnixz commented on Jun 5, 2024 FYI, there was this issue: #119737 (so you may want to close it to avoid duplicates) Reacted by Erlend E. Aasland vstinner commented on Jun 5, 2024 I closed issue #119737 as a duplicate of this issue. vstinner commented on Jun 11, 2024 WolfDWyc commented on Jun 11, 2024 @vstinner
As I noted in the discourse thread, and was mentioned in the comment on the PR, I still feel like this name will be confusing for new users, even with docs clarifying it. Can we maybe re-discuss this? Or at least choose another name?
Should we continue here or in the discourse thread? Reacted by Erlend E. Aasland ncoghlan commented on 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.environ and os.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). zooba commented on Oct 31, 2024 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. vstinner commented on Nov 1, 2024 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 :-) changed the title [-]Add os.environ.refresh() method[/-] [+]Add os.reload_environ() function[/+] on Nov 5, 2024vstinner commented on Nov 5, 2024
I created PR #126268 to replace the os.environ.refresh() method with a new os.reload_environ() function.
Done: I merged the PR. I close the issue.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|