Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bdd574d

Browse files
committed
asyncio doc: annotate coroutine on coroutine functions and methods
1 parent 3d6c784 commit bdd574d

6 files changed

Lines changed: 72 additions & 42 deletions

File tree

Doc/library/asyncio-eventloop.rst

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ Coroutines
180180
Creating connections
181181
--------------------
182182

183-
.. method:: BaseEventLoop.create_connection(protocol_factory, host=None, port=None, \*, ssl=None, family=0, proto=0, flags=0, sock=None, local_addr=None, server_hostname=None)
183+
.. coroutinemethod:: BaseEventLoop.create_connection(protocol_factory, host=None, port=None, \*, ssl=None, family=0, proto=0, flags=0, sock=None, local_addr=None, server_hostname=None)
184184

185185
Create a streaming transport connection to a given Internet *host* and
186186
*port*: socket family :py:data:`~socket.AF_INET` or
@@ -253,7 +253,7 @@ Creating connections
253253
(:class:`StreamReader`, :class:`StreamWriter`) instead of a protocol.
254254

255255

256-
.. method:: BaseEventLoop.create_datagram_endpoint(protocol_factory, local_addr=None, remote_addr=None, \*, family=0, proto=0, flags=0)
256+
.. coroutinemethod:: BaseEventLoop.create_datagram_endpoint(protocol_factory, local_addr=None, remote_addr=None, \*, family=0, proto=0, flags=0)
257257

258258
Create datagram connection: socket family :py:data:`~socket.AF_INET` or
259259
:py:data:`~socket.AF_INET6` depending on *host* (or *family* if specified),
@@ -271,7 +271,7 @@ Creating connections
271271
:ref:`UDP echo server protocol <asyncio-udp-echo-server-protocol>` examples.
272272

273273

274-
.. method:: BaseEventLoop.create_unix_connection(protocol_factory, path, \*, ssl=None, sock=None, server_hostname=None)
274+
.. coroutinemethod:: BaseEventLoop.create_unix_connection(protocol_factory, path, \*, ssl=None, sock=None, server_hostname=None)
275275

276276
Create UNIX connection: socket family :py:data:`~socket.AF_UNIX`, socket
277277
type :py:data:`~socket.SOCK_STREAM`. The :py:data:`~socket.AF_UNIX` socket
@@ -290,7 +290,7 @@ Creating connections
290290
Creating listening connections
291291
------------------------------
292292

293-
.. method:: BaseEventLoop.create_server(protocol_factory, host=None, port=None, \*, family=socket.AF_UNSPEC, flags=socket.AI_PASSIVE, sock=None, backlog=100, ssl=None, reuse_address=None)
293+
.. coroutinemethod:: BaseEventLoop.create_server(protocol_factory, host=None, port=None, \*, family=socket.AF_UNSPEC, flags=socket.AI_PASSIVE, sock=None, backlog=100, ssl=None, reuse_address=None)
294294

295295
Create a TCP server (socket type :data:`~socket.SOCK_STREAM`) bound to
296296
*host* and *port*.
@@ -336,11 +336,13 @@ Creating listening connections
336336
:class:`StreamWriter`) pair and calls back a function with this pair.
337337

338338

339-
.. method:: BaseEventLoop.create_unix_server(protocol_factory, path=None, \*, sock=None, backlog=100, ssl=None)
339+
.. coroutinemethod:: BaseEventLoop.create_unix_server(protocol_factory, path=None, \*, sock=None, backlog=100, ssl=None)
340340

341341
Similar to :meth:`BaseEventLoop.create_server`, but specific to the
342342
socket family :py:data:`~socket.AF_UNIX`.
343343

344+
This method is a :ref:`coroutine <coroutine>`.
345+
344346
Availability: UNIX.
345347

346348

@@ -384,7 +386,7 @@ the file descriptor of a socket.
384386
Low-level socket operations
385387
---------------------------
386388

387-
.. method:: BaseEventLoop.sock_recv(sock, nbytes)
389+
.. coroutinemethod:: BaseEventLoop.sock_recv(sock, nbytes)
388390

389391
Receive data from the socket. The return value is a bytes object
390392
representing the data received. The maximum amount of data to be received
@@ -399,7 +401,7 @@ Low-level socket operations
399401

400402
The :meth:`socket.socket.recv` method.
401403

402-
.. method:: BaseEventLoop.sock_sendall(sock, data)
404+
.. coroutinemethod:: BaseEventLoop.sock_sendall(sock, data)
403405

404406
Send data to the socket. The socket must be connected to a remote socket.
405407
This method continues to send data from *data* until either all data has
@@ -416,7 +418,7 @@ Low-level socket operations
416418

417419
The :meth:`socket.socket.sendall` method.
418420

