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 _collections_abc module #4000

Merged
merged 22 commits into from
Jan 23, 2021
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5db8e8b
Add _collections_abc module
CraftSpider May 16, 2020
c759b7c
Rearrange collections.abc and collections to re-export from _collecti…
CraftSpider May 16, 2020
ce3fc75
Expand stubtest whitelists
CraftSpider May 16, 2020
96c99df
Fix __all__ location
CraftSpider May 16, 2020
d2b048e
Remove collections.abc methods, stubtest no longer tests them
CraftSpider May 16, 2020
01cec54
Remove final remaining unused whitelists
CraftSpider May 16, 2020
9a9ff71
Fix Set name, change import to import all
CraftSpider May 16, 2020
02571c8
Merge branch 'master' into collections-stubs
CraftSpider May 27, 2020
1f66d92
Merge remote-tracking branch 'origin/collections-stubs' into collecti…
CraftSpider May 27, 2020
e4a9488
Fix collections.abc ignores broken by merge
CraftSpider May 27, 2020
1f1038b
Fix mypy and pytype errors by including __all__. See #3923
CraftSpider May 27, 2020
5a7247e
Add stubtest whitelist for collections.abc
CraftSpider May 27, 2020
7163690
Add Set ignores
CraftSpider May 27, 2020
5fdd689
Merge branch 'master' into collections-stubs
srittau May 28, 2020
3a8992b
Update stubtest
srittau May 28, 2020
718e1a4
Remove unused stubtest whitelist entries
srittau May 28, 2020
2aa29fc
Merge branch 'master' into collections-stubs
srittau Jan 23, 2021
3c5f1d8
Remove Python 3.5 compatibility
srittau Jan 23, 2021
8a5d9f8
Remove alias already imported from _collections_abc
srittau Jan 23, 2021
b22ad9b
Add one file to the stubtest whitelist
srittau Jan 23, 2021
b5a07b6
Add more methods to stubgen whitelist
srittau Jan 23, 2021
c83cf0f
Add more methods to stubgen whitelist
srittau Jan 23, 2021
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
63 changes: 63 additions & 0 deletions stdlib/3/_collections_abc.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@

import sys

from typing import (
AsyncIterable as AsyncIterable,
AsyncIterator as AsyncIterator,
Awaitable as Awaitable,
ByteString as ByteString,
Container as Container,
Coroutine as Coroutine,
Generator as Generator,
Hashable as Hashable,
Iterable as Iterable,
Iterator as Iterator,
Sized as Sized,
Callable as Callable,
Mapping as Mapping,
MutableMapping as MutableMapping,
Sequence as Sequence,
MutableSequence as MutableSequence,
AbstractSet as Set,
MutableSet as MutableSet,
MappingView as MappingView,
ItemsView as ItemsView,
KeysView as KeysView,
ValuesView as ValuesView,
)

if sys.version_info >= (3, 6):
from typing import (
Collection as Collection,
Reversible as Reversible,
AsyncGenerator as AsyncGenerator,
)

# 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",
]
35 changes: 2 additions & 33 deletions stdlib/3/collections/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,43 +1,12 @@
# These are not exported.
import sys
import typing
from typing import (
TypeVar, Generic, Dict, overload, List, Tuple,
Any, Type, Optional, Union
)
# These are exported.
from . import abc

from typing import (
AsyncIterable as AsyncIterable,
AsyncIterator as AsyncIterator,
Awaitable as Awaitable,
Callable as Callable,
Container as Container,
Coroutine as Coroutine,
Hashable as Hashable,
Iterable as Iterable,
Iterator as Iterator,
Sized as Sized,
Generator as Generator,
ByteString as ByteString,
Reversible as Reversible,
Mapping as Mapping,
MappingView as MappingView,
ItemsView as ItemsView,
KeysView as KeysView,
ValuesView as ValuesView,
MutableMapping as MutableMapping,
Sequence as Sequence,
MutableSequence as MutableSequence,
MutableSet as MutableSet,
AbstractSet as Set,
)
if sys.version_info >= (3, 6):
from typing import (
Collection as Collection,
AsyncGenerator as AsyncGenerator,
)
if sys.version_info < (3, 10):
from _collections_abc import *

