Repository navigation
Enhance test.support.os_helper.EnvironmentVarGuard interface #131277
Copy link
Copy link
Closed
Labels
3.12only security fixesonly security fixes3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytestsTests in the Lib/test dirTests in the Lib/test dirtriagedThe issue has been accepted as valid by a triager.The issue has been accepted as valid by a triager.type-featureA feature request or enhancementA feature request or enhancement
Description
Activity
added on Mar 15, 2025
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
testsTests in the Lib/test dirTests in the Lib/test dir
type-featureA feature request or enhancementA feature request or enhancement
Ok, nvm actually __del__ checks for the presence of the variable. So we have useless checks :')
Reacted by Cody Maloney
added on Mar 15, 2025
pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is provided
and removed pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is provided
added a commit that references this issue on Mar 16, 2025
Keeping the issue opened until we decide whether to backport this or not to ease future backports.
added on Mar 18, 2025
3.12only security fixesonly security fixes
3.13only security fixesonly security fixes
3.14bugs and security fixesbugs and security fixes
Adding the version labels as I decided to backport this to ease future development. However, the API will not be publicly documented.
added on Mar 18, 2025
triagedThe issue has been accepted as valid by a triager.The issue has been accepted as valid by a triager.
Metadata
Metadata
Assignees
Labels
3.12only security fixesonly security fixes3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytestsTests in the Lib/test dirTests in the Lib/test dirtriagedThe issue has been accepted as valid by a triager.The issue has been accepted as valid by a triager.type-featureA feature request or enhancementA feature request or enhancement
Feature or enhancement
Currently, we have a lot of pattern of the form:
I think it makes sense to have something like this:
or to also provide a decorator-based approach when the values to set/unset are statically known.
Features
env.unset(k1, k2, ...)Some optional features that I rejected after looking at the use cases:
I plan to create a PR today or tomorrow to illustrate the new interface.
EDIT: no need to the support for setting multiple variables at once because
EnvironmentVarGuardis a mapping, so it has.update()which does the trick.Linked PRs
EnvironmentVarGuardto unset more than one environment variable at once #131280See #131277 (comment) for the version labels rationale and #131280 (comment) for the backporte rationale.