Skip to content

Commit c292331

Browse files
authored
Merge branch 'main' into posixsubprocess-no-callsetxid
2 parents 1b3250e + 934b25d commit c292331

File tree

192 files changed

+4505
-3052
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

192 files changed

+4505
-3052
lines changed

Doc/c-api/datetime.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,15 @@ Macros to create objects:
132132
resulting number of microseconds and seconds lie in the ranges documented for
133133
:class:`datetime.timedelta` objects.
134134
135+
135136
.. c:function:: PyObject* PyTimeZone_FromOffset(PyDateTime_DeltaType* offset)
136137
137138
Return a :class:`datetime.timezone` object with an unnamed fixed offset
138139
represented by the *offset* argument.
139140
140141
.. versionadded:: 3.7
141142
143+
142144
.. c:function:: PyObject* PyTimeZone_FromOffsetAndName(PyDateTime_DeltaType* offset, PyUnicode* name)
143145
144146
Return a :class:`datetime.timezone` object with a fixed offset represented
@@ -190,12 +192,21 @@ must not be ``NULL``, and the type is not checked:
190192
191193
Return the microsecond, as an int from 0 through 999999.
192194
195+
196+
.. c:function:: int PyDateTime_DATE_GET_FOLD(PyDateTime_DateTime *o)
197+
198+
Return the fold, as an int from 0 through 1.
199+
200+
.. versionadded:: 3.6
201+
202+
193203
.. c:function:: PyObject* PyDateTime_DATE_GET_TZINFO(PyDateTime_DateTime *o)
194204
195205
Return the tzinfo (which may be ``None``).
196206
197207
.. versionadded:: 3.10
198208
209+
199210
Macros to extract fields from time objects. The argument must be an instance of
200211
:c:data:`PyDateTime_Time`, including subclasses. The argument must not be ``NULL``,
201212
and the type is not checked:
@@ -219,6 +230,14 @@ and the type is not checked:
219230
220231
Return the microsecond, as an int from 0 through 999999.
221232
233+
234+
.. c:function:: int PyDateTime_TIME_GET_FOLD(PyDateTime_Time *o)
235+
236+
Return the fold, as an int from 0 through 1.
237+
238+
.. versionadded:: 3.6
239+
240+
222241
.. c:function:: PyObject* PyDateTime_TIME_GET_TZINFO(PyDateTime_Time *o)
223242
224243
Return the tzinfo (which may be ``None``).

Doc/howto/logging-cookbook.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ messages should not. Here's how you can achieve this::
219219
logging.basicConfig(level=logging.DEBUG,
220220
format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
221221
datefmt='%m-%d %H:%M',
222-
filename='/temp/myapp.log',
222+
filename='/tmp/myapp.log',
223223
filemode='w')
224224
# define a Handler which writes INFO messages or higher to the sys.stderr
225225
console = logging.StreamHandler()
@@ -270,6 +270,11 @@ are sent to both destinations.
270270
This example uses console and file handlers, but you can use any number and
271271
combination of handlers you choose.
272272

273+
Note that the above choice of log filename ``/tmp/myapp.log`` implies use of a
274+
standard location for temporary files on POSIX systems. On Windows, you may need to
275+
choose a different directory name for the log - just ensure that the directory exists
276+
and that you have the permissions to create and update files in it.
277+
273278

274279
Configuration server example
275280
----------------------------

Doc/includes/sqlite3/pysqlite_datetime.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

Doc/library/2to3.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.. _2to3-reference:
22

3-
2to3 - Automated Python 2 to 3 code translation
4-
===============================================
3+
2to3 --- Automated Python 2 to 3 code translation
4+
=================================================
55

66
.. sectionauthor:: Benjamin Peterson <[email protected]>
77

@@ -456,8 +456,8 @@ and off individually. They are described here in more detail.
456456
``from future_builtins import zip`` appears.
457457
458458
459-
:mod:`lib2to3` - 2to3's library
460-
-------------------------------
459+
:mod:`lib2to3` --- 2to3's library
460+
---------------------------------
461461

462462
.. module:: lib2to3
463463
:synopsis: The 2to3 library

Doc/library/ast.rst

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Node classes
4545

4646
This is the base of all AST node classes. The actual node classes are
4747
derived from the :file:`Parser/Python.asdl` file, which is reproduced
48-
:ref:`below <abstract-grammar>`. They are defined in the :mod:`_ast` C
48+
:ref:`above <abstract-grammar>`. They are defined in the :mod:`_ast` C
4949
module and re-exported in :mod:`ast`.
5050

