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

Skip to content

Commit 37f15bc

Browse files
committed
asyncio.docs: Improve wordings; add a note to the Coroutines section. Issue #20706
1 parent 934c885 commit 37f15bc

4 files changed

Lines changed: 49 additions & 38 deletions

File tree

Doc/library/asyncio-eventloop.rst

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ Run an event loop
102102

103103
Run until the :class:`Future` is done.
104104

105-
If the argument is a coroutine, it is wrapped in a :class:`Task`.
105+
If the argument is a :ref:`coroutine <coroutine>`, it is wrapped
106+
in a :class:`Task`.
106107

107108
Return the Future's result, or raise its exception.
108109

@@ -207,7 +208,7 @@ Creating connections
207208
socket type :py:data:`~socket.SOCK_STREAM`. *protocol_factory* must be a
208209
callable returning a :ref:`protocol <asyncio-protocol>` instance.
209210

210-
This method returns a :ref:`coroutine object <coroutine>` which will try to
211+
This method is a :ref:`coroutine <coroutine>` which will try to
211212
establish the connection in the background. When successful, the
212213
coroutine returns a ``(transport, protocol)`` pair.
213214

@@ -274,7 +275,7 @@ Creating connections
274275
:py:data:`~socket.AF_INET6` depending on *host* (or *family* if specified),
275276
socket type :py:data:`~socket.SOCK_DGRAM`.
276277

277-
This method returns a :ref:`coroutine object <coroutine>` which will try to
278+
This method is a :ref:`coroutine <coroutine>` which will try to
278279
establish the connection in the background. When successful, the
279280
coroutine returns a ``(transport, protocol)`` pair.
280281

@@ -288,7 +289,7 @@ Creating connections
288289
family is used to communicate between processes on the same machine
289290
efficiently.
290291

291-
This method returns a :ref:`coroutine object <coroutine>` which will try to
292+
This method is a :ref:`coroutine <coroutine>` which will try to
292293
establish the connection in the background. When successful, the
293294
coroutine returns a ``(transport, protocol)`` pair.
294295

@@ -302,8 +303,8 @@ Creating listening connections
302303

303304
.. 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)
304305

305-
A :ref:`coroutine function <coroutine>` which creates a TCP server bound to host and
306-
port.
306+
A :ref:`coroutine <coroutine>` method which creates a TCP server bound to
307+
host and port.
307308

308309
The return value is a :class:`AbstractServer` object which can be used to stop
309310
the service.
@@ -332,8 +333,6 @@ Creating listening connections
332333
expire. If not specified will automatically be set to True on
333334
UNIX.
334335

335-
This method returns a :ref:`coroutine object <coroutine>`.
336-
337336
.. seealso::
338337

