bpo-36144: Update os.environ and os.environb for PEP 584 (#18911)

This commit is contained in:
Charles Burkland 2020-03-13 09:04:43 -07:00 committed by GitHub
parent 38965ec541
commit d648ef10c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 118 additions and 1 deletions

View file

@ -659,7 +659,7 @@ def get_exec_path(env=None):
# Change environ to automatically call putenv() and unsetenv()
from _collections_abc import MutableMapping
from _collections_abc import MutableMapping, Mapping
class _Environ(MutableMapping):
def __init__(self, data, encodekey, decodekey, encodevalue, decodevalue):
@ -714,6 +714,24 @@ class _Environ(MutableMapping):
self[key] = value
return self[key]
def __ior__(self, other):
self.update(other)
return self
def __or__(self, other):
if not isinstance(other, Mapping):
return NotImplemented
new = dict(self)
new.update(other)
return new
def __ror__(self, other):
if not isinstance(other, Mapping):
return NotImplemented
new = dict(other)
new.update(self)
return new
def _createenviron():
if name == 'nt':
# Where Env Var Names Must Be UPPERCASE