Update typing-extensions; some 3.12 updates (#10200)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
Jelle Zijlstra
2023-05-24 11:06:55 -07:00
committed by GitHub
parent e666602d14
commit e4dcfccbd5
6 changed files with 195 additions and 33 deletions

View File

@@ -1,4 +1,5 @@
import sys
from abc import abstractmethod
from types import MappingProxyType
from typing import ( # noqa: Y022,Y038
AbstractSet as Set,
@@ -23,11 +24,13 @@ from typing import ( # noqa: Y022,Y038
MutableMapping as MutableMapping,
MutableSequence as MutableSequence,
MutableSet as MutableSet,
Protocol,
Reversible as Reversible,
Sequence as Sequence,
Sized as Sized,
TypeVar,
ValuesView as ValuesView,
runtime_checkable,
)
from typing_extensions import final
@@ -58,6 +61,8 @@ __all__ = [
"MutableSequence",
"ByteString",
]
if sys.version_info >= (3, 12):
__all__ += ["Buffer"]
_KT_co = TypeVar("_KT_co", covariant=True) # Key type covariant containers.
_VT_co = TypeVar("_VT_co", covariant=True) # Value type covariant containers.
@@ -79,3 +84,9 @@ class dict_items(ItemsView[_KT_co, _VT_co], Generic[_KT_co, _VT_co]): # undocum
if sys.version_info >= (3, 10):
@property
def mapping(self) -> MappingProxyType[_KT_co, _VT_co]: ...
if sys.version_info >= (3, 12):
@runtime_checkable
class Buffer(Protocol):
@abstractmethod
def __buffer__(self, __flags: int) -> memoryview: ...

View File

@@ -598,3 +598,25 @@ def classify_class_attrs(cls: type) -> list[Attribute]: ...
if sys.version_info >= (3, 9):
class ClassFoundException(Exception): ...
if sys.version_info >= (3, 12):
class BufferFlags(enum.IntFlag):
SIMPLE: int
WRITABLE: int
FORMAT: int
ND: int
STRIDES: int
C_CONTIGUOUS: int
F_CONTIGUOUS: int
ANY_CONTIGUOUS: int
INDIRECT: int
CONTIG: int
CONTIG_RO: int
STRIDED: int
STRIDED_RO: int
RECORDS: int
RECORDS_RO: int
FULL: int
FULL_RO: int
READ: int
WRITE: int

View File

@@ -136,14 +136,32 @@ Any = object()
@_final
class TypeVar:
__name__: str
__bound__: Any | None
__constraints__: tuple[Any, ...]
__covariant__: bool
__contravariant__: bool
def __init__(
self, name: str, *constraints: Any, bound: Any | None = None, covariant: bool = False, contravariant: bool = False
) -> None: ...
@property
def __name__(self) -> str: ...
@property
def __bound__(self) -> Any | None: ...
@property
def __constraints__(self) -> tuple[Any, ...]: ...
@property
def __covariant__(self) -> bool: ...
@property
def __contravariant__(self) -> bool: ...
if sys.version_info >= (3, 12):
@property
def __infer_variance__(self) -> bool: ...
def __init__(
self,
name: str,
*constraints: Any,
bound: Any | None = None,
covariant: bool = False,
contravariant: bool = False,
infer_variance: bool = False,
) -> None: ...
else:
def __init__(
self, name: str, *constraints: Any, bound: Any | None = None, covariant: bool = False, contravariant: bool = False
) -> None: ...
if sys.version_info >= (3, 10):
def __or__(self, right: Any) -> _SpecialForm: ...
def __ror__(self, left: Any) -> _SpecialForm: ...
@@ -194,7 +212,8 @@ if sys.version_info >= (3, 11):
LiteralString: _SpecialForm
class TypeVarTuple:
__name__: str
@property
def __name__(self) -> str: ...
def __init__(self, name: str) -> None: ...
def __iter__(self) -> Any: ...
def __typing_subst__(self, arg: Never) -> Never: ...
@@ -202,21 +221,41 @@ if sys.version_info >= (3, 11):
if sys.version_info >= (3, 10):
class ParamSpecArgs:
__origin__: ParamSpec
@property
def __origin__(self) -> ParamSpec: ...
def __init__(self, origin: ParamSpec) -> None: ...
class ParamSpecKwargs:
__origin__: ParamSpec
@property
def __origin__(self) -> ParamSpec: ...
def __init__(self, origin: ParamSpec) -> None: ...
class ParamSpec:
__name__: str
__bound__: Any | None
__covariant__: bool
__contravariant__: bool
def __init__(
self, name: str, *, bound: Any | None = None, contravariant: bool = False, covariant: bool = False
) -> None: ...
@property
def __name__(self) -> str: ...
@property
def __bound__(self) -> Any | None: ...
@property
def __covariant__(self) -> bool: ...
@property
def __contravariant__(self) -> bool: ...
if sys.version_info >= (3, 12):
@property
def __infer_variance__(self) -> bool: ...
def __init__(
self,
name: str,
*,
bound: Any | None = None,
contravariant: bool = False,
covariant: bool = False,
infer_variance: bool = False,
) -> None: ...
else:
def __init__(
self, name: str, *, bound: Any | None = None, contravariant: bool = False, covariant: bool = False
) -> None: ...
@property
def args(self) -> ParamSpecArgs: ...
@property
@@ -873,3 +912,26 @@ if sys.version_info >= (3, 10):
def is_typeddict(tp: object) -> bool: ...
def _type_repr(obj: object) -> str: ...
if sys.version_info >= (3, 12):
def override(__arg: _F) -> _F: ...
@_final
class TypeAliasType:
def __init__(
self, name: str, value: Any, *, type_params: tuple[TypeVar | ParamSpec | TypeVarTuple, ...] = ()
) -> None: ...
@property
def __value__(self) -> Any: ...
@property
def __type_params__(self) -> tuple[TypeVar | ParamSpec | TypeVarTuple, ...]: ...
@property
def __parameters__(self) -> tuple[Any, ...]: ...
@property
def __name__(self) -> str: ...
# It's writable on types, but not on instances of TypeAliasType.
@property
def __module__(self) -> str | None: ... # type: ignore[override]
def __getitem__(self, parameters: Any) -> Any: ...
if sys.version_info >= (3, 10):
def __or__(self, right: Any) -> _SpecialForm: ...
def __ror__(self, left: Any) -> _SpecialForm: ...

View File

@@ -25,6 +25,12 @@ from typing import ( # noqa: Y022,Y039
NewType as NewType,
NoReturn as NoReturn,
Sequence,
SupportsAbs as SupportsAbs,
SupportsBytes as SupportsBytes,
SupportsComplex as SupportsComplex,
SupportsFloat as SupportsFloat,
SupportsInt as SupportsInt,
SupportsRound as SupportsRound,
Text as Text,
Type as Type,
_Alias,
@@ -39,6 +45,7 @@ if sys.version_info >= (3, 9):
__all__ = [
"Any",
"Buffer",
"ClassVar",
"Concatenate",
"Final",
@@ -66,6 +73,12 @@ __all__ = [
"OrderedDict",
"TypedDict",
"SupportsIndex",
"SupportsAbs",
"SupportsRound",
"SupportsBytes",
"SupportsComplex",
"SupportsFloat",
"SupportsInt",
"Annotated",
"assert_never",
"assert_type",
@@ -272,16 +285,24 @@ else:
# New things in 3.xx
# The `default` parameter was added to TypeVar, ParamSpec, and TypeVarTuple (PEP 696)
# The `infer_variance` parameter was added to TypeVar (PEP 695)
# The `infer_variance` parameter was added to TypeVar in 3.12 (PEP 695)
# typing_extensions.override (PEP 698)
@final
class TypeVar:
__name__: str
__bound__: Any | None
__constraints__: tuple[Any, ...]
__covariant__: bool
__contravariant__: bool
__default__: Any | None
@property
def __name__(self) -> str: ...
@property
def __bound__(self) -> Any | None: ...
@property
def __constraints__(self) -> tuple[Any, ...]: ...
@property
def __covariant__(self) -> bool: ...
@property
def __contravariant__(self) -> bool: ...
@property
def __infer_variance__(self) -> bool: ...
@property
def __default__(self) -> Any | None: ...
def __init__(
self,
name: str,
@@ -300,11 +321,18 @@ class TypeVar:
@final
class ParamSpec:
__name__: str
__bound__: type[Any] | None
__covariant__: bool
__contravariant__: bool
__default__: type[Any] | None
@property
def __name__(self) -> str: ...
@property
def __bound__(self) -> Any | None: ...
@property
def __covariant__(self) -> bool: ...
@property
def __contravariant__(self) -> bool: ...
@property
def __infer_variance__(self) -> bool: ...
@property
def __default__(self) -> Any | None: ...
def __init__(
self,
name: str,
@@ -321,10 +349,41 @@ class ParamSpec:
@final
class TypeVarTuple:
__name__: str
__default__: Any | None
@property
def __name__(self) -> str: ...
@property
def __default__(self) -> Any | None: ...
def __init__(self, name: str, *, default: Any | None = None) -> None: ...
def __iter__(self) -> Any: ... # Unpack[Self]
def override(__arg: _F) -> _F: ...
def deprecated(__msg: str, *, category: type[Warning] | None = ..., stacklevel: int = 1) -> Callable[[_T], _T]: ...
if sys.version_info >= (3, 12):
from collections.abc import Buffer as Buffer
from types import get_original_bases as get_original_bases
from typing import TypeAliasType as TypeAliasType, override as override
else:
def override(__arg: _F) -> _F: ...
def get_original_bases(__cls: type) -> tuple[Any, ...]: ...
@final
class TypeAliasType:
def __init__(
self, name: str, value: Any, *, type_params: tuple[TypeVar | ParamSpec | TypeVarTuple, ...] = ()
) -> None: ...
@property
def __value__(self) -> Any: ...
@property
def __type_params__(self) -> tuple[TypeVar | ParamSpec | TypeVarTuple, ...]: ...
@property
def __parameters__(self) -> tuple[Any, ...]: ...
@property
def __name__(self) -> str: ...
# It's writable on types, but not on instances of TypeAliasType.
@property
def __module__(self) -> str | None: ... # type: ignore[override]
def __getitem__(self, parameters: Any) -> Any: ...
if sys.version_info >= (3, 10):
def __or__(self, right: Any) -> _SpecialForm: ...
def __ror__(self, left: Any) -> _SpecialForm: ...
class Buffer(abc.ABC): ...

View File

@@ -169,3 +169,6 @@ ast.ImportFrom.level # None on the class, but never None on instances
# White lies around defaults
dataclasses.KW_ONLY
# We pretend it's a read-only property for forward compatibility with 3.12
typing.ParamSpec(Args|Kwargs).__origin__

View File

@@ -140,3 +140,8 @@ typing._TypedDict.values
# White lies around defaults
dataclasses.KW_ONLY
# We pretend it's a read-only property for forward compatibility with 3.12
typing.ParamSpec(Args|Kwargs).__origin__
typing\.TypeVar\.__.*__
typing\.ParamSpec\.__.*__