Introduce _typeshed.GenericPath and _typeshed.AnyStr_co (#7970)

This commit is contained in:
Alex Waygood
2022-05-27 19:02:00 +01:00
committed by GitHub
parent f52da1e8b0
commit ceccc655db
6 changed files with 44 additions and 47 deletions

View File

@@ -10,7 +10,7 @@ import sys
from collections.abc import Awaitable, Container, Iterable, Set as AbstractSet
from os import PathLike
from types import TracebackType
from typing import Any, Generic, Protocol, TypeVar, Union
from typing import Any, AnyStr, Generic, Protocol, TypeVar, Union
from typing_extensions import Final, Literal, LiteralString, TypeAlias, final
_KT = TypeVar("_KT")
@@ -26,6 +26,9 @@ _T_contra = TypeVar("_T_contra", contravariant=True)
# def __enter__(self: Self) -> Self: ...
Self = TypeVar("Self") # noqa: Y001
# covariant version of typing.AnyStr, useful for protocols
AnyStr_co = TypeVar("AnyStr_co", str, bytes, covariant=True) # noqa: Y001
# For partially known annotations. Usually, fields where type annotations
# haven't been added are left unannotated, but in some situations this
# isn't possible or a type is already partially known. In cases like these,
@@ -112,9 +115,9 @@ class SupportsItemAccess(SupportsGetItem[_KT_contra, _VT], Protocol[_KT_contra,
def __setitem__(self, __k: _KT_contra, __v: _VT) -> None: ...
def __delitem__(self, __v: _KT_contra) -> None: ...
# These aliases are simple strings in Python 2.
StrPath: TypeAlias = str | PathLike[str] # stable
BytesPath: TypeAlias = bytes | PathLike[bytes] # stable
GenericPath: TypeAlias = AnyStr | PathLike[AnyStr]
StrOrBytesPath: TypeAlias = str | bytes | PathLike[str] | PathLike[bytes] # stable
OpenTextModeUpdating: TypeAlias = Literal[