Navigation Menu

Skip to content
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

Closed
vstinner opened this issue Jan 21, 2020 · 10 comments
Closed

Implement os.unsetenv() on Windows #83594

vstinner opened this issue Jan 21, 2020 · 10 comments
Labels
3.9 only security fixes OS-windows stdlib Python modules in the Lib dir

Comments

@vstinner
Copy link
Member

BPO 39413
Nosy @pfmoore, @vstinner, @tjguk, @zware, @eryksun, @zooba, @miss-islington
PRs
  • bpo-39413: Implement os.unsetenv() on Windows #18104
  • bpo-39413: Use _wputenv(), not SetEnvironmentVariableW() #18107
  • [3.8] bpo-39413: os.unsetenv() is not available on Windows #18108
  • [3.7] bpo-39413: os.unsetenv() is not available on Windows (GH-18108) #18114
  • [WIP] bpo-39413: os.unsetenv() uses _wputenv() on Windows #18115
  • Revert "bpo-39413: Implement os.unsetenv() on Windows (GH-18104)" #18124
  • bpo-39413: Implement os.unsetenv() on Windows #18163
  • 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:

    assignee = None
    closed_at = <Date 2020-01-28.02:08:26.530>
    created_at = <Date 2020-01-21.14:39:20.002>
    labels = ['library', '3.9', 'OS-windows']
    title = 'Implement os.unsetenv() on Windows'
    updated_at = <Date 2020-01-28.02:08:26.529>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2020-01-28.02:08:26.529>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-01-28.02:08:26.530>
    closer = 'vstinner'
    components = ['Library (Lib)', 'Windows']
    creation = <Date 2020-01-21.14:39:20.002>
    creator = 'vstinner'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 39413
    keywords = ['patch']
    message_count = 10.0
    messages = ['360402', '360403', '360404', '360418', '360420', '360423', '360462', '360463', '360503', '360609']
    nosy_count = 7.0
    nosy_names = ['paul.moore', 'vstinner', 'tim.golden', 'zach.ware', 'eryksun', 'steve.dower', 'miss-islington']
    pr_nums = ['18104', '18107', '18108', '18114', '18115', '18124', '18163']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue39413'
    versions = ['Python 3.9']

    @vstinner
    Copy link
    Member Author

    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).

    @vstinner vstinner added 3.9 only security fixes stdlib Python modules in the Lib dir OS-windows labels Jan 21, 2020
    @vstinner
    Copy link
    Member Author

    New changeset 56cd371 by Victor Stinner in branch 'master':
    bpo-39413: Implement os.unsetenv() on Windows (GH-18104)
    56cd371

    @eryksun
    Copy link
    Contributor

    eryksun commented Jan 21, 2020

    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.

    @vstinner
    Copy link
    Member Author

    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.

    @vstinner vstinner reopened this Jan 21, 2020
    @vstinner vstinner reopened this Jan 21, 2020
    @vstinner
    Copy link
    Member Author

    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.

    @vstinner
    Copy link
    Member Author

    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).

    @vstinner
    Copy link
    Member Author

    New changeset f84f65b by Victor Stinner in branch '3.8':
    bpo-39413: os.unsetenv() is not available on Windows (GH-18108)
    f84f65b

    @miss-islington
    Copy link
    Contributor

    New changeset 5707246 by Miss Islington (bot) in branch '3.7':
    bpo-39413: os.unsetenv() is not available on Windows (GH-18108)
    5707246

    @vstinner
    Copy link
    Member Author

    New changeset b73dd02 by Victor Stinner in branch 'master':
    Revert "bpo-39413: Implement os.unsetenv() on Windows (GH-18104)" (GH-18124)
    b73dd02

    @vstinner
    Copy link
    Member Author

    New changeset 161e7b3 by Victor Stinner in branch 'master':
    bpo-39413: Implement os.unsetenv() on Windows (GH-18163)
    161e7b3

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes OS-windows stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants