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

Update stubtest for async and dunder pos only checking #7333

Merged
merged 6 commits into from
Feb 21, 2022
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
2 changes: 1 addition & 1 deletion .github/workflows/stubtest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
# - get_mypy_req in tests/stubtest_third_party.py
# - stubtest-stdlib in .github/workflows/stubtest.yml
# - stubtest-stdlib in .github/workflows/tests.yml
run: pip install $(grep tomli== requirements-tests.txt) git+git://github.com/python/mypy@080bb0e04e9d5c4d2513621d1fb62f1d61a573e9
run: pip install $(grep tomli== requirements-tests.txt) git+git://github.com/python/mypy@85fc99c99e7e2afc5896de1842d52e6e6cd55197
- name: Run stubtest
run: python tests/stubtest_stdlib.py

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ jobs:
# - get_mypy_req in tests/stubtest_third_party.py
# - stubtest-stdlib in .github/workflows/stubtest.yml
# - stubtest-stdlib in .github/workflows/tests.yml
run: pip install $(grep tomli== requirements-tests.txt) git+git://github.com/python/mypy@080bb0e04e9d5c4d2513621d1fb62f1d61a573e9
run: pip install $(grep tomli== requirements-tests.txt) git+git://github.com/python/mypy@85fc99c99e7e2afc5896de1842d52e6e6cd55197
- name: Run stubtest
run: python tests/stubtest_stdlib.py

Expand Down
6 changes: 3 additions & 3 deletions stdlib/types.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,15 @@ class AsyncGeneratorType(AsyncGenerator[_T_co, _T_contra]):
__name__: str
__qualname__: str
def __aiter__(self) -> AsyncGeneratorType[_T_co, _T_contra]: ...
async def __anext__(self) -> _T_co: ...
async def asend(self, __val: _T_contra) -> _T_co: ...
def __anext__(self) -> Coroutine[Any, Any, _T_co]: ...
Copy link
Member

Choose a reason for hiding this comment

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

Out of curiosity, what is the reason for these changes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Well,

>>> inspect.iscoroutinefunction(types.AsyncGeneratorType.aclose)
False

I'm not sure if this matters at all, cc @AlexWaygood who added this to stubtest.

Copy link
Member

Choose a reason for hiding this comment

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

cc. @AlexWaygood who made them async only a few weeks ago as well...

Copy link
Member

Choose a reason for hiding this comment

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

"Classes" in the types module are weird, I'm happy to go with whatever stubtest thinks best personally.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

