Skip to content

Commit 0b68e15

Browse files
committed
Replace async def with @coroutine
1 parent 81b3647 commit 0b68e15

File tree

2 files changed

+106
-74
lines changed

2 files changed

+106
-74
lines changed

stdlib/3/asyncio/base_events.pyi

+51-36
Original file line numberDiff line numberDiff line change
@@ -61,41 +61,51 @@ class BaseEventLoop(AbstractEventLoop):
6161
@coroutine
6262
def getnameinfo(self, sockaddr: tuple, flags: int = ...) -> Generator[Any, None, Tuple[str, int]]: ...
6363
if sys.version_info >= (3, 7):
64-
async def sock_sendfile(self, sock: socket, file: IO[bytes], offset: int = ..., count: Optional[int] = ..., *,
65-
fallback: bool = ...) -> int: ...
64+
@coroutine
65+
def sock_sendfile(self, sock: socket, file: IO[bytes], offset: int = ..., count: Optional[int] = ..., *,
66+
fallback: bool = ...) -> Generator[Any, None, int]: ...
6667
@overload
67-
async def create_connection(self, protocol_factory: _ProtocolFactory, host: str = ..., port: int = ..., *,
68-
ssl: _SSLContext = ..., family: int = ..., proto: int = ..., flags: int = ...,
69-
sock: None = ..., local_addr: Optional[str] = ..., server_hostname: Optional[str] = ...,
70-
ssl_handshake_timeout: Optional[float] = ...) -> _TransProtPair: ...
68+
@coroutine
69+
def create_connection(self, protocol_factory: _ProtocolFactory, host: str = ..., port: int = ..., *,
70+
ssl: _SSLContext = ..., family: int = ..., proto: int = ..., flags: int = ..., sock: None = ...,
71+
local_addr: Optional[str] = ..., server_hostname: Optional[str] = ...,
72+
ssl_handshake_timeout: Optional[float] = ...) -> Generator[Any, None, _TransProtPair]: ...
7173
@overload
72-
async def create_connection(self, protocol_factory: _ProtocolFactory, host: None = ..., port: None = ..., *,
73-
ssl: _SSLContext = ..., family: int = ..., proto: int = ..., flags: int = ...,
74-
sock: socket, local_addr: None = ..., server_hostname: Optional[str] = ...,
75-
ssl_handshake_timeout: Optional[float] = ...) -> _TransProtPair: ...
74+
@coroutine
75+
def create_connection(self, protocol_factory: _ProtocolFactory, host: None = ..., port: None = ..., *,
76+
ssl: _SSLContext = ..., family: int = ..., proto: int = ..., flags: int = ..., sock: socket,
77+
local_addr: None = ..., server_hostname: Optional[str] = ...,
78+
ssl_handshake_timeout: Optional[float] = ...) -> Generator[Any, None, _TransProtPair]: ...
7679
@overload
77-
async def create_server(self, protocol_factory: _ProtocolFactory, host: Optional[Union[str, Sequence[str]]] = ...,
78-
port: int = ..., *, family: int = ..., flags: int = ..., sock: None = ..., backlog: int = ...,
79-
ssl: _SSLContext = ..., reuse_address: Optional[bool] = ..., reuse_port: Optional[bool] = ...,
80-
ssl_handshake_timeout: Optional[float] = ..., start_serving: bool = ...) -> AbstractServer: ...
80+
@coroutine
81+
def create_server(self, protocol_factory: _ProtocolFactory, host: Optional[Union[str, Sequence[str]]] = ...,
82+
port: int = ..., *, family: int = ..., flags: int = ..., sock: None = ..., backlog: int = ...,
83+
ssl: _SSLContext = ..., reuse_address: Optional[bool] = ..., reuse_port: Optional[bool] = ...,
84+
ssl_handshake_timeout: Optional[float] = ..., start_serving: bool = ...) -> Generator[Any, None, AbstractServer]: ...
8185
@overload
82-
async def create_server(self, protocol_factory: _ProtocolFactory, host: None = ..., port: None = ..., *,
83-
family: int = ..., flags: int = ..., sock: socket = ..., backlog: int = ...,
84-
ssl: _SSLContext = ..., reuse_address: Optional[bool] = ..., reuse_port: Optional[bool] = ...,
85-
ssl_handshake_timeout: Optional[float] = ..., start_serving: bool = ...) -> AbstractServer: ...
86-
async def create_unix_connection(self, protocol_factory: _ProtocolFactory, path: str, *, ssl: _SSLContext = ...,
87-
sock: Optional[socket] = ..., server_hostname: str = ...,
88-
ssl_handshake_timeout: Optional[float]) -> _TransProtPair: ...
89-
async def create_unix_server(self, protocol_factory: _ProtocolFactory, path: str, *, sock: Optional[socket] = ...,
90-
backlog: int = ..., ssl: _SSLContext = ..., ssl_handshake_timeout: Optional[float] = ...,
91-
start_serving: bool = ...) -> AbstractServer: ...
92-
async def connect_accepted_socket(self, protocol_factory: _ProtocolFactory, sock: socket, *, ssl: _SSLContext = ...,
93-
ssl_handshake_timeout: Optional[float] = ...) -> _TransProtPair: ...
94-
async def sendfile(self, transport: BaseTransport, file: IO[bytes], offset: int = ..., count: Optional[int] = ..., *,
95-
fallback: bool = ...) -> int: ...
96-
async def start_tls(self, transport: BaseTransport, protocol: BaseProtocol, sslcontext: ssl.SSLContext, *,
97-
server_side: bool = ..., server_hostname: Optional[str] = ...,
98-
ssl_handshake_timeout: Optional[float] = ...) -> BaseTransport: ...
86+
@coroutine
87+
def create_server(self, protocol_factory: _ProtocolFactory, host: None = ..., port: None = ..., *, family: int = ...,
88+
flags: int = ..., sock: socket = ..., backlog: int = ..., ssl: _SSLContext = ...,
89+
reuse_address: Optional[bool] = ..., reuse_port: Optional[bool] = ...,
90+
ssl_handshake_timeout: Optional[float] = ..., start_serving: bool = ...) -> Generator[Any, None, AbstractServer]: ...
91+
@coroutine
92+
def create_unix_connection(self, protocol_factory: _ProtocolFactory, path: str, *, ssl: _SSLContext = ...,
93+
sock: Optional[socket] = ..., server_hostname: str = ...,
94+
ssl_handshake_timeout: Optional[float]) -> Generator[Any, None, _TransProtPair]: ...
95+
@coroutine
96+
def create_unix_server(self, protocol_factory: _ProtocolFactory, path: str, *, sock: Optional[socket] = ...,
97+
backlog: int = ..., ssl: _SSLContext = ..., ssl_handshake_timeout: Optional[float] = ...,
98+
start_serving: bool = ...) -> Generator[Any, None, AbstractServer]: ...
99+
@coroutine
100+
def connect_accepted_socket(self, protocol_factory: _ProtocolFactory, sock: socket, *, ssl: _SSLContext = ...,
101+
ssl_handshake_timeout: Optional[float] = ...) -> Generator[Any, None, _TransProtPair]: ...
102+
@coroutine
103+
def sendfile(self, transport: BaseTransport, file: IO[bytes], offset: int = ..., count: Optional[int] = ..., *,
104+
fallback: bool = ...) -> Generator[Any, None, int]: ...
105+
@coroutine
106+
def start_tls(self, transport: BaseTransport, protocol: BaseProtocol, sslcontext: ssl.SSLContext, *,
107+
server_side: bool = ..., server_hostname: Optional[str] = ...,
108+
ssl_handshake_timeout: Optional[float] = ...) -> Generator[Any, None, BaseTransport]: ...
99109
else:
100110
@overload
101111
@coroutine
@@ -156,11 +166,16 @@ class BaseEventLoop(AbstractEventLoop):
156166
def remove_writer(self, fd: selectors._FileObject) -> None: ...
157167
# Completion based I/O methods returning Futures prior to 3.7
158168
if sys.version_info >= (3, 7):
159-
async def sock_recv(self, sock: socket, nbytes: int) -> bytes: ...
160-
async def sock_recv_into(self, sock: socket, buf: bytearray) -> int: ...
161-
async def sock_sendall(self, sock: socket, data: bytes) -> None: ...
162-
async def sock_connect(self, sock: socket, address: _Address) -> None: ...
163-
async def sock_accept(self, sock: socket) -> Tuple[socket, _RetAddress]: ...
169+
@coroutine
170+
def sock_recv(self, sock: socket, nbytes: int) -> Generator[Any, None, bytes]: ...
171+
@coroutine
172+
def sock_recv_into(self, sock: socket, buf: bytearray) -> Generator[Any, None, int]: ...
173+
@coroutine
174+
def sock_sendall(self, sock: socket, data: bytes) -> Generator[Any, None, None]: ...
175+
@coroutine
176+
def sock_connect(self, sock: socket, address: _Address) -> Generator[Any, None, None]: ...
177+
@coroutine
178+
def sock_accept(self, sock: socket) -> Generator[Any, None, Tuple[socket, _RetAddress]]: ...
164179
else:
165180
def sock_recv(self, sock: socket, nbytes: int) -> Future[bytes]: ...
166181
def sock_sendall(self, sock: socket, data: bytes) -> Future[None]: ...

