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 all 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
56 changes: 56 additions & 0 deletions stdlib/3/_collections_abc.pyi
Original file line number Diff line number Diff line change
@@ -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",
]
41 changes: 3 additions & 38 deletions stdlib/3/collections/__init__.pyi
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
29 changes: 2 additions & 27 deletions stdlib/3/collections/abc.pyi
Original file line number Diff line number Diff line change
@@ -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__
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 # Added in Python 3.8
asyncio.format_helpers # Added in Python 3.7
Expand All @@ -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__
Expand Down
5 changes: 5 additions & 0 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
asyncio.AbstractEventLoop.sock_sendfile
asyncio.compat # Removed in 3.7
asyncio.Future.__init__
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions tests/stubtest_whitelists/py38.txt
Original file line number Diff line number Diff line change
@@ -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__
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions tests/stubtest_whitelists/py39.txt
Original file line number Diff line number Diff line change
@@ -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__
Expand Down
24 changes: 24 additions & 0 deletions tests/stubtest_whitelists/py3_common.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down