Override os._Environ.__ior__ (#6921)

Supporting the `|=` operator for `os.environ` was introduced in Python 3.9. However,
this led to false negatives in type checking statements like `os.environ |= {"k": "v"}`
and `os.environ |= [("k", "v")]` because the definition inherited from
`typing.MutableMapping` was insufficient. This addresses that deficiency.

Fixes #6919.
This commit is contained in:
Matt Bogosian
2022-01-15 17:52:31 -06:00
committed by GitHub
parent 141ac273ae
commit f55dff80f0

View File

@@ -245,6 +245,13 @@ class _Environ(MutableMapping[AnyStr, AnyStr], Generic[AnyStr]):
def __setitem__(self, key: AnyStr, value: AnyStr) -> None: ...
def __iter__(self) -> Iterator[AnyStr]: ...
def __len__(self) -> int: ...
if sys.version_info >= (3, 9):
# We use @overload instead of a Union for reasons similar to those given for
# overloading MutableMapping.update in stdlib/typing.pyi
@overload
def __ior__(self: Self, value: Mapping[AnyStr, AnyStr]) -> Self: ...
@overload
def __ior__(self: Self, value: Iterable[tuple[AnyStr, AnyStr]]) -> Self: ...
environ: _Environ[str]
if sys.platform != "win32":