stdlib/3/asyncio/events.pyi

+55-38
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ class AbstractServer:
3939
if sys.version_info >= (3, 7):
4040
def get_loop(self) -> AbstractEventLoop: ...
4141
def is_serving(self) -> bool: ...
42-
async def start_serving(self) -> None: ...
43-
async def serve_forever(self) -> None: ...
42+
@coroutine
43+
def start_serving(self) -> Generator[Any, None, None]: ...
44+
@coroutine
45+
def serve_forever(self) -> Generator[Any, None, None]: ...
4446
@coroutine
4547
def wait_closed(self) -> Generator[Any, None, None]: ...
4648

@@ -111,50 +113,60 @@ class AbstractEventLoop(metaclass=ABCMeta):
111113
def getnameinfo(self, sockaddr: tuple, flags: int = ...) -> Generator[Any, None, Tuple[str, int]]: ...
112114
if sys.version_info >= (3, 7):
113115
@abstractmethod
114-
async def sock_sendfile(self, sock: socket, file: IO[bytes], offset: int = ..., count: Optional[int] = ..., *,
115-
fallback: bool = ...) -> int: ...
116+
@coroutine
117+
def sock_sendfile(self, sock: socket, file: IO[bytes], offset: int = ..., count: Optional[int] = ..., *,
118+
fallback: bool = ...) -> Generator[Any, None, int]: ...
116119
@overload
117120
@abstractmethod
118-
async def create_connection(self, protocol_factory: _ProtocolFactory, host: str = ..., port: int = ..., *,
119-
ssl: _SSLContext = ..., family: int = ..., proto: int = ..., flags: int = ...,
120-
sock: None = ..., local_addr: Optional[str] = ..., server_hostname: Optional[str] = ...,
121-
ssl_handshake_timeout: Optional[float] = ...) -> _TransProtPair: ...
121+
@coroutine
122+
def create_connection(self, protocol_factory: _ProtocolFactory, host: str = ..., port: int = ..., *,
123+
ssl: _SSLContext = ..., family: int = ..., proto: int = ..., flags: int = ..., sock: None = ...,
124+
local_addr: Optional[str] = ..., server_hostname: Optional[str] = ...,
125+
ssl_handshake_timeout: Optional[float] = ...) -> Generator[Any, None, _TransProtPair]: ...
122126
@overload
123127
@abstractmethod
124-
async def create_connection(self, protocol_factory: _ProtocolFactory, host: None = ..., port: None = ..., *,
125-
ssl: _SSLContext = ..., family: int = ..., proto: int = ..., flags: int = ...,
126-
sock: socket, local_addr: None = ..., server_hostname: Optional[str] = ...,
127-
ssl_handshake_timeout: Optional[float] = ...) -> _TransProtPair: ...
128+
@coroutine
129+
def create_connection(self, protocol_factory: _ProtocolFactory, host: None = ..., port: None = ..., *,
130+
ssl: _SSLContext = ..., family: int = ..., proto: int = ..., flags: int = ..., sock: socket,
131+
local_addr: None = ..., server_hostname: Optional[str] = ...,
132+
ssl_handshake_timeout: Optional[float] = ...) -> Generator[Any, None, _TransProtPair]: ...
128133
@overload
129134
@abstractmethod
130-
async def create_server(self, protocol_factory: _ProtocolFactory, host: Optional[Union[str, Sequence[str]]] = ...,
131-
port: int = ..., *, family: int = ..., flags: int = ..., sock: None = ..., backlog: int = ...,
132-
ssl: _SSLContext = ..., reuse_address: Optional[bool] = ..., reuse_port: Optional[bool] = ...,
133-
ssl_handshake_timeout: Optional[float] = ..., start_serving: bool = ...) -> AbstractServer: ...
135+
@coroutine
136+
def create_server(self, protocol_factory: _ProtocolFactory, host: Optional[Union[str, Sequence[str]]] = ...,
137+
port: int = ..., *, family: int = ..., flags: int = ..., sock: None = ..., backlog: int = ...,
138+
ssl: _SSLContext = ..., reuse_address: Optional[bool] = ..., reuse_port: Optional[bool] = ...,
139+
ssl_handshake_timeout: Optional[float] = ..., start_serving: bool = ...) -> Generator[Any, None, AbstractServer]: ...
134140
@overload
135141
@abstractmethod
136-
async def create_server(self, protocol_factory: _ProtocolFactory, host: None = ..., port: None = ..., *,
137-
family: int = ..., flags: int = ..., sock: socket = ..., backlog: int = ...,
138-
ssl: _SSLContext = ..., reuse_address: Optional[bool] = ..., reuse_port: Optional[bool] = ...,
139-
ssl_handshake_timeout: Optional[float] = ..., start_serving: bool = ...) -> AbstractServer: ...
142+
@coroutine
143+
def create_server(self, protocol_factory: _ProtocolFactory, host: None = ..., port: None = ..., *,
144+
family: int = ..., flags: int = ..., sock: socket = ..., backlog: int = ...,
145+
ssl: _SSLContext = ..., reuse_address: Optional[bool] = ..., reuse_port: Optional[bool] = ...,
146+
ssl_handshake_timeout: Optional[float] = ..., start_serving: bool = ...) -> Generator[Any, None, AbstractServer]: ...
140147
@abstractmethod
141-
async def create_unix_connection(self, protocol_factory: _ProtocolFactory, path: str, *, ssl: _SSLContext = ...,
142-
sock: Optional[socket] = ..., server_hostname: str = ...,
143-
ssl_handshake_timeout: Optional[float]) -> _TransProtPair: ...
148+
@coroutine
149+
def create_unix_connection(self, protocol_factory: _ProtocolFactory, path: str, *, ssl: _SSLContext = ...,
150+
sock: Optional[socket] = ..., server_hostname: str = ...,
151+
ssl_handshake_timeout: Optional[float]) -> Generator[Any, None, _TransProtPair]: ...
144152
@abstractmethod
145-
async def create_unix_server(self, protocol_factory: _ProtocolFactory, path: str, *, sock: Optional[socket] = ...,
146-
backlog: int = ..., ssl: _SSLContext = ..., ssl_handshake_timeout: Optional[float] = ...,
147-
start_serving: bool = ...) -> AbstractServer: ...
153+
@coroutine
154+
def create_unix_server(self, protocol_factory: _ProtocolFactory, path: str, *, sock: Optional[socket] = ...,
155+
backlog: int = ..., ssl: _SSLContext = ..., ssl_handshake_timeout: Optional[float] = ...,
156+
start_serving: bool = ...) -> Generator[Any, None, AbstractServer]: ...
148157
@abstractmethod
149-
async def connect_accepted_socket(self, protocol_factory: _ProtocolFactory, sock: socket, *, ssl: _SSLContext = ...,
150-
ssl_handshake_timeout: Optional[float] = ...) -> _TransProtPair: ...
158+
@coroutine
159+
def connect_accepted_socket(self, protocol_factory: _ProtocolFactory, sock: socket, *, ssl: _SSLContext = ...,
160+
ssl_handshake_timeout: Optional[float] = ...) -> Generator[Any, None, _TransProtPair]: ...
151161
@abstractmethod
152-
async def sendfile(self, transport: BaseTransport, file: IO[bytes], offset: int = ..., count: Optional[int] = ..., *,
153-
fallback: bool = ...) -> int: ...
162+
@coroutine
163+
def sendfile(self, transport: BaseTransport, file: IO[bytes], offset: int = ..., count: Optional[int] = ..., *,
164+
fallback: bool = ...) -> Generator[Any, None, int]: ...
154165
@abstractmethod
155-
async def start_tls(self, transport: BaseTransport, protocol: BaseProtocol, sslcontext: ssl.SSLContext, *,
156-
server_side: bool = ..., server_hostname: Optional[str] = ...,
157-
ssl_handshake_timeout: Optional[float] = ...) -> BaseTransport: ...
166+
@coroutine
167+
def start_tls(self, transport: BaseTransport, protocol: BaseProtocol, sslcontext: ssl.SSLContext, *,
168+
server_side: bool = ..., server_hostname: Optional[str] = ..., ssl_handshake_timeout: Optional[float] = ...
169+
) -> Generator[Any, None, BaseTransport]: ...
158170
else:
159171
@overload
160172
@abstractmethod
@@ -232,15 +244,20 @@ class AbstractEventLoop(metaclass=ABCMeta):
232244
# Completion based I/O methods returning Futures prior to 3.7
233245
if sys.version_info >= (3, 7):
234246
@abstractmethod
235-
async def sock_recv(self, sock: socket, nbytes: int) -> bytes: ...
247+
@coroutine
248+
def sock_recv(self, sock: socket, nbytes: int) -> Generator[Any, None, bytes]: ...
236249
@abstractmethod
237-
async def sock_recv_into(self, sock: socket, buf: bytearray) -> int: ...
250+
@coroutine
251+
def sock_recv_into(self, sock: socket, buf: bytearray) -> Generator[Any, None, int]: ...
238252
@abstractmethod
239-
async def sock_sendall(self, sock: socket, data: bytes) -> None: ...
253+
@coroutine
254+
def sock_sendall(self, sock: socket, data: bytes) -> Generator[Any, None, None]: ...
240255
@abstractmethod
241-
async def sock_connect(self, sock: socket, address: _Address) -> None: ...
256+
@coroutine
257+
def sock_connect(self, sock: socket, address: _Address) -> Generator[Any, None, None]: ...
242258
@abstractmethod
243-
async def sock_accept(self, sock: socket) -> Tuple[socket, _RetAddress]: ...
259+
@coroutine
260+
def sock_accept(self, sock: socket) -> Generator[Any, None, Tuple[socket, _RetAddress]]: ...
244261
else:
245262
@abstractmethod
246263
def sock_recv(self, sock: socket, nbytes: int) -> Future[bytes]: ...

0 commit comments

Comments
 (0)