mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-08 13:04:46 +08:00
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:
@@ -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":
|
||||
|
||||
Reference in New Issue
Block a user