419-
.. method:: BaseEventLoop.sock_connect(sock, address)
421+
.. coroutinemethod:: BaseEventLoop.sock_connect(sock, address)
420422

421423
Connect to a remote socket at *address*.
422424

@@ -438,7 +440,7 @@ Low-level socket operations
438440
method.
439441

440442

441-
.. method:: BaseEventLoop.sock_accept(sock)
443+
.. coroutinemethod:: BaseEventLoop.sock_accept(sock)
442444

443445
Accept a connection. The socket must be bound to an address and listening
444446
for connections. The return value is a pair ``(conn, address)`` where *conn*
@@ -459,12 +461,12 @@ Low-level socket operations
459461
Resolve host name
460462
-----------------
461463

462-
.. method:: BaseEventLoop.getaddrinfo(host, port, \*, family=0, type=0, proto=0, flags=0)
464+
.. coroutinemethod:: BaseEventLoop.getaddrinfo(host, port, \*, family=0, type=0, proto=0, flags=0)
463465

464466
This method is a :ref:`coroutine <coroutine>`, similar to
465467
:meth:`socket.getaddrinfo` function but non-blocking.
466468

467-
.. method:: BaseEventLoop.getnameinfo(sockaddr, flags=0)
469+
.. coroutinemethod:: BaseEventLoop.getnameinfo(sockaddr, flags=0)
468470

469471
This method is a :ref:`coroutine <coroutine>`, similar to
470472
:meth:`socket.getnameinfo` function but non-blocking.
@@ -476,7 +478,7 @@ Connect pipes
476478
On Windows with :class:`SelectorEventLoop`, these methods are not supported.
477479
Use :class:`ProactorEventLoop` to support pipes on Windows.
478480

479-
.. method:: BaseEventLoop.connect_read_pipe(protocol_factory, pipe)
481+
.. coroutinemethod:: BaseEventLoop.connect_read_pipe(protocol_factory, pipe)
480482

481483
Register read pipe in eventloop.
482484

@@ -490,7 +492,7 @@ Use :class:`ProactorEventLoop` to support pipes on Windows.
490492

491493
This method is a :ref:`coroutine <coroutine>`.
492494

493-
.. method:: BaseEventLoop.connect_write_pipe(protocol_factory, pipe)
495+
.. coroutinemethod:: BaseEventLoop.connect_write_pipe(protocol_factory, pipe)
494496

495497
Register write pipe in eventloop.
496498

@@ -543,7 +545,7 @@ Call a function in an :class:`~concurrent.futures.Executor` (pool of threads or
543545
pool of processes). By default, an event loop uses a thread pool executor
544546
(:class:`~concurrent.futures.ThreadPoolExecutor`).
545547

546-
.. method:: BaseEventLoop.run_in_executor(executor, callback, \*args)
548+
.. coroutinemethod:: BaseEventLoop.run_in_executor(executor, callback, \*args)
547549

548550
Arrange for a callback to be called in the specified executor.
549551

@@ -654,7 +656,7 @@ Server
654656
The server is closed asynchonously, use the :meth:`wait_closed` coroutine
655657
to wait until the server is closed.
656658

657-
.. method:: wait_closed()
659+
.. coroutinemethod:: wait_closed()
658660

659661
Wait until the :meth:`close` method completes.
660662

Doc/library/asyncio-stream.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Streams (high-level API)
99
Stream functions
1010
================
1111

12-
.. function:: open_connection(host=None, port=None, \*, loop=None, limit=None, **kwds)
12+
.. coroutinefunction:: open_connection(host=None, port=None, \*, loop=None, limit=None, \*\*kwds)
1313

1414
A wrapper for :meth:`~BaseEventLoop.create_connection()` returning a (reader,
1515
writer) pair.
@@ -32,7 +32,7 @@ Stream functions
3232

3333
This function is a :ref:`coroutine <coroutine>`.
3434

35-
.. function:: start_server(client_connected_cb, host=None, port=None, \*, loop=None, limit=None, **kwds)
35+
.. coroutinefunction:: start_server(client_connected_cb, host=None, port=None, \*, loop=None, limit=None, \*\*kwds)
3636

3737
Start a socket server, with a callback for each client connected. The return
3838
value is the same as :meth:`~BaseEventLoop.create_server()`.
@@ -56,7 +56,7 @@ Stream functions
5656

5757
This function is a :ref:`coroutine <coroutine>`.
5858

59-
.. function:: open_unix_connection(path=None, \*, loop=None, limit=None, **kwds)
59+
.. coroutinefunction:: open_unix_connection(path=None, \*, loop=None, limit=None, **kwds)
6060

6161
A wrapper for :meth:`~BaseEventLoop.create_unix_connection()` returning
6262
a (reader, writer) pair.
@@ -68,7 +68,7 @@ Stream functions
6868

