Skip to content
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

add new typing features #7169

Merged
merged 3 commits into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions stdlib/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ if sys.version_info >= (3, 8):
# TypedDict is a (non-subscriptable) special form.
TypedDict: object

if sys.version_info >= (3, 11):
Self: _SpecialForm
Never: _SpecialForm = ...

if sys.version_info < (3, 7):
class GenericMeta(type): ...

Expand Down Expand Up @@ -697,6 +701,10 @@ def cast(typ: str, val: Any) -> Any: ...
@overload
def cast(typ: object, val: Any) -> Any: ...

if sys.version_info >= (3, 11):
def reveal_type(__obj: _T) -> _T: ...
def assert_never(__arg: Never) -> Never: ...

# Type constructors

class NamedTuple(tuple[Any, ...]):
Expand Down
26 changes: 22 additions & 4 deletions stdlib/typing_extensions.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ def runtime_checkable(cls: _TC) -> _TC: ...
# This alias for above is kept here for backwards compatibility.
runtime = runtime_checkable
Final: _SpecialForm
Self: _SpecialForm
Required: _SpecialForm
NotRequired: _SpecialForm

def final(f: _F) -> _F: ...

Expand Down Expand Up @@ -103,7 +100,7 @@ class SupportsIndex(Protocol, metaclass=abc.ABCMeta):
@abc.abstractmethod
def __index__(self) -> int: ...

# PEP 612 support for Python < 3.9
# New things in 3.10
if sys.version_info >= (3, 10):
from typing import (
Concatenate as Concatenate,
Expand Down Expand Up @@ -137,3 +134,24 @@ else:
TypeAlias: _SpecialForm
TypeGuard: _SpecialForm
def is_typeddict(tp: object) -> bool: ...

# New things in 3.11
if sys.version_info >= (3, 11):
from typing import Never as Never, Self as Self, assert_never as assert_never, reveal_type as reveal_type
else:
Self: _SpecialForm
Never: _SpecialForm
def reveal_type(__obj: _T) -> _T: ...
def assert_never(__arg: NoReturn) -> NoReturn: ...

# Experimental (hopefully these will be in 3.11)
Required: _SpecialForm
NotRequired: _SpecialForm

def dataclass_transform(
*,
eq_default: bool = ...,
order_default: bool = ...,
kw_only_default: bool = ...,
field_descriptors: tuple[type[Any] | Callable[..., Any], ...] = ...,
) -> Callable[[_T], _T]: ...