5151
There is one class defined for each left-hand side symbol in the abstract
@@ -1028,10 +1028,11 @@ Control flow
10281028
.. class:: For(target, iter, body, orelse, type_comment)
10291029

10301030
A ``for`` loop. ``target`` holds the variable(s) the loop assigns to, as a
1031-
single :class:`Name`, :class:`Tuple` or :class:`List` node. ``iter`` holds
1032-
the item to be looped over, again as a single node. ``body`` and ``orelse``
1033-
contain lists of nodes to execute. Those in ``orelse`` are executed if the
1034-
loop finishes normally, rather than via a ``break`` statement.
1031+
single :class:`Name`, :class:`Tuple`, :class:`List`, :class:`Attribute` or
1032+
:class:`Subscript` node. ``iter`` holds the item to be looped over, again
1033+
as a single node. ``body`` and ``orelse`` contain lists of nodes to execute.
1034+
Those in ``orelse`` are executed if the loop finishes normally, rather than
1035+
via a ``break`` statement.
10351036

10361037
.. attribute:: type_comment
10371038

@@ -1950,7 +1951,7 @@ and classes for traversing abstract syntax trees:
19501951

19511952
If source contains a null character ('\0'), :exc:`ValueError` is raised.
19521953

1953-
.. warning::
1954+
.. warning::
19541955
Note that successfully parsing source code into an AST object doesn't
19551956
guarantee that the source code provided is valid Python code that can
19561957
be executed as the compilation step can raise further :exc:`SyntaxError`

Doc/library/asyncio-task.rst

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,24 @@ Creating Tasks
282282
Added the *context* parameter.
283283

284284

285+
Task Cancellation
286+
=================
287+
288+
Tasks can easily and safely be cancelled.
289+
When a task is cancelled, :exc:`asyncio.CancelledError` will be raised
290+
in the task at the next opportunity.
291+
292+
It is recommended that coroutines use ``try/finally`` blocks to robustly
293+
perform clean-up logic. In case :exc:`asyncio.CancelledError`
294+
is explicitly caught, it should generally be propagated when
295+
clean-up is complete. Most code can safely ignore :exc:`asyncio.CancelledError`.
296+
297+
Important asyncio components, like :class:`asyncio.TaskGroup` and the
298+
:func:`asyncio.timeout` context manager, are implemented using cancellation
299+
internally and might misbehave if a coroutine swallows
300+
:exc:`asyncio.CancelledError`.
301+
302+
285303
Task Groups
286304
===========
287305

@@ -537,6 +555,122 @@ Shielding From Cancellation
537555
Timeouts
538556
========
539557

