From d1ce6c8e712fe2887b9cc08dc494d47d439e8ae4 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Wed, 18 May 2022 20:42:46 +0200 Subject: [PATCH 1/5] Use "all +=" instead of duplicating the branches --- stdlib/typing.pyi | 534 ++++++++-------------------------------------- 1 file changed, 90 insertions(+), 444 deletions(-) diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index 37ea55c9f2ef..07575b6edbd9 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -11,466 +11,112 @@ if sys.version_info >= (3, 7): if sys.version_info >= (3, 9): from types import GenericAlias -if sys.version_info >= (3, 11): - __all__ = [ - "Annotated", - "Any", - "Callable", - "ClassVar", - "Concatenate", - "Final", - "ForwardRef", - "Generic", - "Literal", - "LiteralString", - "NotRequired", - "Optional", - "ParamSpec", - "Protocol", - "Required", - "Tuple", - "Type", - "TypeVar", - "TypeVarTuple", - "Union", - "Unpack", - "AbstractSet", - "ByteString", - "Container", - "ContextManager", - "Hashable", - "ItemsView", - "Iterable", - "Iterator", - "KeysView", - "Mapping", - "MappingView", - "MutableMapping", - "MutableSequence", - "MutableSet", - "Sequence", - "Sized", - "ValuesView", - "Awaitable", - "AsyncIterator", - "AsyncIterable", - "Coroutine", - "Collection", - "AsyncGenerator", +__all__ = [ + "AbstractSet", + "Any", + "AnyStr", + "ByteString", + "Callable", + "ClassVar", + "Container", + "ContextManager", + "Counter", + "DefaultDict", + "Deque", + "Dict", + "FrozenSet", + "Generator", + "Generic", + "Hashable", + "ItemsView", + "Iterable", + "Iterator", + "KeysView", + "List", + "Mapping", + "MappingView", + "MutableMapping", + "MutableSequence", + "MutableSet", + "NamedTuple", + "NewType", + "Optional", + "Reversible", + "Sequence", + "Set", + "Sized", + "SupportsAbs", + "SupportsBytes", + "SupportsComplex", + "SupportsFloat", + "SupportsInt", + "SupportsRound", + "Text", + "Tuple", + "Type", + "TypeVar", + "Union", + "ValuesView", + "TYPE_CHECKING", + "cast", + "get_type_hints", + "no_type_check", + "no_type_check_decorator", + "overload", +] + +if sys.version_info < (3, 7): + __all__ += ["GenericMeta"] + +if sys.version_info >= (3, 7): + __all__ += [ "AsyncContextManager", - "Reversible", - "SupportsAbs", - "SupportsBytes", - "SupportsComplex", - "SupportsFloat", - "SupportsIndex", - "SupportsInt", - "SupportsRound", - "ChainMap", - "Counter", - "Deque", - "Dict", - "DefaultDict", - "List", - "OrderedDict", - "Set", - "FrozenSet", - "NamedTuple", - "TypedDict", - "Generator", - "BinaryIO", - "IO", - "Match", - "Pattern", - "TextIO", - "AnyStr", - "assert_never", - "assert_type", - "cast", - "clear_overloads", - "dataclass_transform", - "final", - "get_args", - "get_origin", - "get_overloads", - "get_type_hints", - "is_typeddict", - "Never", - "NewType", - "no_type_check", - "no_type_check_decorator", - "NoReturn", - "overload", - "ParamSpecArgs", - "ParamSpecKwargs", - "reveal_type", - "runtime_checkable", - "Self", - "Text", - "TYPE_CHECKING", - "TypeAlias", - "TypeGuard", - ] -elif sys.version_info >= (3, 10): - __all__ = [ - "Annotated", - "Any", - "Callable", - "ClassVar", - "Concatenate", - "Final", - "ForwardRef", - "Generic", - "Literal", - "Optional", - "ParamSpec", - "Protocol", - "Tuple", - "Type", - "TypeVar", - "Union", - "AbstractSet", - "ByteString", - "Container", - "ContextManager", - "Hashable", - "ItemsView", - "Iterable", - "Iterator", - "KeysView", - "Mapping", - "MappingView", - "MutableMapping", - "MutableSequence", - "MutableSet", - "Sequence", - "Sized", - "ValuesView", - "Awaitable", - "AsyncIterator", - "AsyncIterable", - "Coroutine", - "Collection", "AsyncGenerator", - "AsyncContextManager", - "Reversible", - "SupportsAbs", - "SupportsBytes", - "SupportsComplex", - "SupportsFloat", - "SupportsIndex", - "SupportsInt", - "SupportsRound", - "ChainMap", - "Counter", - "Deque", - "Dict", - "DefaultDict", - "List", - "OrderedDict", - "Set", - "FrozenSet", - "NamedTuple", - "TypedDict", - "Generator", - "BinaryIO", - "IO", - "Match", - "Pattern", - "TextIO", - "AnyStr", - "cast", - "final", - "get_args", - "get_origin", - "get_type_hints", - "is_typeddict", - "NewType", - "no_type_check", - "no_type_check_decorator", - "NoReturn", - "overload", - "ParamSpecArgs", - "ParamSpecKwargs", - "runtime_checkable", - "Text", - "TYPE_CHECKING", - "TypeAlias", - "TypeGuard", - ] -elif sys.version_info >= (3, 9): - __all__ = [ - "Annotated", - "Any", - "Callable", - "ClassVar", - "Final", - "ForwardRef", - "Generic", - "Literal", - "Optional", - "Protocol", - "Tuple", - "Type", - "TypeVar", - "Union", - "AbstractSet", - "ByteString", - "Container", - "ContextManager", - "Hashable", - "ItemsView", - "Iterable", - "Iterator", - "KeysView", - "Mapping", - "MappingView", - "MutableMapping", - "MutableSequence", - "MutableSet", - "Sequence", - "Sized", - "ValuesView", - "Awaitable", - "AsyncIterator", "AsyncIterable", - "Coroutine", - "Collection", - "AsyncGenerator", - "AsyncContextManager", - "Reversible", - "SupportsAbs", - "SupportsBytes", - "SupportsComplex", - "SupportsFloat", - "SupportsIndex", - "SupportsInt", - "SupportsRound", + "AsyncIterator", + "Awaitable", "ChainMap", - "Counter", - "Deque", - "Dict", - "DefaultDict", - "List", - "OrderedDict", - "Set", - "FrozenSet", - "NamedTuple", - "TypedDict", - "Generator", - "BinaryIO", - "IO", - "Match", - "Pattern", - "TextIO", - "AnyStr", - "cast", - "final", - "get_args", - "get_origin", - "get_type_hints", - "NewType", - "no_type_check", - "no_type_check_decorator", + "Collection", + "Coroutine", + "ForwardRef", "NoReturn", - "overload", - "runtime_checkable", - "Text", - "TYPE_CHECKING", + "OrderedDict", ] -elif sys.version_info >= (3, 8): - __all__ = [ - "Any", - "Callable", - "ClassVar", + +if sys.version_info >= (3, 8): + __all__ += [ "Final", - "ForwardRef", - "Generic", "Literal", - "Optional", "Protocol", - "Tuple", - "Type", - "TypeVar", - "Union", - "AbstractSet", - "ByteString", - "Container", - "ContextManager", - "Hashable", - "ItemsView", - "Iterable", - "Iterator", - "KeysView", - "Mapping", - "MappingView", - "MutableMapping", - "MutableSequence", - "MutableSet", - "Sequence", - "Sized", - "ValuesView", - "Awaitable", - "AsyncIterator", - "AsyncIterable", - "Coroutine", - "Collection", - "AsyncGenerator", - "AsyncContextManager", - "Reversible", - "SupportsAbs", - "SupportsBytes", - "SupportsComplex", - "SupportsFloat", "SupportsIndex", - "SupportsInt", - "SupportsRound", - "ChainMap", - "Counter", - "Deque", - "Dict", - "DefaultDict", - "List", - "OrderedDict", - "Set", - "FrozenSet", - "NamedTuple", "TypedDict", - "Generator", - "AnyStr", - "cast", "final", "get_args", "get_origin", - "get_type_hints", - "NewType", - "no_type_check", - "no_type_check_decorator", - "NoReturn", - "overload", "runtime_checkable", - "Text", - "TYPE_CHECKING", ] -elif sys.version_info >= (3, 7): - __all__ = [ - "Any", - "Callable", - "ClassVar", - "ForwardRef", - "Generic", - "Optional", - "Tuple", - "Type", - "TypeVar", - "Union", - "AbstractSet", - "ByteString", - "Container", - "ContextManager", - "Hashable", - "ItemsView", - "Iterable", - "Iterator", - "KeysView", - "Mapping", - "MappingView", - "MutableMapping", - "MutableSequence", - "MutableSet", - "Sequence", - "Sized", - "ValuesView", - "Awaitable", - "AsyncIterator", - "AsyncIterable", - "Coroutine", - "Collection", - "AsyncGenerator", - "AsyncContextManager", - "Reversible", - "SupportsAbs", - "SupportsBytes", - "SupportsComplex", - "SupportsFloat", - "SupportsInt", - "SupportsRound", - "ChainMap", - "Counter", - "Deque", - "Dict", - "DefaultDict", - "List", - "OrderedDict", - "Set", - "FrozenSet", - "NamedTuple", - "Generator", - "AnyStr", - "cast", - "get_type_hints", - "NewType", - "no_type_check", - "no_type_check_decorator", - "NoReturn", - "overload", - "Text", - "TYPE_CHECKING", - ] -else: - __all__ = [ - "Any", - "Callable", - "ClassVar", - "Generic", - "Optional", - "Tuple", - "Type", - "TypeVar", - "Union", - "AbstractSet", - "GenericMeta", - "ByteString", - "Container", - "ContextManager", - "Hashable", - "ItemsView", - "Iterable", - "Iterator", - "KeysView", - "Mapping", - "MappingView", - "MutableMapping", - "MutableSequence", - "MutableSet", - "Sequence", - "Sized", - "ValuesView", - "Reversible", - "SupportsAbs", - "SupportsBytes", - "SupportsComplex", - "SupportsFloat", - "SupportsInt", - "SupportsRound", - "Counter", - "Deque", - "Dict", - "DefaultDict", - "List", - "Set", - "FrozenSet", - "NamedTuple", - "Generator", - "AnyStr", - "cast", - "get_type_hints", - "NewType", - "no_type_check", - "no_type_check_decorator", - "overload", - "Text", - "TYPE_CHECKING", + +if sys.version_info >= (3, 9): + __all__ += ["Annotated", "BinaryIO", "IO", "Match", "Pattern", "TextIO"] + +if sys.version_info >= (3, 10): + __all__ += ["Concatenate", "ParamSpec", "ParamSpecArgs", "ParamSpecKwargs", "TypeAlias", "TypeGuard", "is_typeddict"] + +if sys.version_info >= (3, 11): + __all__ += [ + "LiteralString", + "Never", + "NotRequired", + "Required", + "Self", + "TypeVarTuple", + "Unpack", + "assert_never", + "assert_type", + "clear_overloads", + "dataclass_transform", + "get_overloads", + "reveal_type", ] Any = object() From 3542b26a812517be47b6bb45df617d5028a3adf7 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Wed, 18 May 2022 20:56:58 +0200 Subject: [PATCH 2/5] Add a test case for star imports --- test_cases/stdlib/typing/all.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 test_cases/stdlib/typing/all.py diff --git a/test_cases/stdlib/typing/all.py b/test_cases/stdlib/typing/all.py new file mode 100644 index 000000000000..d81a2bdc5eb5 --- /dev/null +++ b/test_cases/stdlib/typing/all.py @@ -0,0 +1,9 @@ +""" +This tests that star imports work when using "all += " syntax. +""" + +import sys +from typing import * + +if sys.version_info >= (3, 9): + x: Annotated[int, 42] From aa5afb32efe3e37c16c4d51ec7e98e8ef41c35df Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Wed, 18 May 2022 21:00:43 +0200 Subject: [PATCH 3/5] Use all += in zipfile (+ test) --- stdlib/zipfile.pyi | 46 ++++++++++++--------------------- test_cases/stdlib/typing/all.py | 4 +++ 2 files changed, 20 insertions(+), 30 deletions(-) diff --git a/stdlib/zipfile.pyi b/stdlib/zipfile.pyi index 276f8df82a6d..3ceafd1d4a0e 100644 --- a/stdlib/zipfile.pyi +++ b/stdlib/zipfile.pyi @@ -7,37 +7,23 @@ from types import TracebackType from typing import IO, Any, Protocol, overload from typing_extensions import Literal, TypeAlias +__all__ = [ + "BadZipFile", + "BadZipfile", + "error", + "ZIP_STORED", + "ZIP_DEFLATED", + "ZIP_BZIP2", + "ZIP_LZMA", + "is_zipfile", + "ZipInfo", + "ZipFile", + "PyZipFile", + "LargeZipFile", +] + if sys.version_info >= (3, 8): - __all__ = [ - "BadZipFile", - "BadZipfile", - "error", - "ZIP_STORED", - "ZIP_DEFLATED", - "ZIP_BZIP2", - "ZIP_LZMA", - "is_zipfile", - "ZipInfo", - "ZipFile", - "PyZipFile", - "LargeZipFile", - "Path", - ] -else: - __all__ = [ - "BadZipFile", - "BadZipfile", - "error", - "ZIP_STORED", - "ZIP_DEFLATED", - "ZIP_BZIP2", - "ZIP_LZMA", - "is_zipfile", - "ZipInfo", - "ZipFile", - "PyZipFile", - "LargeZipFile", - ] + __all__ += ["Path"] _DateTuple: TypeAlias = tuple[int, int, int, int, int, int] _ReadWriteMode: TypeAlias = Literal["r", "w"] diff --git a/test_cases/stdlib/typing/all.py b/test_cases/stdlib/typing/all.py index d81a2bdc5eb5..624ab5e3ba27 100644 --- a/test_cases/stdlib/typing/all.py +++ b/test_cases/stdlib/typing/all.py @@ -4,6 +4,10 @@ import sys from typing import * +from zipfile import * if sys.version_info >= (3, 9): x: Annotated[int, 42] + +if sys.version_info >= (3, 8): + p: Path From 05c56a5b1277e398141841a5f715f37ed676cdc6 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Wed, 18 May 2022 21:05:45 +0200 Subject: [PATCH 4/5] Ignore some flake8 warning in test --- test_cases/stdlib/typing/all.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test_cases/stdlib/typing/all.py b/test_cases/stdlib/typing/all.py index 624ab5e3ba27..383567e85368 100644 --- a/test_cases/stdlib/typing/all.py +++ b/test_cases/stdlib/typing/all.py @@ -3,11 +3,11 @@ """ import sys -from typing import * -from zipfile import * +from typing import * # noqa: F403 +from zipfile import * # noqa: F403 if sys.version_info >= (3, 9): - x: Annotated[int, 42] + x: Annotated[int, 42] # noqa: F405 if sys.version_info >= (3, 8): - p: Path + p: Path # noqa: F405 From 2c5c2800b0c1d1cdb1a03a94a41ad9ede760b51b Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Wed, 18 May 2022 21:11:32 +0200 Subject: [PATCH 5/5] Disable a pyright warning in test --- test_cases/stdlib/typing/all.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test_cases/stdlib/typing/all.py b/test_cases/stdlib/typing/all.py index 383567e85368..3519912e1425 100644 --- a/test_cases/stdlib/typing/all.py +++ b/test_cases/stdlib/typing/all.py @@ -1,3 +1,5 @@ +# pyright: reportWildcardImportFromLibrary=false + """ This tests that star imports work when using "all += " syntax. """