Skip to content

Commit 2aba3d9

Browse files
[3.15] gh-150285: Fix too long docstrings in the asyncio package (GH-151074) (GH-151172)
(cherry picked from commit ed2b042) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent ca0cb46 commit 2aba3d9

13 files changed

Lines changed: 133 additions & 118 deletions

Lib/asyncio/base_events.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -487,10 +487,10 @@ def set_task_factory(self, factory):
487487
If factory is None the default task factory will be set.
488488
489489
If factory is a callable, it should have a signature matching
490-
'(loop, coro, **kwargs)', where 'loop' will be a reference to the active
491-
event loop, 'coro' will be a coroutine object, and **kwargs will be
492-
arbitrary keyword arguments that should be passed on to Task.
493-
The callable must return a Task.
490+
'(loop, coro, **kwargs)', where 'loop' will be a reference to the
491+
active event loop, 'coro' will be a coroutine object, and **kwargs
492+
will be arbitrary keyword arguments that should be passed on to
493+
Task. The callable must return a Task.
494494
"""
495495
if factory is not None and not callable(factory):
496496
raise TypeError('task factory must be a callable or None')
@@ -726,8 +726,8 @@ def run_until_complete(self, future):
726726
def stop(self):
727727
"""Stop running the event loop.
728728
729-
Every callback already scheduled will still run. This simply informs
730-
run_forever to stop looping after a complete iteration.
729+
Every callback already scheduled will still run. This simply
730+
informs run_forever to stop looping after a complete iteration.
731731
"""
732732
self._stopping = True
733733

@@ -1075,12 +1075,12 @@ async def create_connection(
10751075
10761076
Create a streaming transport connection to a given internet host and
10771077
port: socket family AF_INET or socket.AF_INET6 depending on host (or
1078-
family if specified), socket type SOCK_STREAM. protocol_factory must be
1079-
a callable returning a protocol instance.
1078+
family if specified), socket type SOCK_STREAM. protocol_factory must
1079+
be a callable returning a protocol instance.
10801080
1081-
This method is a coroutine which will try to establish the connection
1082-
in the background. When successful, the coroutine returns a
1083-
(transport, protocol) pair.
1081+
This method is a coroutine which will try to establish the
1082+
connection in the background. When successful, the coroutine
1083+
returns a (transport, protocol) pair.
10841084
"""
10851085
if server_hostname is not None and not ssl:
10861086
raise ValueError('server_hostname is only meaningful with ssl')
@@ -1549,11 +1549,11 @@ async def create_server(
15491549
The host parameter can be a string, in that case the TCP server is
15501550
bound to host and port.
15511551
1552-
The host parameter can also be a sequence of strings and in that case
1553-
the TCP server is bound to all hosts of the sequence. If a host
1554-
appears multiple times (possibly indirectly e.g. when hostnames
1555-
resolve to the same IP address), the server is only bound once to that
1556-
host.
1552+
The host parameter can also be a sequence of strings and in that
1553+
case the TCP server is bound to all hosts of the sequence. If
1554+
a host appears multiple times (possibly indirectly e.g. when
1555+
hostnames resolve to the same IP address), the server is only bound
1556+
once to that host.
15571557
15581558
Return a Server object which can be used to stop the service.
15591559

Lib/asyncio/events.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,8 @@ async def create_server(
374374
375375
If host is an empty string or None all interfaces are assumed
376376
and a list of multiple sockets will be returned (most likely
377-
one for IPv4 and another one for IPv6). The host parameter can also be
378-
a sequence (e.g. list) of hosts to bind to.
377+
one for IPv4 and another one for IPv6). The host parameter can also
378+
be a sequence (e.g. list) of hosts to bind to.
379379
380380
family can be set to either AF_INET or AF_INET6 to force the
381381
socket to use IPv4 or IPv6. If not set it will be determined
@@ -415,8 +415,9 @@ async def create_server(
415415
416416
start_serving set to True (default) causes the created server
417417
to start accepting connections immediately. When set to False,
418-
the user should await Server.start_serving() or Server.serve_forever()
419-
to make the server to start accepting connections.
418+
the user should await Server.start_serving() or
419+
Server.serve_forever() to make the server to start accepting
420+
connections.
420421
"""
421422
raise NotImplementedError
422423

@@ -479,8 +480,9 @@ async def create_unix_server(
479480
480481
start_serving set to True (default) causes the created server
481482
to start accepting connections immediately. When set to False,
482-
the user should await Server.start_serving() or Server.serve_forever()
483-
to make the server to start accepting connections.
483+
the user should await Server.start_serving() or
484+
Server.serve_forever() to make the server to start accepting
485+
connections.
484486
"""
485487
raise NotImplementedError
486488

@@ -511,8 +513,8 @@ async def create_datagram_endpoint(self, protocol_factory,
511513
512514
protocol_factory must be a callable returning a protocol instance.
513515
514-
socket family AF_INET, socket.AF_INET6 or socket.AF_UNIX depending on
515-
host (or family if specified), socket type SOCK_DGRAM.
516+
socket family AF_INET, socket.AF_INET6 or socket.AF_UNIX depending
517+
on host (or family if specified), socket type SOCK_DGRAM.
516518
517519
reuse_address tells the kernel to reuse a local socket in
518520
TIME_WAIT state, without waiting for its natural timeout to
@@ -552,7 +554,8 @@ async def connect_read_pipe(self, protocol_factory, pipe):
552554
async def connect_write_pipe(self, protocol_factory, pipe):
553555
"""Register write pipe in event loop.
554556
555-
protocol_factory should instantiate object with BaseProtocol interface.
557+
protocol_factory should instantiate object with BaseProtocol
558+
interface.
556559
Pipe is file-like object already switched to nonblocking.
557560
Return pair (transport, protocol), where transport support
558561
WriteTransport interface."""

Lib/asyncio/graph.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,13 @@ def capture_call_graph(
112112
optional keyword-only 'depth' argument can be used to skip the specified
113113
number of frames from top of the stack.
114114
115-
If the optional keyword-only 'limit' argument is provided, each call stack
116-
in the resulting graph is truncated to include at most ``abs(limit)``
117-
entries. If 'limit' is positive, the entries left are the closest to
118-
the invocation point. If 'limit' is negative, the topmost entries are
119-
left. If 'limit' is omitted or None, all entries are present.
120-
If 'limit' is 0, the call stack is not captured at all, only
121-
"awaited by" information is present.
115+
If the optional keyword-only 'limit' argument is provided, each call
116+
stack in the resulting graph is truncated to include at most
117+
``abs(limit)`` entries. If 'limit' is positive, the entries left are
118+
the closest to the invocation point. If 'limit' is negative, the
119+
topmost entries are left. If 'limit' is omitted or None, all entries
120+
are present. If 'limit' is 0, the call stack is not captured at all,
121+
only "awaited by" information is present.
122122
"""
123123

124124
loop = events._get_running_loop()

Lib/asyncio/locks.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,10 @@ def _wake_up_first(self):
158158
class Event(mixins._LoopBoundMixin):
159159
"""Asynchronous equivalent to threading.Event.
160160
161-
Class implementing event objects. An event manages a flag that can be set
162-
to true with the set() method and reset to false with the clear() method.
163-
The wait() method blocks until the flag is true. The flag is initially
164-
false.
161+
Class implementing event objects. An event manages a flag that can be
162+
set to true with the set() method and reset to false with the clear()
163+
method. The wait() method blocks until the flag is true. The flag is
164+
initially false.
165165
"""
166166

167167
def __init__(self):
@@ -353,9 +353,9 @@ class Semaphore(_ContextManagerMixin, mixins._LoopBoundMixin):
353353
"""A Semaphore implementation.
354354
355355
A semaphore manages an internal counter which is decremented by each
356-
acquire() call and incremented by each release() call. The counter
357-
can never go below zero; when acquire() finds that it is zero, it blocks,
358-
waiting until some other thread calls release().
356+
acquire() call and incremented by each release() call. The counter
357+
can never go below zero; when acquire() finds that it is zero, it
358+
blocks, waiting until some other thread calls release().
359359
360360
Semaphores also support the context management protocol.
361361
@@ -511,8 +511,8 @@ async def __aexit__(self, *args):
511511
async def wait(self):
512512
"""Wait for the barrier.
513513
514-
When the specified number of tasks have started waiting, they are all
515-
simultaneously awoken.
514+
When the specified number of tasks have started waiting, they are
515+
all simultaneously awoken.
516516
Returns an unique and individual index number from 0 to 'parties-1'.
517517
"""
518518
async with self._cond:

Lib/asyncio/queues.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ class QueueShutDown(Exception):
3333
class Queue(mixins._LoopBoundMixin):
3434
"""A queue, useful for coordinating producer and consumer coroutines.
3535
36-
If maxsize is less than or equal to zero, the queue size is infinite. If it
37-
is an integer greater than 0, then "await put()" will block when the
38-
queue reaches maxsize, until an item is removed by get().
36+
If maxsize is less than or equal to zero, the queue size is infinite.
37+
If it is an integer greater than 0, then "await put()" will block when
38+
the queue reaches maxsize, until an item is removed by get().
3939
4040
Unlike queue.Queue, you can reliably know this Queue's size
4141
with qsize(), since your single-threaded asyncio application won't be
@@ -174,8 +174,8 @@ async def get(self):
174174
175175
If queue is empty, wait until an item is available.
176176
177-
Raises QueueShutDown if the queue has been shut down and is empty, or
178-
if the queue has been shut down immediately.
177+
Raises QueueShutDown if the queue has been shut down and is empty,
178+
or if the queue has been shut down immediately.
179179
"""
180180
while self.empty():
181181
if self._is_shutdown and self.empty():
@@ -203,10 +203,11 @@ async def get(self):
203203
def get_nowait(self):
204204
"""Remove and return an item from the queue.
205205
206-
Return an item if one is immediately available, else raise QueueEmpty.
206+
Return an item if one is immediately available, else raise
207+
QueueEmpty.
207208
208-
Raises QueueShutDown if the queue has been shut down and is empty, or
209-
if the queue has been shut down immediately.
209+
Raises QueueShutDown if the queue has been shut down and is empty,
210+
or if the queue has been shut down immediately.
210211
"""
211212
if self.empty():
212213
if self._is_shutdown:
@@ -223,12 +224,12 @@ def task_done(self):
223224
a subsequent call to task_done() tells the queue that the processing
224225
on the task is complete.
225226
226-
If a join() is currently blocking, it will resume when all items have
227-
been processed (meaning that a task_done() call was received for every
228-
item that had been put() into the queue).
227+
If a join() is currently blocking, it will resume when all items
228+
have been processed (meaning that a task_done() call was received
229+
for every item that had been put() into the queue).
229230
230-
Raises ValueError if called more times than there were items placed in
231-
the queue.
231+
Raises ValueError if called more times than there were items placed
232+
in the queue.
232233
"""
233234
if self._unfinished_tasks <= 0:
234235
raise ValueError('task_done() called too many times')
@@ -239,10 +240,11 @@ def task_done(self):
239240
async def join(self):
240241
"""Block until all items in the queue have been gotten and processed.
241242
242-
The count of unfinished tasks goes up whenever an item is added to the
243-
queue. The count goes down whenever a consumer calls task_done() to
244-
indicate that the item was retrieved and all work on it is complete.
245-
When the count of unfinished tasks drops to zero, join() unblocks.
243+
The count of unfinished tasks goes up whenever an item is added to
244+
the queue. The count goes down whenever a consumer calls
245+
task_done() to indicate that the item was retrieved and all work on
246+
it is complete. When the count of unfinished tasks drops to zero,
247+
join() unblocks.
246248
"""
247249
if self._unfinished_tasks > 0:
248250
await self._finished.wait()

Lib/asyncio/runners.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ class Runner:
3535
with asyncio.Runner(debug=True) as runner:
3636
runner.run(main())
3737
38-
The run() method can be called multiple times within the runner's context.
38+
The run() method can be called multiple times within the runner's
39+
context.
3940
4041
This can be useful for interactive console (e.g. IPython),
4142
unittest runners, console tools, -- everywhere when async code

Lib/asyncio/selector_events.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -533,11 +533,12 @@ def _sock_recvfrom_into(self, fut, sock, buf, bufsize):
533533
async def sock_sendall(self, sock, data):
534534
"""Send data to the socket.
535535
536-
The socket must be connected to a remote socket. This method continues
537-
to send data from data until either all data has been sent or an
538-
error occurs. None is returned on success. On error, an exception is
539-
raised, and there is no way to determine how much data, if any, was
540-
successfully processed by the receiving end of the connection.
536+
The socket must be connected to a remote socket. This method
537+
continues to send data from data until either all data has been
538+
sent or an error occurs. None is returned on success. On error,
539+
an exception is raised, and there is no way to determine how much
540+
data, if any, was successfully processed by the receiving end of
541+
the connection.
541542
"""
542543
base_events._check_ssl_socket(sock)
543544
if self._debug and sock.gettimeout() != 0:
@@ -586,11 +587,12 @@ def _sock_sendall(self, fut, sock, view, pos):
586587
async def sock_sendto(self, sock, data, address):
587588
"""Send data to the socket.
588589
589-
The socket must be connected to a remote socket. This method continues
590-
to send data from data until either all data has been sent or an
591-
error occurs. None is returned on success. On error, an exception is
592-
raised, and there is no way to determine how much data, if any, was
593-
successfully processed by the receiving end of the connection.
590+
The socket must be connected to a remote socket. This method
591+
continues to send data from data until either all data has been
592+
sent or an error occurs. None is returned on success. On error,
593+
an exception is raised, and there is no way to determine how much
594+
data, if any, was successfully processed by the receiving end of
595+
the connection.
594596
"""
595597
base_events._check_ssl_socket(sock)
596598
if self._debug and sock.gettimeout() != 0:
@@ -701,10 +703,11 @@ def _sock_connect_cb(self, fut, sock, address):
701703
async def sock_accept(self, sock):
702704
"""Accept a connection.
703705
704-
The socket must be bound to an address and listening for connections.
705-
The return value is a pair (conn, address) where conn is a new socket
706-
object usable to send and receive data on the connection, and address
707-
is the address bound to the socket on the other end of the connection.
706+
The socket must be bound to an address and listening for
707+
connections. The return value is a pair (conn, address) where
708+
conn is a new socket object usable to send and receive data on the
709+
connection, and address is the address bound to the socket on the
710+
other end of the connection.
708711
"""
709712
base_events._check_ssl_socket(sock)
710713
if self._debug and sock.gettimeout() != 0:

Lib/asyncio/streams.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -539,17 +539,17 @@ async def _wait_for_data(self, func_name):
539539
self._waiter = None
540540

541541
async def readline(self):
542-
"""Read chunk of data from the stream until newline (b'\n') is found.
542+
r"""Read chunk of data from the stream until newline (b'\n') is found.
543543
544-
On success, return chunk that ends with newline. If only partial
544+
On success, return chunk that ends with newline. If only partial
545545
line can be read due to EOF, return incomplete line without
546-
terminating newline. When EOF was reached while no bytes read, empty
547-
bytes object is returned.
546+
terminating newline. When EOF was reached while no bytes read,
547+
empty bytes object is returned.
548548
549-
If limit is reached, ValueError will be raised. In that case, if
549+
If limit is reached, ValueError will be raised. In that case, if
550550
newline was found, complete line including newline will be removed
551-
from internal buffer. Else, internal buffer will be cleared. Limit is
552-
compared against part of the line without newline.
551+
from internal buffer. Else, internal buffer will be cleared.
552+
Limit is compared against part of the line without newline.
553553
554554
If stream was paused, this function will automatically resume it if
555555
needed.

Lib/asyncio/taskgroups.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -289,14 +289,14 @@ def cancel(self):
289289
"""Cancel the task group
290290
291291
`cancel()` will be called on any tasks in the group that aren't yet
292-
done, as well as the parent (body) of the group. This will cause the
293-
task group context manager to exit *without* `asyncio.CancelledError`
294-
being raised.
295-
296-
If `cancel()` is called before entering the task group, the group will be
297-
cancelled upon entry. This is useful for patterns where one piece of
298-
code passes an unused TaskGroup instance to another in order to have
299-
the ability to cancel anything run within the group.
292+
done, as well as the parent (body) of the group. This will cause
293+
the task group context manager to exit *without*
294+
`asyncio.CancelledError` being raised.
295+
296+
If `cancel()` is called before entering the task group, the group
297+
will be cancelled upon entry. This is useful for patterns where
298+
one piece of code passes an unused TaskGroup instance to another in
299+
order to have the ability to cancel anything run within the group.
300300
301301
`cancel()` is idempotent and may be called after the task group has
302302
already exited.

0 commit comments

Comments
 (0)