Skip to content

Clean up stubtest allowlist for typing #10205

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 9 commits into from
May 24, 2023
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
6 changes: 5 additions & 1 deletion stdlib/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ if sys.version_info >= (3, 11):
NotRequired: _SpecialForm
LiteralString: _SpecialForm

@_final
class TypeVarTuple:
@property
def __name__(self) -> str: ...
Expand All @@ -220,16 +221,19 @@ if sys.version_info >= (3, 11):
def __typing_prepare_subst__(self, alias: Incomplete, args: Incomplete) -> Incomplete: ...

if sys.version_info >= (3, 10):
@_final
class ParamSpecArgs:
@property
def __origin__(self) -> ParamSpec: ...
def __init__(self, origin: ParamSpec) -> None: ...

@_final
class ParamSpecKwargs:
@property
def __origin__(self) -> ParamSpec: ...
def __init__(self, origin: ParamSpec) -> None: ...

@_final
class ParamSpec:
@property
def __name__(self) -> str: ...
Expand Down Expand Up @@ -272,7 +276,7 @@ if sys.version_info >= (3, 10):

class NewType:
def __init__(self, name: str, tp: Any) -> None: ...
def __call__(self, x: _T) -> _T: ...
def __call__(self, __x: _T) -> _T: ...
def __or__(self, other: Any) -> _SpecialForm: ...
def __ror__(self, other: Any) -> _SpecialForm: ...
__supertype__: type
Expand Down
19 changes: 15 additions & 4 deletions stdlib/typing_extensions.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ from typing import ( # noqa: Y022,Y039
DefaultDict as DefaultDict,
Deque as Deque,
Mapping,
NewType as NewType,
NoReturn as NoReturn,
Sequence,
SupportsAbs as SupportsAbs,
Expand Down Expand Up @@ -97,6 +96,7 @@ __all__ = [
"runtime_checkable",
"Text",
"TypeAlias",
"TypeAliasType",
"TypeGuard",
"TYPE_CHECKING",
"Never",
Expand All @@ -106,6 +106,7 @@ __all__ = [
"clear_overloads",
"get_args",
"get_origin",
"get_original_bases",
"get_overloads",
"get_type_hints",
]
Expand Down Expand Up @@ -196,30 +197,40 @@ class SupportsIndex(Protocol, metaclass=abc.ABCMeta):
@abc.abstractmethod
def __index__(self) -> int: ...

# New things in 3.10
# New and changed things in 3.10
if sys.version_info >= (3, 10):
from typing import (
Concatenate as Concatenate,
NewType as NewType,
ParamSpecArgs as ParamSpecArgs,
ParamSpecKwargs as ParamSpecKwargs,
TypeAlias as TypeAlias,
TypeGuard as TypeGuard,
is_typeddict as is_typeddict,
)
else:
@final
class ParamSpecArgs:
__origin__: ParamSpec
@property
def __origin__(self) -> ParamSpec: ...
def __init__(self, origin: ParamSpec) -> None: ...

@final
class ParamSpecKwargs:
__origin__: ParamSpec
@property
def __origin__(self) -> ParamSpec: ...
def __init__(self, origin: ParamSpec) -> None: ...

Concatenate: _SpecialForm
TypeAlias: _SpecialForm
TypeGuard: _SpecialForm
def is_typeddict(tp: object) -> bool: ...

class NewType:
def __init__(self, name: str, tp: Any) -> None: ...
def __call__(self, __x: _T) -> _T: ...
__supertype__: type

# New things in 3.11
# NamedTuples are not new, but the ability to create generic NamedTuples is new in 3.11
if sys.version_info >= (3, 11):
Expand Down
11 changes: 11 additions & 0 deletions tests/stubtest_allowlists/py310.txt
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,14 @@ dataclasses.KW_ONLY

# We pretend it's a read-only property for forward compatibility with 3.12
typing.ParamSpec(Args|Kwargs).__origin__

# https://github.com/python/mypy/issues/15302
typing_extensions\.assert_never
typing_extensions\.assert_type
typing_extensions\.reveal_type
typing.NewType.__call__

# Super-special typing primitives
typing_extensions\.Final
typing\.NamedTuple
typing\.Annotated
6 changes: 5 additions & 1 deletion tests/stubtest_allowlists/py311.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ contextlib.AbstractAsyncContextManager.__class_getitem__
contextlib.AbstractContextManager.__class_getitem__

# Super-special typing primitives
typing._SpecialForm.__mro_entries__
typing\._SpecialForm.*
typing._TypedDict.__delitem__
typing._TypedDict.__ior__
typing._TypedDict.__or__
Expand All @@ -137,6 +137,10 @@ typing._TypedDict.pop
typing._TypedDict.setdefault
typing._TypedDict.update
typing._TypedDict.values
typing_extensions\.Final
typing\.NamedTuple
typing\.LiteralString
typing\.Annotated

# White lies around defaults
dataclasses.KW_ONLY
Expand Down
8 changes: 8 additions & 0 deletions tests/stubtest_allowlists/py37.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,11 @@ types.GetSetDescriptorType.__get__
types.MemberDescriptorType.__get__
types.MethodDescriptorType.__get__
types.WrapperDescriptorType.__get__

# https://github.com/python/mypy/issues/15302
typing_extensions\.assert_never
typing_extensions\.assert_type
typing_extensions\.reveal_type

# Doesn't exist at runtime
typing\.Protocol
8 changes: 8 additions & 0 deletions tests/stubtest_allowlists/py38.txt
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,11 @@ types.GetSetDescriptorType.__get__
types.MemberDescriptorType.__get__
types.MethodDescriptorType.__get__
types.WrapperDescriptorType.__get__

# https://github.com/python/mypy/issues/15302
typing_extensions\.assert_never
typing_extensions\.assert_type
typing_extensions\.reveal_type

# Super-special typing primitives
typing_extensions\.Final
10 changes: 10 additions & 0 deletions tests/stubtest_allowlists/py39.txt
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,13 @@ types.GetSetDescriptorType.__get__
types.MemberDescriptorType.__get__
types.MethodDescriptorType.__get__
types.WrapperDescriptorType.__get__

# https://github.com/python/mypy/issues/15302
typing_extensions\.assert_never
typing_extensions\.assert_type
typing_extensions\.reveal_type

# Super-special typing primitives
typing_extensions\.Final
typing\.NamedTuple
typing\.Annotated
65 changes: 62 additions & 3 deletions tests/stubtest_allowlists/py3_common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,68 @@ pickle.Unpickler.memo # undocumented implementation detail, has different type
re.Pattern.scanner # Undocumented and not useful. #6405
tempfile._TemporaryFileWrapper.[\w_]+ # Dynamically specified by __getattr__, and thus don't exist on the class

# Various classes in typing aren't types at runtime. In addition, mypy thinks some special forms are tautologically defined.
typing.[A-Z]\w+
typing_extensions\..*
# Details of runtime definition don't need to be in stubs
typing_extensions\._SpecialForm.*
typing_extensions\.TypeVar.*
typing_extensions\.ParamSpec.*
typing\.Generic
typing\.Protocol

# Special primitives
typing_extensions\.Annotated
typing_extensions\.NamedTuple
typing_extensions\.LiteralString
typing_extensions\.Coroutine
typing_extensions\.Awaitable
typing_extensions\.AsyncIterator
typing_extensions\.AsyncIterable
typing_extensions\.AsyncGenerator
typing\.ValuesView
typing\.Sized
typing\.Sequence
typing\.Reversible
typing\.Pattern
typing\.MutableSet
typing\.MutableSequence
typing\.MutableMapping
typing\.Match
typing\.MappingView
typing\.Mapping
typing\.KeysView
typing\.Iterator
typing\.Iterable
typing\.ItemsView
typing\.Hashable
typing\.Generator
typing\.Coroutine
typing\.Collection
typing\.Container
typing\.ByteString
typing\.AwaitableGenerator
typing\.Awaitable
typing\.AsyncIterator
typing\.AsyncIterable
typing\.AsyncGenerator
typing\.AbstractSet

# Internal attributes
.*\.__protocol_attrs__
.*\.__callable_proto_members_only__
Comment on lines +454 to +456
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

python/mypy#15294 means we should be able to remove these, come the next mypy release

(No change requested)


# Exist at runtime for internal reasons, no need to put them in the stub
typing_extensions\.TypeAliasType\.__call__
typing_extensions\.TypeAliasType\.__init_subclass__

typing_extensions.NewType.__mro_entries__ # just exists for an error message

# We call them read-only properties, runtime implementation is slightly different
typing_extensions\.TypeAliasType\.__(parameters|type_params|name|module|value)__

# https://github.com/python/mypy/issues/15302
typing_extensions.NewType.__call__
typing_extensions\.deprecated
typing_extensions\.get_original_bases
typing_extensions\.override

# These are abstract properties at runtime,
# but marking them as such in the stub breaks half the the typed-Python ecosystem (see #8726)
Expand Down