339338
The function :func:`start_server` creates a (:class:`StreamReader`,
@@ -380,7 +379,7 @@ Low-level socket operations
380379
representing the data received. The maximum amount of data to be received
381380
at once is specified by *nbytes*.
382381

383-
This method returns a :ref:`coroutine object <coroutine>`.
382+
This method is a :ref:`coroutine <coroutine>`.
384383

385384
.. seealso::
386385

@@ -392,9 +391,9 @@ Low-level socket operations
392391
This method continues to send data from *data* until either all data has
393392
been sent or an error occurs. ``None`` is returned on success. On error,
394393
an exception is raised, and there is no way to determine how much data, if
395-
any, was successfully sent.
394+
any, was successfully processed by the receiving end of the connection.
396395

397-
This method returns a :ref:`coroutine object <coroutine>`.
396+
This method is a :ref:`coroutine <coroutine>`.
398397

399398
.. seealso::
400399

@@ -410,7 +409,7 @@ Low-level socket operations
410409
:py:data:`~socket.AF_INET` and :py:data:`~socket.AF_INET6` address families.
411410
Use :meth:`getaddrinfo` to resolve the hostname asynchronously.
412411

413-
This method returns a :ref:`coroutine object <coroutine>`.
412+
This method is a :ref:`coroutine <coroutine>`.
414413

415414
.. seealso::
416415

@@ -427,7 +426,7 @@ Low-level socket operations
427426
and *address* is the address bound to the socket on the other end of the
428427
connection.
429428

430-
This method returns a :ref:`coroutine object <coroutine>`.
429+
This method is a :ref:`coroutine <coroutine>`.
431430

432431
.. seealso::
433432

@@ -440,13 +439,13 @@ Resolve host name
440439

441440
.. method:: BaseEventLoop.getaddrinfo(host, port, \*, family=0, type=0, proto=0, flags=0)
442441

443-
Similar to the :meth:`socket.getaddrinfo` function, but return a
444-
:ref:`coroutine object <coroutine>`.
442+
This method is a :ref:`coroutine <coroutine>`, similar to
443+
:meth:`socket.getaddrinfo` function but non-blocking.
445444

446445
.. method:: BaseEventLoop.getnameinfo(sockaddr, flags=0)
447446

448-
Similar to the :meth:`socket.getnameinfo` function, but return a
449-
:ref:`coroutine object <coroutine>`.
447+
This method is a :ref:`coroutine <coroutine>`, similar to
448+
:meth:`socket.getnameinfo` function but non-blocking.
450449

451450

452451
Running subprocesses
@@ -472,15 +471,15 @@ Run subprocesses asynchronously using the :mod:`subprocess` module.
472471

473472
XXX
474473

475-
This method returns a :ref:`coroutine object <coroutine>`.
474+
This method is a :ref:`coroutine <coroutine>`.
476475

477476
See the constructor of the :class:`subprocess.Popen` class for parameters.
478477

479478
.. method:: BaseEventLoop.subprocess_shell(protocol_factory, cmd, \*, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=False, shell=True, bufsize=0, \*\*kwargs)
480479

481480
XXX
482481

483-
This method returns a :ref:`coroutine object <coroutine>`.
482+
This method is a :ref:`coroutine <coroutine>`.
484483

485484
See the constructor of the :class:`subprocess.Popen` class for parameters.
486485

@@ -493,7 +492,7 @@ Run subprocesses asynchronously using the :mod:`subprocess` module.
493492
Return pair (transport, protocol), where transport support
494493
:class:`ReadTransport` interface.
495494

496-
This method returns a :ref:`coroutine object <coroutine>`.
495+
This method is a :ref:`coroutine <coroutine>`.
497496

498497
.. method:: BaseEventLoop.connect_write_pipe(protocol_factory, pipe)
499498

@@ -504,7 +503,7 @@ Run subprocesses asynchronously using the :mod:`subprocess` module.
504503
Return pair (transport, protocol), where transport support
505504
:class:`WriteTransport` interface.
506505

507-
This method returns a :ref:`coroutine object <coroutine>`.
506+
This method is a :ref:`coroutine <coroutine>`.
508507

509508
.. seealso::
510509

@@ -549,6 +548,8 @@ pool of processes). By default, an event loop uses a thread pool executor
549548
*executor* is a :class:`~concurrent.futures.Executor` instance,
550549
the default executor is used if *executor* is ``None``.
551550

551+
This method is a :ref:`coroutine <coroutine>`.
552+
552553
.. method:: BaseEventLoop.set_default_executor(executor)
553554

554555
Set the default executor used by :meth:`run_in_executor`.
@@ -633,7 +634,7 @@ Server
633634

634635
.. method:: wait_closed()
635636

636-
Coroutine to wait until service is closed.
637+
A :ref:`coroutine <coroutine>` to wait until service is closed.
637638

638639

639640
Handle

Doc/library/asyncio-stream.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Stream functions
3030
:class:`StreamReaderProtocol` classes, just copy the code -- there's really
3131
nothing special here except some convenience.)
3232

33-
This function returns a :ref:`coroutine object <coroutine>`.
33+
This function is a :ref:`coroutine <coroutine>`.
3434

3535
.. function:: start_server(client_connected_cb, host=None, port=None, \*, loop=None, limit=None, **kwds)
3636

@@ -56,7 +56,7 @@ Stream functions
5656
The return value is the same as :meth:`~BaseEventLoop.create_server()`, i.e.
5757
a :class:`AbstractServer` object which can be used to stop the service.
5858

59-
This function returns a :ref:`coroutine object <coroutine>`.
59+
This function is a :ref:`coroutine <coroutine>`.
6060

6161
.. function:: open_unix_connection(path=None, \*, loop=None, limit=None, **kwds)
6262

@@ -66,7 +66,7 @@ Stream functions
6666
See :func:`open_connection` for information about return value and other
6767
details.
6868

69-
This function returns a :ref:`coroutine object <coroutine>`.
69+
This function is a :ref:`coroutine <coroutine>`.
7070

7171
Availability: UNIX.
7272

@@ -77,7 +77,7 @@ Stream functions
7777
See :func:`start_server` for information about return value and other
7878
details.
7979

80-
This function returns a :ref:`coroutine object <coroutine>`.
80+
This function is a :ref:`coroutine <coroutine>`.
8181

8282
Availability: UNIX.
8383

@@ -116,7 +116,7 @@ StreamReader
116116
If the EOF was received and the internal buffer is empty,
117117
return an empty ``bytes`` object.
118118

119-
This method returns a :ref:`coroutine object <coroutine>`.
119+
This method is a :ref:`coroutine <coroutine>`.
120120

121121
.. method:: readline()
122122