558+
.. coroutinefunction:: timeout(delay)
559+
560+
An :ref:`asynchronous context manager <async-context-managers>`
561+
that can be used to limit the amount of time spent waiting on
562+
something.
563+
564+
*delay* can either be ``None``, or a float/int number of
565+
seconds to wait. If *delay* is ``None``, no time limit will
566+
be applied; this can be useful if the delay is unknown when
567+
the context manager is created.
568+
569+
In either case, the context manager can be rescheduled after
570+
creation using :meth:`Timeout.reschedule`.
571+
572+
Example::
573+
574+
async def main():
575+
async with asyncio.timeout(10):
576+
await long_running_task()
577+
578+
If ``long_running_task`` takes more than 10 seconds to complete,
579+
the context manager will cancel the current task and handle
580+
the resulting :exc:`asyncio.CancelledError` internally, transforming it
581+
into an :exc:`asyncio.TimeoutError` which can be caught and handled.
582+
583+
.. note::
584+
585+
The :func:`asyncio.timeout` context manager is what transforms
586+
the :exc:`asyncio.CancelledError` into an :exc:`asyncio.TimeoutError`,
587+
which means the :exc:`asyncio.TimeoutError` can only be caught
588+
*outside* of the context manager.
589+
590+
Example of catching :exc:`asyncio.TimeoutError`::
591+
592+
async def main():
593+
try:
594+
async with asyncio.timeout(10):
595+
await long_running_task()
596+
except TimeoutError:
597+
print("The long operation timed out, but we've handled it.")
598+
599+
print("This statement will run regardless.")
600+
601+
The context manager produced by :func:`asyncio.timeout` can be
602+
rescheduled to a different deadline and inspected.
603+
604+
.. class:: Timeout()
605+
606+
An :ref:`asynchronous context manager <async-context-managers>`
607+
that limits time spent inside of it.
608+
609+
.. versionadded:: 3.11
610+
611+
.. method:: when() -> float | None
612+
613+
Return the current deadline, or ``None`` if the current
614+
deadline is not set.
615+
616+
The deadline is a float, consistent with the time returned by
617+
:meth:`loop.time`.
618+
619+
.. method:: reschedule(when: float | None)
620+
621+
Change the time the timeout will trigger.
622+
623+
If *when* is `None`, any current deadline will be removed, and the
624+
context manager will wait indefinitely.
625+
626+
If *when* is a float, it is set as the new deadline.
627+
628+
.. method:: expired() -> bool
629+
630+
Return whether the context manager has exceeded its deadline
631+
(expired).
632+
633+
Example::
634+
635+
async def main():
636+
try:
637+
# We do not know the timeout when starting, so we pass ``None``.
638+
async with asyncio.timeout(None) as cm:
639+
# We know the timeout now, so we reschedule it.
640+
new_deadline = get_running_loop().time() + 10
641+
cm.reschedule(new_deadline)
642+
643+
await long_running_task()
644+
except TimeoutError:
645+
pass
646+
647+
if cm.expired:
648+
print("Looks like we haven't finished on time.")
649+
650+
Timeout context managers can be safely nested.
651+
652+
.. versionadded:: 3.11
653+
654+
.. coroutinefunction:: timeout_at(when)
655+
656+
Similar to :func:`asyncio.timeout`, except *when* is the absolute time
657+
to stop waiting, or ``None``.
658+
659+
Example::
660+
661+
async def main():
662+
loop = get_running_loop()
663+
deadline = loop.time() + 20
664+
try:
665+
async with asyncio.timeout_at(deadline):
666+
await long_running_task()
667+
except TimeoutError:
668+
print("The long operation timed out, but we've handled it.")
669+
670+
print("This statement will run regardless.")
671+
672+
.. versionadded:: 3.11
673+
540674
.. coroutinefunction:: wait_for(aw, timeout)
541675

542676
Wait for the *aw* :ref:`awaitable <asyncio-awaitables>`

Doc/library/datetime.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,8 +1370,8 @@ Instance methods:
13701370
time and this method relies on the platform C :c:func:`mktime`
13711371
function to perform the conversion. Since :class:`.datetime`
13721372
supports wider range of values than :c:func:`mktime` on many
1373-
platforms, this method may raise :exc:`OverflowError` for times far
1374-
in the past or far in the future.
1373+
platforms, this method may raise :exc:`OverflowError` or :exc:`OSError`
1374+
for times far in the past or far in the future.
13751375

13761376
For aware :class:`.datetime` instances, the return value is computed
13771377
as::

Doc/library/dis.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -604,12 +604,6 @@ iterations of the loop.
604604
.. versionchanged:: 3.11
605605
oparg set to be the stack depth, for efficient handling on frames.
606606

607-
.. opcode:: YIELD_FROM
608-
609-
Pops TOS and delegates to it as a subiterator from a :term:`generator`.
610-
611-
.. versionadded:: 3.3
612-
613607

614608
.. opcode:: SETUP_ANNOTATIONS
615609

Doc/library/logging.handlers.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,8 @@ possible, while any potentially slow operations (such as sending an email via
10181018
have the task tracking API, which means that you can use
10191019
:class:`~queue.SimpleQueue` instances for *queue*.
10201020

1021+
.. note:: If you are using :mod:`multiprocessing`, you should avoid using
1022+
:class:`~queue.SimpleQueue` and instead use :class:`multiprocessing.Queue`.
10211023

10221024
.. method:: emit(record)
10231025

@@ -1091,6 +1093,9 @@ possible, while any potentially slow operations (such as sending an email via
10911093
task tracking API (though it's used if available), which means that you can
10921094
use :class:`~queue.SimpleQueue` instances for *queue*.
10931095

1096+
.. note:: If you are using :mod:`multiprocessing`, you should avoid using
1097+
:class:`~queue.SimpleQueue` and instead use :class:`multiprocessing.Queue`.
1098+
10941099
If ``respect_handler_level`` is ``True``, a handler's level is respected
10951100
(compared with the level for the message) when deciding whether to pass
10961101
messages to that handler; otherwise, the behaviour is as in previous Python

0 commit comments

Comments
 (0)