Add _collections_abc module (#4000)

* Add _collections_abc module
* Rearrange collections.abc and collections to re-export from _collections_abc

Co-authored-by: Sebastian Rittau <srittau@rittau.biz>
This commit is contained in:
Rune Tynan
2021-01-23 10:17:57 -05:00
committed by GitHub
parent b85f46eb07
commit 6aa5cc691c
8 changed files with 118 additions and 69 deletions

View File

@@ -0,0 +1,56 @@
from typing import (
AbstractSet as Set,
AsyncGenerator as AsyncGenerator,
AsyncIterable as AsyncIterable,
AsyncIterator as AsyncIterator,
Awaitable as Awaitable,
ByteString as ByteString,
Callable as Callable,
Collection as Collection,
Container as Container,
Coroutine as Coroutine,
Generator as Generator,
Hashable as Hashable,
ItemsView as ItemsView,
Iterable as Iterable,
Iterator as Iterator,
KeysView as KeysView,
Mapping as Mapping,
MappingView as MappingView,
MutableMapping as MutableMapping,
MutableSequence as MutableSequence,
MutableSet as MutableSet,
Reversible as Reversible,
Sequence as Sequence,
Sized as Sized,
ValuesView as ValuesView,
)
# Without the real definition, mypy and pytest both think that __all__ is empty, so re-exports nothing
__all__ = [
"Awaitable",
"Coroutine",
"AsyncIterable",
"AsyncIterator",
"AsyncGenerator",
"Hashable",
"Iterable",
"Iterator",
"Generator",
"Reversible",
"Sized",
"Container",
"Callable",
"Collection",
"Set",
"MutableSet",
"Mapping",
"MutableMapping",
"MappingView",
"KeysView",
"ItemsView",
"ValuesView",
"Sequence",
"MutableSequence",
"ByteString",
]

View File

@@ -1,44 +1,9 @@
import sys
import typing
from typing import (
AbstractSet,
Any,
AsyncGenerator as AsyncGenerator,
AsyncIterable as AsyncIterable,
AsyncIterator as AsyncIterator,
Awaitable as Awaitable,
ByteString as ByteString,
Callable as Callable,
Collection as Collection,
Container as Container,
Coroutine as Coroutine,
Dict,
Generator as Generator,
Generic,
Hashable as Hashable,
ItemsView as ItemsView,
Iterable as Iterable,
Iterator as Iterator,
KeysView as KeysView,
List,
Mapping as Mapping,
MappingView as MappingView,
MutableMapping as MutableMapping,
MutableSequence as MutableSequence,
MutableSet as MutableSet,
Optional,
Reversible as Reversible,
Sequence as Sequence,
Sized as Sized,
Tuple,
Type,
TypeVar,
Union,
ValuesView as ValuesView,
overload,
)
from typing import Any, Dict, Generic, List, Optional, Tuple, Type, TypeVar, Union, overload
Set = AbstractSet
if sys.version_info < (3, 10):
from _collections_abc import *
_S = TypeVar("_S")
_T = TypeVar("_T")

View File

@@ -1,27 +1,2 @@
from . import (
AsyncGenerator as AsyncGenerator,
AsyncIterable as AsyncIterable,
AsyncIterator as AsyncIterator,
Awaitable as Awaitable,
ByteString as ByteString,
Callable as Callable,
Collection as Collection,
Container as Container,
Coroutine as Coroutine,
Generator as Generator,
Hashable as Hashable,
ItemsView as ItemsView,
Iterable as Iterable,
Iterator as Iterator,
KeysView as KeysView,
Mapping as Mapping,
MappingView as MappingView,
MutableMapping as MutableMapping,
MutableSequence as MutableSequence,
MutableSet as MutableSet,
Reversible as Reversible,
Sequence as Sequence,
Set as Set,
Sized as Sized,
ValuesView as ValuesView,
)
from _collections_abc import *
from _collections_abc import __all__ as __all__

View File

@@ -1,3 +1,7 @@
_collections_abc.AsyncGenerator.ag_await
_collections_abc.AsyncGenerator.ag_code
_collections_abc.AsyncGenerator.ag_frame
_collections_abc.AsyncGenerator.ag_running
asyncio.Future.__init__
asyncio.exceptions # Added in Python 3.8
asyncio.format_helpers # Added in Python 3.7
@@ -15,10 +19,6 @@ collections.AsyncGenerator.ag_code
collections.AsyncGenerator.ag_frame
collections.AsyncGenerator.ag_running
collections.UserString.maketrans
collections.abc.AsyncGenerator.ag_await
collections.abc.AsyncGenerator.ag_code
collections.abc.AsyncGenerator.ag_frame
collections.abc.AsyncGenerator.ag_running
contextlib._GeneratorContextManager.__init__
copy.PyStringMap
ctypes.CDLL.__init__

View File

@@ -1,3 +1,7 @@
_collections_abc.AsyncGenerator.ag_await
_collections_abc.AsyncGenerator.ag_code
_collections_abc.AsyncGenerator.ag_frame
_collections_abc.AsyncGenerator.ag_running
asyncio.AbstractEventLoop.sock_sendfile
asyncio.compat # Removed in 3.7
asyncio.Future.__init__
@@ -21,6 +25,7 @@ collections.abc.AsyncGenerator.ag_await
collections.abc.AsyncGenerator.ag_code
collections.abc.AsyncGenerator.ag_frame
collections.abc.AsyncGenerator.ag_running
concurrent.futures.ProcessPoolExecutor.map
contextvars.Context.__init__
contextvars.Context.get
contextvars.ContextVar.get

View File

@@ -1,3 +1,12 @@
_collections_abc.AsyncGenerator.ag_await
_collections_abc.AsyncGenerator.ag_code
_collections_abc.AsyncGenerator.ag_frame
_collections_abc.AsyncGenerator.ag_running
_collections_abc.ItemsView.__reversed__
_collections_abc.KeysView.__reversed__
_collections_abc.ValuesView.__reversed__
_thread.ExceptHookArgs
_thread._ExceptHookArgs
ast.Bytes.__new__
ast.Ellipsis.__new__
ast.NameConstant.__new__
@@ -29,6 +38,7 @@ collections.abc.AsyncGenerator.ag_running
collections.abc.ItemsView.__reversed__
collections.abc.KeysView.__reversed__
collections.abc.ValuesView.__reversed__
concurrent.futures.ProcessPoolExecutor.map
contextvars.Context.__init__
contextvars.Context.get
copy.PyStringMap

View File

@@ -1,4 +1,18 @@
_ast.ImportFrom.level
_collections_abc.AsyncGenerator.ag_await
_collections_abc.AsyncGenerator.ag_code
_collections_abc.AsyncGenerator.ag_frame
_collections_abc.AsyncGenerator.ag_running
_collections_abc.AsyncGenerator.asend
_collections_abc.AsyncGenerator.athrow
_collections_abc.Container.__contains__
_collections_abc.Coroutine.send
_collections_abc.Coroutine.throw
_collections_abc.Generator.send
_collections_abc.Generator.throw
_collections_abc.ItemsView.__reversed__
_collections_abc.KeysView.__reversed__
_collections_abc.ValuesView.__reversed__
_dummy_thread
ast.Bytes.__new__
ast.Ellipsis.__new__

View File

@@ -1,4 +1,26 @@
__future__._Feature.__init__
_collections_abc.Callable
_collections_abc.Coroutine.cr_await
_collections_abc.Coroutine.cr_code
_collections_abc.Coroutine.cr_frame
_collections_abc.Coroutine.cr_running
_collections_abc.Generator.gi_code
_collections_abc.Generator.gi_frame
_collections_abc.Generator.gi_running
_collections_abc.Generator.gi_yieldfrom
_collections_abc.Mapping.get
_collections_abc.MutableMapping.pop
_collections_abc.MutableMapping.setdefault
_collections_abc.MutableSequence.append
_collections_abc.MutableSequence.extend
_collections_abc.MutableSequence.insert
_collections_abc.MutableSequence.remove
_collections_abc.MutableSet.add
_collections_abc.MutableSet.discard
_collections_abc.MutableSet.remove
_collections_abc.Sequence.count
_collections_abc.Sequence.index
_collections_abc.Set.isdisjoint
_csv.Dialect.__init__
_dummy_threading
_importlib_modulespec
@@ -84,6 +106,7 @@ collections.Generator.gi_running
collections.Generator.gi_yieldfrom
collections.Mapping.get
collections.Sequence.index
collections.Set.isdisjoint
collections.abc.Callable
collections.abc.Coroutine.cr_await
collections.abc.Coroutine.cr_code
@@ -431,6 +454,7 @@ builtins.quit
# Builtins that mypy pretends exist
builtins.reveal_locals
builtins.reveal_type
collections.abc.* # Types are re-exported from _collections_abc, so errors should be fixed there
# Various classes in typing aren't types at runtime. In addition, mypy thinks some special forms are tautologically defined.
typing.[A-Z]\w+
# We can't distinguish not having a default value from having a default value of inspect.Parameter.empty