Skip to content

Update typing-extensions; some 3.12 updates #10200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
6664a00
Update typing-extensions; some 3.12 updates
JelleZijlstra May 23, 2023
ea4c90e
clean
JelleZijlstra May 23, 2023
1f42ee3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 23, 2023
12df74b
Fix name conflicts
JelleZijlstra May 23, 2023
060bd3c
missed some
JelleZijlstra May 23, 2023
cfd5be2
Maybe flake8 will like this
JelleZijlstra May 23, 2023
ef6698c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 23, 2023
8d2800e
Undo AST changes
JelleZijlstra May 23, 2023
10a065c
Update stdlib/typing.pyi
JelleZijlstra May 23, 2023
2779a39
Update stdlib/typing_extensions.pyi
JelleZijlstra May 23, 2023
dcb2f99
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 23, 2023
4461707
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 23, 2023
50af9b4
Update stdlib/_collections_abc.pyi
JelleZijlstra May 23, 2023
2813cff
what is an abstractmethod
JelleZijlstra May 23, 2023
15ad706
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 23, 2023
2bb54f0
Update stdlib/_collections_abc.pyi
JelleZijlstra May 23, 2023
f8ee085
CI-driven development
JelleZijlstra May 23, 2023
4168a7e
More CI-driven development
AlexWaygood May 23, 2023
052197c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 23, 2023
8feb81d
properties all around
JelleZijlstra May 24, 2023
e9dfb2b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 24, 2023
63ed9e3
__module__ can be None
JelleZijlstra May 24, 2023
4a944c1
Ignore mypy error
JelleZijlstra May 24, 2023
2973ebd
Also ignore on typing-extensions
JelleZijlstra May 24, 2023
d0d7e67
lies
JelleZijlstra May 24, 2023
059d8ce
More lies
JelleZijlstra May 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions stdlib/_collections_abc.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
from abc import abstractmethod
from types import MappingProxyType
from typing import ( # noqa: Y022,Y038
AbstractSet as Set,
Expand All @@ -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

Expand Down Expand Up @@ -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.
Expand All @@ -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: ...
22 changes: 22 additions & 0 deletions stdlib/inspect.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
98 changes: 80 additions & 18 deletions stdlib/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Expand Down Expand Up @@ -194,29 +212,50 @@ 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: ...
def __typing_prepare_subst__(self, alias: Incomplete, args: Incomplete) -> Incomplete: ...

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
Expand Down Expand Up @@ -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: ...
89 changes: 74 additions & 15 deletions stdlib/typing_extensions.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -39,6 +45,7 @@ if sys.version_info >= (3, 9):

__all__ = [
"Any",
"Buffer",
"ClassVar",
"Concatenate",
"Final",
Expand Down Expand Up @@ -66,6 +73,12 @@ __all__ = [
"OrderedDict",
"TypedDict",
"SupportsIndex",
"SupportsAbs",
"SupportsRound",
"SupportsBytes",
"SupportsComplex",
"SupportsFloat",
"SupportsInt",
"Annotated",
"assert_never",
"assert_type",
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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): ...
3 changes: 3 additions & 0 deletions tests/stubtest_allowlists/py310.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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__
5 changes: 5 additions & 0 deletions tests/stubtest_allowlists/py311.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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\.__.*__