_S = TypeVar('_S')
_T = TypeVar('_T')
Expand Down
37 changes: 2 additions & 35 deletions stdlib/3/collections/abc.pyi
Original file line number Diff line number Diff line change
@@ -1,36 +1,3 @@
# Stubs for collections.abc (introduced from Python 3.3)
#
# https://docs.python.org/3.3/whatsnew/3.3.html#collections
import sys

from . import (
AsyncIterable as AsyncIterable,
AsyncIterator as AsyncIterator,
Awaitable as Awaitable,
ByteString as ByteString,
Container as Container,
Coroutine as Coroutine,
Generator as Generator,
Hashable as Hashable,
Iterable as Iterable,
Iterator as Iterator,
Sized as Sized,
Callable as Callable,
Mapping as Mapping,
MutableMapping as MutableMapping,
Sequence as Sequence,
MutableSequence as MutableSequence,
Set as Set,
MutableSet as MutableSet,
MappingView as MappingView,
ItemsView as ItemsView,
KeysView as KeysView,
ValuesView as ValuesView,
)

if sys.version_info >= (3, 6):
from . import (
Collection as Collection,
Reversible as Reversible,
AsyncGenerator as AsyncGenerator,
)
from _collections_abc import *
from _collections_abc import __all__ as __all__
1 change: 0 additions & 1 deletion tests/stubtest_whitelists/py35.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ bdb.GENERATOR_AND_COROUTINE_FLAGS
builtins.str.maketrans
cmath.log
codecs.StreamRecoder.seek
collections.Reversible
collections.UserString.maketrans
ctypes.CDLL.__init__
decimal.Decimal.as_integer_ratio
Expand Down
8 changes: 4 additions & 4 deletions tests/stubtest_whitelists/py36.txt
Original file line number Diff line number Diff line change
@@ -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
asyncio.futures.Future.__init__
Expand All @@ -12,10 +16,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
copy.PyStringMap
ctypes.CDLL.__init__
email.message.MIMEPart.as_string
Expand Down
8 changes: 4 additions & 4 deletions tests/stubtest_whitelists/py37.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
_collections_abc.AsyncGenerator.ag_await
_collections_abc.AsyncGenerator.ag_code
_collections_abc.AsyncGenerator.ag_frame
_collections_abc.AsyncGenerator.ag_running
_tracemalloc._get_object_traceback
_tracemalloc.start
asyncio.AbstractEventLoop.sock_sendfile
Expand All @@ -20,10 +24,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
concurrent.futures.ProcessPoolExecutor.map
contextvars.Context.__init__
contextvars.Context.get
Expand Down
16 changes: 8 additions & 8 deletions tests/stubtest_whitelists/py38.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
_collections_abc.AsyncGenerator.ag_await
_collections_abc.AsyncGenerator.ag_code
_collections_abc.AsyncGenerator.ag_frame
_collections_abc.AsyncGenerator.ag_running
_collections_abc.Container.__contains__
_collections_abc.ItemsView.__reversed__
_collections_abc.KeysView.__reversed__
_collections_abc.ValuesView.__reversed__
_thread.ExceptHookArgs
_thread._ExceptHookArgs
_tracemalloc._get_object_traceback
Expand Down Expand Up @@ -39,14 +47,6 @@ collections.KeysView.__reversed__
collections.OrderedDict.fromkeys
collections.OrderedDict.setdefault
collections.ValuesView.__reversed__
collections.abc.AsyncGenerator.ag_await
collections.abc.AsyncGenerator.ag_code
collections.abc.AsyncGenerator.ag_frame
collections.abc.AsyncGenerator.ag_running
collections.abc.Container.__contains__
collections.abc.ItemsView.__reversed__
collections.abc.KeysView.__reversed__
collections.abc.ValuesView.__reversed__
concurrent.futures.Executor.submit
concurrent.futures.ProcessPoolExecutor.map
concurrent.futures.ProcessPoolExecutor.submit
Expand Down
45 changes: 23 additions & 22 deletions tests/stubtest_whitelists/py3_common.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
_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
Expand Down Expand Up @@ -100,28 +122,6 @@ collections.MutableSet.remove
collections.Sequence.count
collections.Sequence.index
collections.Set.isdisjoint
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
collections.deque.__hash__
concurrent.futures.Executor.map
concurrent.futures._base.Executor.map
Expand Down Expand Up @@ -534,6 +534,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
Expand Down