Skip to content

Commit 4cf3154

Browse files
authored
Merge branch '3.13' into backport-a10152f-3.13
2 parents 3ce0e1c + df34903 commit 4cf3154

Some content is hidden

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

50 files changed

+1252
-550
lines changed

Doc/c-api/veryhigh.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ the same library that the Python runtime is using.
183183
objects *globals* and *locals* with the compiler flags specified by
184184
*flags*. *globals* must be a dictionary; *locals* can be any object
185185
that implements the mapping protocol. The parameter *start* specifies
186-
the start token that should be used to parse the source code.
186+
the start symbol and must one of the following:
187+
:c:data:`Py_eval_input`, :c:data:`Py_file_input`, or :c:data:`Py_single_input`.
187188
188189
Returns the result of executing the code as a Python object, or ``NULL`` if an
189190
exception was raised.
@@ -231,7 +232,7 @@ the same library that the Python runtime is using.
231232
.. c:function:: PyObject* Py_CompileStringObject(const char *str, PyObject *filename, int start, PyCompilerFlags *flags, int optimize)
232233
233234
Parse and compile the Python source code in *str*, returning the resulting code
234-
object. The start token is given by *start*; this can be used to constrain the
235+
object. The start symbol is given by *start*; this can be used to constrain the
235236
code which can be compiled and should be :c:data:`Py_eval_input`,
236237
:c:data:`Py_file_input`, or :c:data:`Py_single_input`. The filename specified by
237238
*filename* is used to construct the code object and may appear in tracebacks or

Doc/library/argparse.rst

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -687,16 +687,16 @@ how the command-line arguments should be handled. The supplied actions are:
687687
>>> parser.parse_args('--foo --bar'.split())
688688
Namespace(foo=True, bar=False, baz=True)
689689

690-
* ``'append'`` - This stores a list, and appends each argument value to the
691-
list. It is useful to allow an option to be specified multiple times.
692-
If the default value is non-empty, the default elements will be present
693-
in the parsed value for the option, with any values from the
694-
command line appended after those default values. Example usage::
690+
* ``'append'`` - This appends each argument value to a list.
691+
It is useful for allowing an option to be specified multiple times.
692+
If the default value is a non-empty list, the parsed value will start
693+
with the default list's elements and any values from the command line
694+
will be appended after those default values. Example usage::
695695

696696
>>> parser = argparse.ArgumentParser()
697-
>>> parser.add_argument('--foo', action='append')
697+
>>> parser.add_argument('--foo', action='append', default=['0'])
698698
>>> parser.parse_args('--foo 1 --foo 2'.split())
699-
Namespace(foo=['1', '2'])
699+
Namespace(foo=['0', '1', '2'])
700700

701701
* ``'append_const'`` - This stores a list, and appends the value specified by
702702
the const_ keyword argument to the list; note that the const_ keyword
@@ -896,8 +896,8 @@ the various :class:`ArgumentParser` actions. The two most common uses of it are
896896
(like ``-f`` or ``--foo``) and ``nargs='?'``. This creates an optional
897897
argument that can be followed by zero or one command-line arguments.
898898
When parsing the command line, if the option string is encountered with no
899-
command-line argument following it, the value of ``const`` will be assumed to
900-
be ``None`` instead. See the nargs_ description for examples.
899+
command-line argument following it, the value from ``const`` will be used.
900+
See the nargs_ description for examples.
901901

902902
.. versionchanged:: 3.11
903903
``const=None`` by default, including when ``action='append_const'`` or
@@ -1058,16 +1058,21 @@ if the argument was not one of the acceptable values::
10581058
game.py: error: argument move: invalid choice: 'fire' (choose from 'rock',
10591059
'paper', 'scissors')
10601060

1061-
Note that inclusion in the *choices* sequence is checked after any type_
1062-
conversions have been performed, so the type of the objects in the *choices*
1063-
sequence should match the type_ specified.
1064-
10651061
Any sequence can be passed as the *choices* value, so :class:`list` objects,
10661062
:class:`tuple` objects, and custom sequences are all supported.
10671063

10681064
Use of :class:`enum.Enum` is not recommended because it is difficult to
10691065
control its appearance in usage, help, and error messages.
10701066

1067+
Note that *choices* are checked after any type_
1068+
conversions have been performed, so objects in *choices*
1069+
should match the type_ specified. This can make *choices*
1070+
appear unfamiliar in usage, help, or error messages.
1071+
1072+
To keep *choices* user-friendly, consider a custom type wrapper that
1073+
converts and formats values, or omit type_ and handle conversion in
1074+
your application code.
1075+
10711076
Formatted choices override the default *metavar* which is normally derived
10721077
from *dest*. This is usually what you want because the user never sees the
10731078
*dest* parameter. If this display isn't desirable (perhaps because there are

Doc/library/html.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ This module defines utilities to manipulate HTML.
1414

