-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement os.unsetenv() on Windows #83594
Comments
os.unsetenv() is documented to be available on Windows, but it's not. In Python 3.8, "del os.environ[key]" is implemented as: os.putenv(key.upper(), "") Attached PR implements it using SetEnvironmentVariableW(name, NULL). |
This bypasses the CRT's copy of the environment. If any C code calls [_w]getenv, it will still see the variable defined. The only way it won't is if setting the value also bypassed the CRT environment by directly calling SetEnvironmentVariableW. |
Oh. That's a valid concern. I reopen the issue. |
I checked the doc: _putenv("VAR=") removes the environment variable "VAR". It's well documented: https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/putenv-wputenv?view=vs-2019 "You can remove a variable from the environment by specifying an empty value_string, or in other words, by specifying only varname=." So Python 3.8 os._unsetenv() is correct, but this function was not exposed, and so this issue remains relevant: Python 3.8 documents that os.unsetenv() is available on Windows, but it's not. |
PR 18107 still fix this issue (add os.unsetenv() to Python 3.9 on Windows), but fix the implementation (use _wputenv() rather than SetEnvironmentVariableW(), to update the CRT). |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: