mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-30 08:04:24 +08:00
Introduce _typeshed.GenericPath and _typeshed.AnyStr_co (#7970)
This commit is contained in:
@@ -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[
|
||||
|
||||
Reference in New Issue
Block a user