(the other big change we've made recently is switching a lot of (...) -> Awaitable into async (...) -> which actually does make a difference to type checking)

Copy link
Member

Choose a reason for hiding this comment

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

Interestingly, it looks like there are already at least 2 open BPO issues about the fact that inspect.iscoroutinefunction returns False for types.AsyncGeneratorType.__anext__, .asend and .aclose. https://bugs.python.org/issue42760.

I'm not really sure what we should make of that, but it's interesting!

def asend(self, __val: _T_contra) -> Coroutine[Any, Any, _T_co]: ...
@overload
async def athrow(
self, __typ: type[BaseException], __val: BaseException | object = ..., __tb: TracebackType | None = ...
) -> _T_co: ...
@overload
async def athrow(self, __typ: BaseException, __val: None = ..., __tb: TracebackType | None = ...) -> _T_co: ...
async def aclose(self) -> None: ...
def aclose(self) -> Coroutine[Any, Any, None]: ...
if sys.version_info >= (3, 9):
def __class_getitem__(cls, __item: Any) -> GenericAlias: ...

Expand Down
13 changes: 12 additions & 1 deletion tests/stubtest_allowlists/darwin-py36.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,16 @@ ntpath.splitunc
posix.stat_float_times
ssl.OP_ENABLE_MIDDLEBOX_COMPAT
ssl.Options.OP_ENABLE_MIDDLEBOX_COMPAT

uuid.lib

# Not "async defs" at runtime
asyncio.SelectorEventLoop.create_unix_connection
asyncio.SelectorEventLoop.create_unix_server
asyncio.open_unix_connection
asyncio.start_unix_server
asyncio.streams.open_unix_connection
asyncio.streams.start_unix_server
asyncio.unix_events.SelectorEventLoop.create_unix_connection
asyncio.unix_events.SelectorEventLoop.create_unix_server
asyncio.unix_events._UnixSelectorEventLoop.create_unix_connection
asyncio.unix_events._UnixSelectorEventLoop.create_unix_server
12 changes: 12 additions & 0 deletions tests/stubtest_allowlists/linux-py36.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,15 @@ posix.stat_float_times
ssl.OP_ENABLE_MIDDLEBOX_COMPAT
ssl.Options.OP_ENABLE_MIDDLEBOX_COMPAT
uuid.lib

# Not "async defs" at runtime
asyncio.SelectorEventLoop.create_unix_connection
asyncio.SelectorEventLoop.create_unix_server
asyncio.open_unix_connection
asyncio.start_unix_server
asyncio.streams.open_unix_connection
asyncio.streams.start_unix_server
asyncio.unix_events.SelectorEventLoop.create_unix_connection
asyncio.unix_events.SelectorEventLoop.create_unix_server
asyncio.unix_events._UnixSelectorEventLoop.create_unix_connection
asyncio.unix_events._UnixSelectorEventLoop.create_unix_server
87 changes: 87 additions & 0 deletions tests/stubtest_allowlists/py36.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,93 @@ collections.Generator.gi_yieldfrom
collections.Mapping.get # Adding None to the Union messed up mypy
collections.Sequence.index # Supporting None in end is not mandatory

# Not "async def"s at runtime
asyncio.AbstractEventLoop.connect_read_pipe
asyncio.AbstractEventLoop.connect_write_pipe
asyncio.AbstractEventLoop.create_datagram_endpoint
asyncio.AbstractEventLoop.create_unix_connection
asyncio.AbstractEventLoop.create_unix_server
asyncio.AbstractEventLoop.getaddrinfo
asyncio.AbstractEventLoop.getnameinfo
asyncio.AbstractEventLoop.shutdown_asyncgens
asyncio.AbstractEventLoop.subprocess_exec
asyncio.AbstractEventLoop.subprocess_shell
asyncio.AbstractServer.wait_closed
asyncio.BaseEventLoop.connect_accepted_socket
asyncio.BaseEventLoop.connect_read_pipe
asyncio.BaseEventLoop.connect_write_pipe
asyncio.BaseEventLoop.create_datagram_endpoint
asyncio.BaseEventLoop.getaddrinfo
asyncio.BaseEventLoop.getnameinfo
asyncio.BaseEventLoop.shutdown_asyncgens
asyncio.BaseEventLoop.subprocess_shell
asyncio.Condition.wait
asyncio.Condition.wait_for
asyncio.Event.wait
asyncio.Lock.acquire
asyncio.Queue.get
asyncio.Queue.join
asyncio.Queue.put
asyncio.Semaphore.acquire
asyncio.StreamReader.__anext__
asyncio.StreamReader.read
asyncio.StreamReader.readexactly
asyncio.StreamReader.readline
asyncio.StreamReader.readuntil
asyncio.StreamWriter.drain
asyncio.create_subprocess_exec
asyncio.create_subprocess_shell
asyncio.open_connection
asyncio.sleep
asyncio.start_server
asyncio.wait_for
asyncio.base_events.BaseEventLoop.connect_accepted_socket
asyncio.base_events.BaseEventLoop.connect_read_pipe
asyncio.base_events.BaseEventLoop.connect_write_pipe
asyncio.base_events.BaseEventLoop.create_datagram_endpoint
asyncio.base_events.BaseEventLoop.getaddrinfo
asyncio.base_events.BaseEventLoop.getnameinfo
asyncio.base_events.BaseEventLoop.shutdown_asyncgens
asyncio.base_events.BaseEventLoop.subprocess_shell
asyncio.base_events.Server.wait_closed
asyncio.base_subprocess.BaseSubprocessTransport._connect_pipes
asyncio.base_subprocess.BaseSubprocessTransport._wait
asyncio.events.AbstractEventLoop.connect_read_pipe
asyncio.events.AbstractEventLoop.connect_write_pipe
asyncio.events.AbstractEventLoop.create_datagram_endpoint
asyncio.events.AbstractEventLoop.create_unix_connection
asyncio.events.AbstractEventLoop.create_unix_server
asyncio.events.AbstractEventLoop.getaddrinfo
asyncio.events.AbstractEventLoop.getnameinfo
asyncio.events.AbstractEventLoop.shutdown_asyncgens
asyncio.events.AbstractEventLoop.subprocess_exec
asyncio.events.AbstractEventLoop.subprocess_shell
asyncio.events.AbstractServer.wait_closed
asyncio.locks.Condition.wait
asyncio.locks.Condition.wait_for
asyncio.locks.Event.wait
asyncio.locks.Lock.acquire
asyncio.locks.Semaphore.acquire
asyncio.locks._ContextManagerMixin.__aenter__
asyncio.locks._ContextManagerMixin.__aexit__
asyncio.queues.Queue.get
asyncio.queues.Queue.join
asyncio.queues.Queue.put
asyncio.streams.StreamReader.__anext__
asyncio.streams.StreamReader.read
asyncio.streams.StreamReader.readexactly
asyncio.streams.StreamReader.readline
asyncio.streams.StreamReader.readuntil
asyncio.streams.StreamWriter.drain
asyncio.streams.open_connection
asyncio.streams.start_server
asyncio.subprocess.Process.communicate
asyncio.subprocess.Process.wait
asyncio.subprocess.create_subprocess_exec
asyncio.subprocess.create_subprocess_shell
asyncio.tasks.sleep
asyncio.tasks.wait_for

# Exists at runtime, but missing from stubs
_bisect.bisect
_bisect.insort
Expand Down
2 changes: 2 additions & 0 deletions tests/stubtest_allowlists/py37.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ _collections_abc.AsyncGenerator.ag_code
_collections_abc.AsyncGenerator.ag_frame
_collections_abc.AsyncGenerator.ag_running
_dummy_threading
asyncio.AbstractEventLoop.run_in_executor # allowed to return a Future, changed in 3.8
asyncio.events.AbstractEventLoop.run_in_executor
asyncio.Future.__init__ # Usually initialized from c object
asyncio.Future._callbacks # Usually initialized from c object
asyncio.futures.Future.__init__ # Usually initialized from c object
Expand Down
8 changes: 8 additions & 0 deletions tests/stubtest_allowlists/win32-py36.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,11 @@ os.startfile
# Exists at runtime, but missing from stubs
asyncio.windows_utils.socketpair
venv.EnvBuilder.include_binary

# Not "async defs" at runtime
asyncio.IocpProactor.connect_pipe
asyncio.ProactorEventLoop.create_pipe_connection
asyncio.ProactorEventLoop.start_serving_pipe
asyncio.windows_events.IocpProactor.connect_pipe
asyncio.windows_events.ProactorEventLoop.create_pipe_connection
asyncio.windows_events.ProactorEventLoop.start_serving_pipe
2 changes: 1 addition & 1 deletion tests/stubtest_third_party.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def get_mypy_req():
# - get_mypy_req in tests/stubtest_third_party.py
# - stubtest-stdlib in .github/workflows/stubtest.yml
# - stubtest-stdlib in .github/workflows/tests.yml
return "git+git://github.com/python/mypy@080bb0e04e9d5c4d2513621d1fb62f1d61a573e9"
return "git+git://github.com/python/mypy@85fc99c99e7e2afc5896de1842d52e6e6cd55197"

with open("requirements-tests.txt") as f:
return next(line.strip() for line in f if "mypy" in line)
Expand Down