1515
Convert the characters ``&``, ``<`` and ``>`` in string *s* to HTML-safe
1616
sequences. Use this if you need to display text that might contain such
17-
characters in HTML. If the optional flag *quote* is true, the characters
18-
(``"``) and (``'``) are also translated; this helps for inclusion in an HTML
19-
attribute value delimited by quotes, as in ``<a href="...">``.
17+
characters in HTML. If the optional flag *quote* is true (the default), the
18+
characters (``"``) and (``'``) are also translated; this helps for inclusion
19+
in an HTML attribute value delimited by quotes, as in ``<a href="...">``.
20+
If *quote* is set to false, the characters (``"``) and (``'``) are not
21+
translated.
22+
2023

2124
.. versionadded:: 3.2
2225

Doc/library/inspect.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
222222
+-----------------+-------------------+---------------------------+
223223
| | gi_running | is the generator running? |
224224
+-----------------+-------------------+---------------------------+
225+
| | gi_suspended | is the generator |
226+
| | | suspended? |
227+
+-----------------+-------------------+---------------------------+
225228
| | gi_code | code |
226229
+-----------------+-------------------+---------------------------+
227230
| | gi_yieldfrom | object being iterated by |

Doc/library/platform.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ Cross platform
5656
Returns the machine type, e.g. ``'AMD64'``. An empty string is returned if the
5757
value cannot be determined.
5858

59+
The output is platform-dependent and may differ in casing and naming conventions.
60+
5961

6062
.. function:: node()
6163

Doc/library/sqlite3.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ Connection objects
632632
supplied, this must be a :term:`callable` returning
633633
an instance of :class:`Cursor` or its subclasses.
634634

635-
.. method:: blobopen(table, column, row, /, *, readonly=False, name="main")
635+
.. method:: blobopen(table, column, rowid, /, *, readonly=False, name="main")
636636

637637
Open a :class:`Blob` handle to an existing
638638
:abbr:`BLOB (Binary Large OBject)`.
@@ -643,8 +643,8 @@ Connection objects
643643
:param str column:
644644
The name of the column where the blob is located.
645645

646-
:param str row:
647-
The name of the row where the blob is located.
646+
:param int rowid:
647+
The row id where the blob is located.
648648

649649
:param bool readonly:
650650
Set to ``True`` if the blob should be opened without write

Doc/library/sysconfig.rst

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -382,22 +382,19 @@ Other functions
382382

383383
Examples of returned values:
384384

385-
- linux-i586
386-
- linux-alpha (?)
387-
- solaris-2.6-sun4u
388385

389-
Windows will return one of:
386+
Windows:
390387

391388
- win-amd64 (64-bit Windows on AMD64, aka x86_64, Intel64, and EM64T)
392389
- win-arm64 (64-bit Windows on ARM64, aka AArch64)
393390
- win32 (all others - specifically, sys.platform is returned)
394391

395-
macOS can return:
392+
POSIX based OS:
396393

397-
- macosx-10.6-ppc
398-
- macosx-10.4-ppc64
399-
- macosx-10.3-i386
400-
- macosx-10.4-fat
394+
- linux-x86_64
395+
- macosx-15.5-arm64
396+
- macosx-26.0-universal2 (macOS on Apple Silicon or Intel)
397+
- android-24-arm64_v8a
401398

402399
For other non-POSIX platforms, currently just returns :data:`sys.platform`.
403400

Doc/reference/compound_stmts.rst

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -332,15 +332,29 @@ stored in the :mod:`sys` module is reset to its previous value::
332332
:keyword:`!except*` clause
333333
--------------------------
334334

335-
The :keyword:`!except*` clause(s) are used for handling
336-
:exc:`ExceptionGroup`\s. The exception type for matching is interpreted as in
337-
the case of :keyword:`except`, but in the case of exception groups we can have
338-
partial matches when the type matches some of the exceptions in the group.
339-
This means that multiple :keyword:`!except*` clauses can execute,
340-
each handling part of the exception group.
341-
Each clause executes at most once and handles an exception group
342-
of all matching exceptions. Each exception in the group is handled by at most
343-
one :keyword:`!except*` clause, the first that matches it. ::
335+
The :keyword:`!except*` clause(s) specify one or more handlers for groups of
336+
exceptions (:exc:`BaseExceptionGroup` instances). A :keyword:`try` statement
337+
can have either :keyword:`except` or :keyword:`!except*` clauses, but not both.
338+
The exception type for matching is mandatory in the case of :keyword:`!except*`,
339+
so ``except*:`` is a syntax error. The type is interpreted as in the case of
340+
:keyword:`!except`, but matching is performed on the exceptions contained in the
341+
group that is being handled. An :exc:`TypeError` is raised if a matching
342+
type is a subclass of :exc:`!BaseExceptionGroup`, because that would have
343+
ambiguous semantics.
344+
345+
When an exception group is raised in the try block, each :keyword:`!except*`
346+
clause splits (see :meth:`~BaseExceptionGroup.split`) it into the subgroups
347+
of matching and non-matching exceptions. If the matching subgroup is not empty,
348+
it becomes the handled exception (the value returned from :func:`sys.exception`)
349+
and assigned to the target of the :keyword:`!except*` clause (if there is one).
350+
Then, the body of the :keyword:`!except*` clause executes. If the non-matching
351+
subgroup is not empty, it is processed by the next :keyword:`!except*` in the
352+
same manner. This continues until all exceptions in the group have been matched,
353+
or the last :keyword:`!except*` clause has run.
354+
355+
After all :keyword:`!except*` clauses execute, the group of unhandled exceptions
356+
is merged with any exceptions that were raised or re-raised from within
357+
:keyword:`!except*` clauses. This merged exception group propagates on.::
344358

345359
>>> try:
346360
... raise ExceptionGroup("eg",
@@ -353,22 +367,18 @@ one :keyword:`!except*` clause, the first that matches it. ::
353367
caught <class 'ExceptionGroup'> with nested (TypeError(2),)
354368
caught <class 'ExceptionGroup'> with nested (OSError(3), OSError(4))
355369
+ Exception Group Traceback (most recent call last):
356-
| File "<stdin>", line 2, in <module>
357-
| ExceptionGroup: eg
370+
| File "<doctest default[0]>", line 2, in <module>
371+
| raise ExceptionGroup("eg",
372+
| [ValueError(1), TypeError(2), OSError(3), OSError(4)])
373+
| ExceptionGroup: eg (1 sub-exception)
358374
+-+---------------- 1 ----------------
359375
| ValueError: 1
360376
+------------------------------------
361377

362-
363-
Any remaining exceptions that were not handled by any :keyword:`!except*`
364-
clause are re-raised at the end, along with all exceptions that were
365-
raised from within the :keyword:`!except*` clauses. If this list contains
366-
more than one exception to reraise, they are combined into an exception
367-
group.
368-
369-
If the raised exception is not an exception group and its type matches
370-
one of the :keyword:`!except*` clauses, it is caught and wrapped by an
371-
exception group with an empty message string. ::
378+
If the exception raised from the :keyword:`try` block is not an exception group
379+
and its type matches one of the :keyword:`!except*` clauses, it is caught and
380+
wrapped by an exception group with an empty message string. This ensures that the
381+
type of the target ``e`` is consistently :exc:`BaseExceptionGroup`::
372382

373383
>>> try:
374384
... raise BlockingIOError
@@ -377,13 +387,7 @@ exception group with an empty message string. ::
377387
...
378388
ExceptionGroup('', (BlockingIOError()))
379389

380-
An :keyword:`!except*` clause must have a matching expression; it cannot be ``except*:``.
381-
Furthermore, this expression cannot contain exception group types, because that would
382-
have ambiguous semantics.
383-
384-
It is not possible to mix :keyword:`except` and :keyword:`!except*`
385-
in the same :keyword:`try`.
386-
The :keyword:`break`, :keyword:`continue`, and :keyword:`return` statements
390+
:keyword:`break`, :keyword:`continue` and :keyword:`return`
387391
cannot appear in an :keyword:`!except*` clause.
388392

389393

Doc/reference/simple_stmts.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,8 @@ Deletion of a target list recursively deletes each target, from left to right.
463463

464464
Deletion of a name removes the binding of that name from the local or global
465465
namespace, depending on whether the name occurs in a :keyword:`global` statement
466-
in the same code block. If the name is unbound, a :exc:`NameError` exception
467-
will be raised.
466+
in the same code block. Trying to delete an unbound name raises a
467+
:exc:`NameError` exception.
468468

469469
.. index:: pair: attribute; deletion
470470

Include/pymath.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,24 @@
5454

5555
/* Py_NAN: Value that evaluates to a quiet Not-a-Number (NaN). The sign is
5656
* undefined and normally not relevant, but e.g. fixed for float("nan").
57+
*
58+
* Note: On Solaris, NAN is a function address, hence arithmetic is impossible.
59+
* For that reason, we instead use the built-in call if available or fallback
60+
* to a generic NaN computed from strtod() as a last resort.
61+
*
62+
* See https://github.com/python/cpython/issues/136006 for details.
5763
*/
5864
#if !defined(Py_NAN)
59-
# define Py_NAN ((double)NAN)
65+
# if defined(__sun)
66+
# if _Py__has_builtin(__builtin_nanf)
67+
# define Py_NAN ((double)__builtin_nanf(""))
68+
# else
69+
# include <stdlib.h>
70+
# define Py_NAN (strtod("NAN", NULL))
71+
# endif
72+
# else
73+
# define Py_NAN ((double)NAN)
74+
# endif
6075
#endif
6176

6277
#endif /* Py_PYMATH_H */

0 commit comments

Comments
 (0)