@@ -128,7 +128,7 @@ StreamReader
128128
If the EOF was received and the internal buffer is empty,
129129
return an empty ``bytes`` object.
130130

131-
This method returns a :ref:`coroutine object <coroutine>`.
131+
This method is a :ref:`coroutine <coroutine>`.
132132

133133
.. method:: readexactly(n)
134134

@@ -137,7 +137,7 @@ StreamReader
137137
:attr:`IncompleteReadError.partial` attribute of the exception contains
138138
the partial read bytes.
139139

140-
This method returns a :ref:`coroutine object <coroutine>`.
140+
This method is a :ref:`coroutine <coroutine>`.
141141

142142
.. method:: at_eof()
143143

Doc/library/asyncio-sync.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ Event
124124
Otherwise, block until another coroutine calls :meth:`set` to set the
125125
flag to true, then return ``True``.
126126

127-
This method returns a :ref:`coroutine object <coroutine>`.
127+
This method is a :ref:`coroutine <coroutine>`.
128128

129129

130130
Condition
@@ -175,7 +175,7 @@ Condition
175175
condition variable in another coroutine. Once awakened, it re-acquires
176176
the lock and returns ``True``.
177177

178-
This method returns a :ref:`coroutine object <coroutine>`.
178+
This method is a :ref:`coroutine <coroutine>`.
179179

180180
.. method:: wait_for(predicate)
181181

@@ -184,7 +184,7 @@ Condition
184184
The predicate should be a callable which result will be interpreted as a
185185
boolean value. The final predicate value is the return value.
186186

187-
This method returns a :ref:`coroutine object <coroutine>`.
187+
This method is a :ref:`coroutine <coroutine>`.
188188

189189

190190
Semaphores
@@ -217,7 +217,7 @@ Semaphore
217217
until some other coroutine has called :meth:`release` to make it larger
218218
than ``0``, and then return ``True``.
219219

220-
This method returns a :ref:`coroutine object <coroutine>`.
220+
This method is a :ref:`coroutine <coroutine>`.
221221

222222
.. method:: locked()
223223

@@ -279,7 +279,7 @@ Queue
279279

280280
If you yield from :meth:`get()`, wait until a item is available.
281281

282-
This method returns a :ref:`coroutine object <coroutine>`.
282+
This method is a :ref:`coroutine <coroutine>`.
283283

284284
.. method:: get_nowait()
285285

@@ -295,7 +295,7 @@ Queue
295295
If you yield from ``put()``, wait until a free slot is available before
296296
adding item.
297297

298-
This method returns a :ref:`coroutine object <coroutine>`.
298+
This method is a :ref:`coroutine <coroutine>`.
299299

300300
.. method:: put_nowait(item)
301301

@@ -350,7 +350,7 @@ JoinableQueue
350350
it is complete. When the count of unfinished tasks drops to zero,
351351
:meth:`join` unblocks.
352352

353-
This method returns a :ref:`coroutine object <coroutine>`.
353+
This method is a :ref:`coroutine <coroutine>`.
354354

355355
.. method:: task_done()
356356

Doc/library/asyncio-task.rst

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ Coroutines (and tasks) can only run when the event loop is running.
6464
message is logged. See :ref:`Detect coroutines never scheduled
6565
<asyncio-coroutine-not-scheduled>`.
6666

67+
.. note::
68+
69+
In this documentation, some methods are documented as coroutines,
70+
even if they are plain Python functions returning a :class:`Future`.
71+
This is intentional to have a freedom of tweaking the implementation
72+
of these functions in the future. If such a function is needed to be
73+
used in a callback-style code, wrap its result with :func:`async`.
74+
6775

6876
.. _asyncio-hello-world-coroutine:
6977

@@ -440,7 +448,7 @@ Task functions
440448

441449
.. function:: sleep(delay, result=None, \*, loop=None)
442450

443-
Create a :ref:`coroutine object <coroutine>` that completes after a given
451+
Create a :ref:`coroutine <coroutine>` that completes after a given
444452
time (in seconds). If *result* is provided, it is produced to the caller
445453
when the coroutine completes.
446454

@@ -505,7 +513,7 @@ Task functions
505513
| | futures finish or are cancelled. |
506514
+-----------------------------+----------------------------------------+
507515

508-
This function returns a :ref:`coroutine object <coroutine>`.
516+
This function is a :ref:`coroutine <coroutine>`.
509517

510518
Usage::
511519

@@ -529,6 +537,8 @@ Task functions
529537
cancels the task and raises :exc:`TimeoutError`. To avoid the task
530538
cancellation, wrap it in :func:`shield`.
531539

540+
This function is a :ref:`coroutine <coroutine>`.
541+
532542
Usage::
533543

534544
result = yield from asyncio.wait_for(fut, 60.0)

0 commit comments

Comments
 (0)