Skip to content

Commit bf167d4

Browse files
authored
Add __all__ for asyncio.unix_events & asyncio.taskgroups, and simplify asyncio.__init__ (#7343)
1 parent b8421eb commit bf167d4

File tree

3 files changed

+47
-115
lines changed

3 files changed

+47
-115
lines changed

stdlib/asyncio/__init__.pyi

Lines changed: 19 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,31 @@
11
import sys
22

3-
from .base_events import BaseEventLoop as BaseEventLoop
4-
from .coroutines import iscoroutine as iscoroutine, iscoroutinefunction as iscoroutinefunction
5-
from .events import (
6-
AbstractEventLoop as AbstractEventLoop,
7-
AbstractEventLoopPolicy as AbstractEventLoopPolicy,
8-
AbstractServer as AbstractServer,
9-
Handle as Handle,
10-
TimerHandle as TimerHandle,
11-
_get_running_loop as _get_running_loop,
12-
_set_running_loop as _set_running_loop,
13-
get_child_watcher as get_child_watcher,
14-
get_event_loop as get_event_loop,
15-
get_event_loop_policy as get_event_loop_policy,
16-
new_event_loop as new_event_loop,
17-
set_child_watcher as set_child_watcher,
18-
set_event_loop as set_event_loop,
19-
set_event_loop_policy as set_event_loop_policy,
20-
)
21-
from .futures import Future as Future, isfuture as isfuture, wrap_future as wrap_future
22-
from .locks import (
23-
BoundedSemaphore as BoundedSemaphore,
24-
Condition as Condition,
25-
Event as Event,
26-
Lock as Lock,
27-
Semaphore as Semaphore,
28-
)
29-
from .protocols import (
30-
BaseProtocol as BaseProtocol,
31-
DatagramProtocol as DatagramProtocol,
32-
Protocol as Protocol,
33-
SubprocessProtocol as SubprocessProtocol,
34-
)
35-
from .queues import (
36-
LifoQueue as LifoQueue,
37-
PriorityQueue as PriorityQueue,
38-
Queue as Queue,
39-
QueueEmpty as QueueEmpty,
40-
QueueFull as QueueFull,
41-
)
42-
from .streams import (
43-
StreamReader as StreamReader,
44-
StreamReaderProtocol as StreamReaderProtocol,
45-
StreamWriter as StreamWriter,
46-
open_connection as open_connection,
47-
start_server as start_server,
48-
)
49-
from .subprocess import create_subprocess_exec as create_subprocess_exec, create_subprocess_shell as create_subprocess_shell
50-
from .tasks import (
51-
ALL_COMPLETED as ALL_COMPLETED,
52-
FIRST_COMPLETED as FIRST_COMPLETED,
53-
FIRST_EXCEPTION as FIRST_EXCEPTION,
54-
Task as Task,
55-
as_completed as as_completed,
56-
ensure_future as ensure_future,
57-
gather as gather,
58-
run_coroutine_threadsafe as run_coroutine_threadsafe,
59-
shield as shield,
60-
sleep as sleep,
61-
wait as wait,
62-
wait_for as wait_for,
63-
)
64-
from .transports import (
65-
BaseTransport as BaseTransport,
66-
DatagramTransport as DatagramTransport,
67-
ReadTransport as ReadTransport,
68-
SubprocessTransport as SubprocessTransport,
69-
Transport as Transport,
70-
WriteTransport as WriteTransport,
71-
)
3+
# As at runtime, this depends on all submodules defining __all__ accurately.
4+
from .base_events import *
5+
from .coroutines import *
6+
from .events import *
7+
from .futures import *
8+
from .locks import *
9+
from .protocols import *
10+
from .queues import *
11+
from .streams import *
12+
from .subprocess import *
13+
from .tasks import *
14+
from .transports import *
7215

73-
if sys.version_info < (3, 11):
74-
from .coroutines import coroutine as coroutine
75-
76-
if sys.version_info >= (3, 9):
77-
from .threads import to_thread as to_thread
78-
79-
if sys.version_info >= (3, 8):
80-
from .exceptions import (
81-
CancelledError as CancelledError,
82-
IncompleteReadError as IncompleteReadError,
83-
InvalidStateError as InvalidStateError,
84-
LimitOverrunError as LimitOverrunError,
85-
TimeoutError as TimeoutError,
86-
)
87-
else:
88-
from .futures import CancelledError as CancelledError, InvalidStateError as InvalidStateError, TimeoutError as TimeoutError
89-
from .streams import IncompleteReadError as IncompleteReadError, LimitOverrunError as LimitOverrunError
16+
if sys.version_info >= (3, 7):
17+
from .runners import *
9018

9119
if sys.version_info >= (3, 8):
92-
from .exceptions import SendfileNotAvailableError as SendfileNotAvailableError
93-
elif sys.version_info >= (3, 7):
94-
from .events import SendfileNotAvailableError as SendfileNotAvailableError
20+
from .exceptions import *
9521

96-
if sys.version_info >= (3, 7):
97-
from .events import get_running_loop as get_running_loop
98-
from .protocols import BufferedProtocol as BufferedProtocol
99-
from .runners import run as run
100-
from .tasks import (
101-
_enter_task as _enter_task,
102-
_leave_task as _leave_task,
103-
_register_task as _register_task,
104-
_unregister_task as _unregister_task,
105-
all_tasks as all_tasks,
106-
create_task as create_task,
107-
current_task as current_task,
108-
)
22+
if sys.version_info >= (3, 9):
23+
from .threads import *
10924

11025
if sys.version_info >= (3, 11):
111-
from .taskgroups import TaskGroup as TaskGroup
112-
113-
DefaultEventLoopPolicy: type[AbstractEventLoopPolicy]
26+
from .taskgroups import *
11427

11528
if sys.platform == "win32":
11629
from .windows_events import *
11730
else:
118-
from .streams import open_unix_connection as open_unix_connection, start_unix_server as start_unix_server
119-
from .unix_events import (
120-
AbstractChildWatcher as AbstractChildWatcher,
121-
FastChildWatcher as FastChildWatcher,
122-
SafeChildWatcher as SafeChildWatcher,
123-
SelectorEventLoop as SelectorEventLoop,
124-
)
125-
126-
if sys.version_info >= (3, 8):
127-
from .unix_events import MultiLoopChildWatcher as MultiLoopChildWatcher, ThreadedChildWatcher as ThreadedChildWatcher
31+
from .unix_events import *

stdlib/asyncio/taskgroups.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ from typing import Any, Coroutine, Generator, TypeVar
66

77
from .tasks import Task
88

9+
__all__ = ["TaskGroup"]
10+
911
_T = TypeVar("_T")
1012

1113
class TaskGroup:

stdlib/asyncio/unix_events.pyi

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,32 @@ class AbstractChildWatcher:
2222
def is_active(self) -> bool: ...
2323

2424
if sys.platform != "win32":
25+
if sys.version_info >= (3, 9):
26+
__all__ = (
27+
"SelectorEventLoop",
28+
"AbstractChildWatcher",
29+
"SafeChildWatcher",
30+
"FastChildWatcher",
31+
"PidfdChildWatcher",
32+
"MultiLoopChildWatcher",
33+
"ThreadedChildWatcher",
34+
"DefaultEventLoopPolicy",
35+
)
36+
elif sys.version_info >= (3, 8):
37+
__all__ = (
38+
"SelectorEventLoop",
39+
"AbstractChildWatcher",
40+
"SafeChildWatcher",
41+
"FastChildWatcher",
42+
"MultiLoopChildWatcher",
43+
"ThreadedChildWatcher",
44+
"DefaultEventLoopPolicy",
45+
)
46+
elif sys.version_info >= (3, 7):
47+
__all__ = ("SelectorEventLoop", "AbstractChildWatcher", "SafeChildWatcher", "FastChildWatcher", "DefaultEventLoopPolicy")
48+
else:
49+
__all__ = ["SelectorEventLoop", "AbstractChildWatcher", "SafeChildWatcher", "FastChildWatcher", "DefaultEventLoopPolicy"]
50+
2551
class BaseChildWatcher(AbstractChildWatcher):
2652
def __init__(self) -> None: ...
2753

0 commit comments

Comments
 (0)