6969
Availability: UNIX.
7070

71-
.. function:: start_unix_server(client_connected_cb, path=None, \*, loop=None, limit=None, **kwds)
71+
.. coroutinefunction:: start_unix_server(client_connected_cb, path=None, \*, loop=None, limit=None, **kwds)
7272

7373
Start a UNIX Domain Socket server, with a callback for each client connected.
7474

@@ -106,7 +106,7 @@ StreamReader
106106

107107
Set the transport.
108108

109-
.. method:: read(n=-1)
109+
.. coroutinemethod:: read(n=-1)
110110

111111
Read up to *n* bytes. If *n* is not provided, or set to ``-1``,
112112
read until EOF and return all read bytes.
@@ -116,7 +116,7 @@ StreamReader
116116

117117
This method is a :ref:`coroutine <coroutine>`.
118118

119-
.. method:: readline()
119+
.. coroutinemethod:: readline()
120120

121121
Read one line, where "line" is a sequence of bytes ending with ``\n``.
122122

@@ -128,7 +128,7 @@ StreamReader
128128

129129
This method is a :ref:`coroutine <coroutine>`.
130130

131-
.. method:: readexactly(n)
131+
.. coroutinemethod:: readexactly(n)
132132

133133
Read exactly *n* bytes. Raise an :exc:`IncompleteReadError` if the end of
134134
the stream is reached before *n* can be read, the
@@ -168,7 +168,7 @@ StreamWriter
168168

169169
Close the transport: see :meth:`BaseTransport.close`.
170170

171-
.. method:: drain()
171+
.. coroutinemethod:: drain()
172172

173173
Let the write buffer of the underlying transport a chance to be flushed.
174174

Doc/library/asyncio-subprocess.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Example to use it on Windows::
2727
Create a subprocess: high-level API using Process
2828
-------------------------------------------------
2929

30-
.. function:: create_subprocess_exec(\*args, stdin=None, stdout=None, stderr=None, loop=None, limit=None, \*\*kwds)
30+
.. coroutinefunction:: create_subprocess_exec(\*args, stdin=None, stdout=None, stderr=None, loop=None, limit=None, \*\*kwds)
3131

3232
Create a subprocess.
3333

@@ -39,7 +39,7 @@ Create a subprocess: high-level API using Process
3939

4040
This function is a :ref:`coroutine <coroutine>`.
4141

42-
.. function:: create_subprocess_shell(cmd, stdin=None, stdout=None, stderr=None, loop=None, limit=None, \*\*kwds)
42+
.. coroutinefunction:: create_subprocess_shell(cmd, stdin=None, stdout=None, stderr=None, loop=None, limit=None, \*\*kwds)
4343

4444
Run the shell command *cmd*.
4545

@@ -67,7 +67,7 @@ Create a subprocess: low-level API using subprocess.Popen
6767

6868
Run subprocesses asynchronously using the :mod:`subprocess` module.
6969

70-
.. method:: BaseEventLoop.subprocess_exec(protocol_factory, \*args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, \*\*kwargs)
70+
.. coroutinemethod:: BaseEventLoop.subprocess_exec(protocol_factory, \*args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, \*\*kwargs)
7171

7272
Create a subprocess from one or more string arguments (character strings or
7373
bytes strings encoded to the :ref:`filesystem encoding
@@ -116,7 +116,7 @@ Run subprocesses asynchronously using the :mod:`subprocess` module.
116116

117117
See the constructor of the :class:`subprocess.Popen` class for parameters.
118118

119-
.. method:: BaseEventLoop.subprocess_shell(protocol_factory, cmd, \*, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, \*\*kwargs)
119+
.. coroutinemethod:: BaseEventLoop.subprocess_shell(protocol_factory, cmd, \*, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, \*\*kwargs)
120120

121121
Create a subprocess from *cmd*, which is a character string or a bytes
122122
string encoded to the :ref:`filesystem encoding <filesystem-encoding>`,
@@ -193,7 +193,7 @@ Process
193193
:meth:`~subprocess.Popen.wait` method of the :class:`~subprocess.Popen`
194194
class is implemented as a busy loop.
195195

196-
.. method:: wait()
196+
.. coroutinemethod:: wait()
197197

198198
Wait for child process to terminate. Set and return :attr:`returncode`
199199
attribute.
@@ -207,7 +207,7 @@ Process
207207
blocks waiting for the OS pipe buffer to accept more data. Use the
208208
:meth:`communicate` method when using pipes to avoid that.
209209

210-
.. method:: communicate(input=None)
210+
.. coroutinemethod:: communicate(input=None)
211211

212212
Interact with process: Send data to stdin. Read data from stdout and
213213
stderr, until end-of-file is reached. Wait for process to terminate.

Doc/library/asyncio-sync.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ Lock
8989

9090
Return ``True`` if the lock is acquired.
9191

92-
.. method:: acquire()
92+
.. coroutinemethod:: acquire()
9393

9494
Acquire a lock.
9595

@@ -139,7 +139,7 @@ Event
139139
true are awakened. Coroutine that call :meth:`wait` once the flag is true
140140
will not block at all.
141141

142-
.. method:: wait()
142+
.. coroutinemethod:: wait()
143143

144144
Block until the internal flag is true.
145145

@@ -166,7 +166,7 @@ Condition
166166
object, and it is used as the underlying lock. Otherwise,
167167
a new :class:`Lock` object is created and used as the underlying lock.
168168

169-
.. method:: acquire()
169+
.. coroutinemethod:: acquire()
170170

171171
Acquire the underlying lock.
172172

@@ -213,7 +213,7 @@ Condition
213213

214214
There is no return value.
215215

216-
.. method:: wait()
216+
.. coroutinemethod:: wait()
217217

218218
Wait until notified.
219219

@@ -227,7 +227,7 @@ Condition
227227

228228
This method is a :ref:`coroutine <coroutine>`.
229229

230-
.. method:: wait_for(predicate)
230+
.. coroutinemethod:: wait_for(predicate)
231231

232232
Wait until a predicate becomes true.
233233

@@ -258,7 +258,7 @@ Semaphore
258258
defaults to ``1``. If the value given is less than ``0``, :exc:`ValueError`
259259
is raised.
260260

261-
.. method:: acquire()
261+
.. coroutinemethod:: acquire()
262262

263263
Acquire a semaphore.
264264

@@ -273,7 +273,7 @@ Semaphore
273273

274274
Returns ``True`` if semaphore can not be acquired immediately.
275275

276-
.. method:: release()
276+
.. coroutinemethod:: release()
277277

278278
Release a semaphore, incrementing the internal counter by one. When it
279279
was zero on entry and another coroutine is waiting for it to become
@@ -323,7 +323,7 @@ Queue
323323
If the Queue was initialized with ``maxsize=0`` (the default), then
324324
:meth:`full()` is never ``True``.
325325

326-
.. method:: get()
326+
.. coroutinemethod:: get()
327327

328328
Remove and return an item from the queue. If queue is empty, wait until
329329
an item is available.
@@ -341,7 +341,7 @@ Queue
341341
Return an item if one is immediately available, else raise
342342
:exc:`QueueEmpty`.
343343

344-
.. method:: put(item)
344+
.. coroutinemethod:: put(item)
345345

346346
Put an item into the queue. If the queue is full, wait until a free slot
347347
is available before adding item.
@@ -395,7 +395,7 @@ JoinableQueue
395395
A subclass of :class:`Queue` with :meth:`task_done` and :meth:`join`
396396
methods.
397397

398-
.. method:: join()
398+
.. coroutinemethod:: join()
399399

400400
Block until all items in the queue have been gotten and processed.
401401

Doc/library/asyncio-task.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ Task functions
545545
Return ``True`` if *func* is a decorated :ref:`coroutine function
546546
<coroutine>`.
547547

548-
.. function:: sleep(delay, result=None, \*, loop=None)
548+
.. coroutinefunction:: sleep(delay, result=None, \*, loop=None)
549549

550550
Create a :ref:`coroutine <coroutine>` that completes after a given
551551
time (in seconds). If *result* is provided, it is produced to the caller
@@ -554,6 +554,8 @@ Task functions
554554
The resolution of the sleep depends on the :ref:`granularity of the event
555555
loop <asyncio-delayed-calls>`.
556556

557+
This function is a :ref:`coroutine <coroutine>`.
558+
557559
.. function:: shield(arg, \*, loop=None)
558560

559561
Wait for a future, shielding it from cancellation.
@@ -581,7 +583,7 @@ Task functions
581583
except CancelledError:
582584
res = None
583585

584-
.. function:: wait(futures, \*, loop=None, timeout=None, return_when=ALL_COMPLETED)
586+
.. coroutinefunction:: wait(futures, \*, loop=None, timeout=None, return_when=ALL_COMPLETED)
585587

586588
Wait for the Futures and coroutine objects given by the sequence *futures*
587589
to complete. Coroutines will be wrapped in Tasks. Returns two sets of
@@ -626,7 +628,7 @@ Task functions
626628
when the timeout occurs are returned in the second set.
627629

628630

629-
.. function:: wait_for(fut, timeout, \*, loop=None)
631+
.. coroutinefunction:: wait_for(fut, timeout, \*, loop=None)
630632

631633
Wait for the single :class:`Future` or :ref:`coroutine object <coroutine>`
632634
to complete with timeout. If *timeout* is ``None``, block until the future

0 commit comments

Comments
 (0)