Skip to content

Commit b71b124

Browse files
committed
Merge branch 'main' into bpo_44133
* main: (21 commits) bpo-45876: Have stdev() also use decimal specific square root. (pythonGH-29869) bpo-45876: Correctly rounded stdev() and pstdev() for the Decimal case (pythonGH-29828) bpo-45711: Change exc_info related APIs to derive type and traceback from the exception instance (pythonGH-29780) bpo-30533:Add function inspect.getmembers_static that does not call properties or dynamic properties. (python#20911) bpo-45476: Disallow using asdl_seq_GET() as l-value (pythonGH-29866) bpo-45476: Add _Py_RVALUE() macro (pythonGH-29860) bpo-33381: [doc] strftime's %f option may pad zeros on the left or the right (pythonGH-29801) Fix EncodingWarning in Tools/freeze/test/freeze.py (pythonGH-29742) no-issue: remove unused import from test_graphlib.py (pythonGH-29853) bpo-45931: Prevent Directory.Build.props/targets from leaking from directories above the repo when building on Windows (pythonGH-29854) bpo-45653: fix test_embed on windows (pythonGH-29814) bpo-45917: Add math.exp2() method - return 2 raised to the power of x (pythonGH-29829) bpo-43905: Expand dataclasses.astuple() and asdict() docs (pythonGH-26154) bpo-44391: Remove unused argument from a varargs call. (pythonGH-29843) bpo-45881: configure --with-freeze-module --with-build-python (pythonGH-29835) bpo-45847: PY_STDLIB_MOD_SIMPLE now checks py_stdlib_not_available (pythonGH-29844) bpo-45828: Use unraisable exceptions within sqlite3 callbacks (FH-29591) bpo-40280: Emscripten systems use .wasm suffix by default (pythonGH-29842) bpo-45723: Sort the grand AC_CHECK_HEADERS check (pythonGH-29846) bpo-45847: Make socket module conditional (pythonGH-29769) ...
2 parents 0230c8b + 0aa0bd0 commit b71b124

Some content is hidden

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

48 files changed

+1589
-428
lines changed

Doc/c-api/exceptions.rst

+6-1
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,6 @@ Querying the error indicator
482482
to an exception that was *already caught*, not to an exception that was
483483
freshly raised. This function steals the references of the arguments.
484484
To clear the exception state, pass ``NULL`` for all three arguments.
485-
For general rules about the three arguments, see :c:func:`PyErr_Restore`.
486485
487486
.. note::
488487
@@ -493,6 +492,12 @@ Querying the error indicator
493492
494493
.. versionadded:: 3.3
495494
495+
.. versionchanged:: 3.11
496+
The ``type`` and ``traceback`` arguments are no longer used and
497+
can be NULL. The interpreter now derives them from the exception
498+
instance (the ``value`` argument). The function still steals
499+
references of all three arguments.
500+
496501
497502
Signal Handling
498503
===============

Doc/howto/logging-cookbook.rst

+22
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,17 @@ alternative there, as well as adapting the above script to use your alternative
541541
serialization.
542542

543543

544+
Running a logging socket listener in production
545+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
546+
547+
To run a logging listener in production, you may need to use a process-management tool
548+
such as `Supervisor <http://supervisord.org/>`_. `Here
549+
<https://gist.github.com/vsajip/4b227eeec43817465ca835ca66f75e2b>`_ is a Gist which
550+
provides the bare-bones files to run the above functionality using Supervisor: you
551+
will need to change the `/path/to/` parts in the Gist to reflect the actual paths you
552+
want to use.
553+
554+
544555
.. _context-info:
545556

546557
Adding contextual information to your logging output
@@ -982,6 +993,17 @@ to this (remembering to first import :mod:`concurrent.futures`)::
982993
for i in range(10):
983994
executor.submit(worker_process, queue, worker_configurer)
984995

996+
Deploying Web applications using Gunicorn and uWSGI
997+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
998+
999+
When deploying Web applications using `Gunicorn <https://gunicorn.org/>`_ or `uWSGI
1000+
<https://uwsgi-docs.readthedocs.io/en/latest/>`_ (or similar), multiple worker
1001+
processes are created to handle client requests. In such environments, avoid creating
1002+
file-based handlers directly in your web application. Instead, use a
1003+
:class:`SocketHandler` to log from the web application to a listener in a separate
1004+
process. This can be set up using a process management tool such as Supervisor - see
1005+
`Running a logging socket listener in production`_ for more details.
1006+
9851007

9861008
Using file rotation
9871009
-------------------

Doc/library/dataclasses.rst

+18-4
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,10 @@ Module contents
324324
Converts the dataclass ``instance`` to a dict (by using the
325325
factory function ``dict_factory``). Each dataclass is converted
326326
to a dict of its fields, as ``name: value`` pairs. dataclasses, dicts,
327-
lists, and tuples are recursed into. For example::
327+
lists, and tuples are recursed into. Other objects are copied with
328+
:func:`copy.deepcopy`.
329+
330+
Example of using :func:`asdict` on nested dataclasses::
328331

329332
@dataclass
330333
class Point:
@@ -341,21 +344,32 @@ Module contents
341344
c = C([Point(0, 0), Point(10, 4)])
342345
assert asdict(c) == {'mylist': [{'x': 0, 'y': 0}, {'x': 10, 'y': 4}]}
343346

344-
Raises :exc:`TypeError` if ``instance`` is not a dataclass instance.
347+
To create a shallow copy, the following workaround may be used::
348+
349+
dict((field.name, getattr(instance, field.name)) for field in fields(instance))
350+
351+
:func:`asdict` raises :exc:`TypeError` if ``instance`` is not a dataclass
352+
instance.
345353

346354
.. function:: astuple(instance, *, tuple_factory=tuple)
347355

348356
Converts the dataclass ``instance`` to a tuple (by using the
349357
factory function ``tuple_factory``). Each dataclass is converted
350358
to a tuple of its field values. dataclasses, dicts, lists, and
351-
tuples are recursed into.
359+
tuples are recursed into. Other objects are copied with
360+
:func:`copy.deepcopy`.
352361

353362
Continuing from the previous example::
354363

355364
assert astuple(p) == (10, 20)
356365
assert astuple(c) == ([(0, 0), (10, 4)],)
357366

358-
Raises :exc:`TypeError` if ``instance`` is not a dataclass instance.
367+
To create a shallow copy, the following workaround may be used::
368+
369+
tuple(getattr(instance, field.name) for field in dataclasses.fields(instance))
370+
371+
:func:`astuple` raises :exc:`TypeError` if ``instance`` is not a dataclass
372+
instance.
359373

360374
.. function:: make_dataclass(cls_name, fields, *, bases=(), namespace=None, init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False, match_args=True, kw_only=False, slots=False)
361375

Doc/library/datetime.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -2359,8 +2359,8 @@ requires, and these work on all platforms with a standard C implementation.
23592359
| | decimal number. | | \(9) |
23602360
+-----------+--------------------------------+------------------------+-------+
23612361
| ``%f`` | Microsecond as a decimal | 000000, 000001, ..., | \(5) |
2362-
| | number, zero-padded on the | 999999 | |
2363-
| | left. | | |
2362+
| | number, zero-padded to 6 | 999999 | |
2363+
| | digits. | | |
23642364
+-----------+--------------------------------+------------------------+-------+
23652365
| ``%z`` | UTC offset in the form | (empty), +0000, | \(6) |
23662366
| | ``±HHMM[SS[.ffffff]]`` (empty | -0400, +1030, | |

Doc/library/math.rst

+7
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,13 @@ Power and logarithmic functions
356356
or ``pow(math.e, x)``.
357357

358358

359+
.. function:: exp2(x)
360+
361+
Return *2* raised to the power *x*.
362+
363+
.. versionadded:: 3.11
364+
365+
359366
.. function:: expm1(x)
360367

361368
Return *e* raised to the power *x*, minus 1. Here *e* is the base of natural

Doc/library/sqlite3.rst

+21-3
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,27 @@ Module functions and constants
329329

330330
By default you will not get any tracebacks in user-defined functions,
331331
aggregates, converters, authorizer callbacks etc. If you want to debug them,
332-
you can call this function with *flag* set to ``True``. Afterwards, you will
333-
get tracebacks from callbacks on ``sys.stderr``. Use :const:`False` to
334-
disable the feature again.
332+
you can call this function with *flag* set to :const:`True`. Afterwards, you
333+
will get tracebacks from callbacks on :data:`sys.stderr`. Use :const:`False`
334+
to disable the feature again.
335+
336+
Register an :func:`unraisable hook handler <sys.unraisablehook>` for an
337+
improved debug experience::
338+
339+
>>> import sqlite3
340+
>>> sqlite3.enable_callback_tracebacks(True)
341+
>>> cx = sqlite3.connect(":memory:")
342+
>>> cx.set_trace_callback(lambda stmt: 5/0)
343+
>>> cx.execute("select 1")
344+
Exception ignored in: <function <lambda> at 0x10b4e3ee0>
345+
Traceback (most recent call last):
346+
File "<stdin>", line 1, in <lambda>
347+
ZeroDivisionError: division by zero
348+
>>> import sys
349+
>>> sys.unraisablehook = lambda unraisable: print(unraisable)
350+
>>> cx.execute("select 1")
351+
UnraisableHookArgs(exc_type=<class 'ZeroDivisionError'>, exc_value=ZeroDivisionError('division by zero'), exc_traceback=<traceback object at 0x10b559900>, err_msg=None, object=<function <lambda> at 0x10b4e3ee0>)
352+
<sqlite3.Cursor object at 0x10b1fe840>
335353

336354

337355
.. _sqlite3-connection-objects:

Doc/library/sys.rst

+8-3
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,14 @@ always available.
396396
``(type, value, traceback)``. Their meaning is: *type* gets the type of the
397397
exception being handled (a subclass of :exc:`BaseException`); *value* gets
398398
the exception instance (an instance of the exception type); *traceback* gets
399-
a :ref:`traceback object <traceback-objects>` which encapsulates the call
400-
stack at the point where the exception originally occurred.
401-
399+
a :ref:`traceback object <traceback-objects>` which typically encapsulates
400+
the call stack at the point where the exception last occurred.
401+
402+
.. versionchanged:: 3.11
403+
The ``type`` and ``traceback`` fields are now derived from the ``value``
404+
(the exception instance), so when an exception is modified while it is
405+
being handled, the changes are reflected in the results of subsequent
406+
calls to :func:`exc_info`.
402407

403408
.. data:: exec_prefix
404409

Doc/reference/simple_stmts.rst

+6
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,12 @@ and information about handling exceptions is in section :ref:`try`.
655655
The ``__suppress_context__`` attribute to suppress automatic display of the
656656
exception context.
657657

658+
.. versionchanged:: 3.11
659+
If the traceback of the active exception is modified in an :keyword:`except`
660+
clause, a subsequent ``raise`` statement re-raises the exception with the
661+
modified traceback. Previously, the exception was re-raised with the
662+
traceback it had when it was caught.
663+
658664
.. _break:
659665

660666
The :keyword:`!break` statement

Doc/using/configure.rst

+55-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ General Options
5353
Set the Python executable suffix to *SUFFIX*.
5454

5555
The default suffix is ``.exe`` on Windows and macOS (``python.exe``
56-
executable), and an empty string on other platforms (``python`` executable).
56+
executable), ``.wasm`` on Emscripten (``python.wasm`` executable), and
57+
an empty string on other platforms (``python`` executable).
58+
59+
.. versionchanged:: 3.11
60+
The default suffix on Emscripten platform is ``.wasm``.
5761

5862
.. cmdoption:: --with-tzpath=<list of absolute paths separated by pathsep>
5963

@@ -509,6 +513,56 @@ See ``Mac/README.rst``.
509513
:option:`--enable-framework` is set (default: ``Python``).
510514

511515

516+
Cross Compiling Options
517+
-----------------------
518+
519+
Cross compiling, also known as cross building, can be used to build Python
520+
for another CPU architecture or platform. Cross compiling requires a Python
521+
interpreter and the :program:`_freeze_module` binary from another build. The
522+
version of the build Python and :program:`_freeze_module` command must be
523+
the same as the cross compiled host Python.
524+
525+
.. cmdoption:: --build=BUILD
526+
527+
configure for building on BUILD, usually guessed by :program:`config.guess`.
528+
529+
.. cmdoption:: --host=HOST
530+
531+
cross-compile to build programs to run on HOST (target platform)
532+
533+
.. cmdoption:: --with-freeze-module=Programs/_freeze_module
534+
535+
path to ``_freeze_module`` binary for cross compiling.
536+
537+
.. versionadded:: 3.11
538+
539+
.. cmdoption:: --with-build-python=python3.xx
540+
541+
path to build ``python`` binary for cross compiling
542+
543+
.. versionadded:: 3.11
544+
545+
.. cmdoption:: CONFIG_SITE=file
546+
547+
An environment variable that points to a file with configure overrides.
548+
549+
Example *config.site* file::
550+
551+
# config.site-aarch64
552+
ac_cv_buggy_getaddrinfo=no
553+
ac_cv_file__dev_ptmx=yes
554+
ac_cv_file__dev_ptc=no
555+
556+
557+
Cross compiling example::
558+
559+
CONFIG_SITE=config.site-aarch64 ../configure \
560+
--build=x86_64-pc-linux-gnu \
561+
--host=aarch64-unknown-linux-gnu \
562+
--with-freeze-module=../x86_64/Programs/_freeze_module \
563+
--with-build-python=../x86_64/python
564+
565+
512566
Python Build System
513567
===================
514568

Doc/whatsnew/3.11.rst

+41-1
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,12 @@ Other CPython Implementation Changes
181181
hash-based pyc files now use ``siphash13``, too.
182182
(Contributed by Inada Naoki in :issue:`29410`.)
183183

184+
* When an active exception is re-raised by a :keyword:`raise` statement with no parameters,
185+
the traceback attached to this exception is now always ``sys.exc_info()[1].__traceback__``.
186+
This means that changes made to the traceback in the current :keyword:`except` clause are
187+
reflected in the re-raised exception.
188+
(Contributed by Irit Katriel in :issue:`45711`.)
189+
184190
New Modules
185191
===========
186192

@@ -203,6 +209,8 @@ fractions
203209

204210
math
205211
----
212+
* Add :func:`math.exp2`: return 2 raised to the power of x.
213+
(Contributed by Gideon Mitchell in :issue:`45917`.)
206214

207215
* Add :func:`math.cbrt`: return the cube root of x.
208216
(Contributed by Ajith Ramachandran in :issue:`44357`.)
@@ -248,7 +256,6 @@ sqlite3
248256
(Contributed by Aviv Palivoda, Daniel Shahaf, and Erlend E. Aasland in
249257
:issue:`16379` and :issue:`24139`.)
250258

251-
252259
* Add :meth:`~sqlite3.Connection.setlimit` and
253260
:meth:`~sqlite3.Connection.getlimit` to :class:`sqlite3.Connection` for
254261
setting and getting SQLite limits by connection basis.
@@ -258,6 +265,22 @@ sqlite3
258265
threading mode the underlying SQLite library has been compiled with.
259266
(Contributed by Erlend E. Aasland in :issue:`45613`.)
260267

268+
* :mod:`sqlite3` C callbacks now use unraisable exceptions if callback
269+
tracebacks are enabled. Users can now register an
270+
:func:`unraisable hook handler <sys.unraisablehook>` to improve their debug
271+
experience.
272+
(Contributed by Erlend E. Aasland in :issue:`45828`.)
273+
274+
275+
sys
276+
---
277+
278+
* :func:`sys.exc_info` now derives the ``type`` and ``traceback`` fields
279+
from the ``value`` (the exception instance), so when an exception is
280+
modified while it is being handled, the changes are reflected in
281+
the results of subsequent calls to :func:`exc_info`.
282+
(Contributed by Irit Katriel in :issue:`45711`.)
283+
261284

262285
threading
263286
---------
@@ -555,6 +578,12 @@ Build Changes
555578
``libdb`` 3.x and 4.x are no longer supported.
556579
(Contributed by Christian Heimes in :issue:`45747`.)
557580

581+
* The Python binary now builds the libpython static library using
582+
``-Wl,--whole-archive`` or ``-Wl,-all_load`` linker option to
583+
export all symbols exported by object files.
584+
Previously, the ``Py_FrozenMain`` symbol was not exported.
585+
(Contributed by Hai Shi and Victor Stinner in :issue:`44133`.)
586+
558587
C API Changes
559588
=============
560589

@@ -572,6 +601,17 @@ New Features
572601
suspend and resume tracing and profiling.
573602
(Contributed by Victor Stinner in :issue:`43760`.)
574603

604+
* :c:func:`PyErr_SetExcInfo()` no longer uses the ``type`` and ``traceback``
605+
arguments, the interpreter now derives those values from the exception
606+
instance (the ``value`` argument). The function still steals references
607+
of all three arguments.
608+
(Contributed by Irit Katriel in :issue:`45711`.)
609+
610+
* :c:func:`PyErr_GetExcInfo()` now derives the ``type`` and ``traceback``
611+
fields of the result from the exception instance (the ``value`` field).
612+
(Contributed by Irit Katriel in :issue:`45711`.)
613+
614+
575615
Porting to Python 3.11
576616
----------------------
577617

Include/cpython/cellobject.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ PyAPI_FUNC(PyObject *) PyCell_Get(PyObject *);
2222
PyAPI_FUNC(int) PyCell_Set(PyObject *, PyObject *);
2323

2424
#define PyCell_GET(op) (((PyCellObject *)(op))->ob_ref)
25-
#define PyCell_SET(op, v) ((void)(((PyCellObject *)(op))->ob_ref = v))
25+
#define PyCell_SET(op, v) _Py_RVALUE(((PyCellObject *)(op))->ob_ref = (v))
2626

2727
#ifdef __cplusplus
2828
}

Include/cpython/listobject.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ PyAPI_FUNC(void) _PyList_DebugMallocStats(FILE *out);
3030
#define _PyList_CAST(op) (assert(PyList_Check(op)), (PyListObject *)(op))
3131

3232
#define PyList_GET_ITEM(op, i) (_PyList_CAST(op)->ob_item[i])
33-
#define PyList_SET_ITEM(op, i, v) ((void)(_PyList_CAST(op)->ob_item[i] = (v)))
33+
#define PyList_SET_ITEM(op, i, v) _Py_RVALUE(_PyList_CAST(op)->ob_item[i] = (v))
3434
#define PyList_GET_SIZE(op) Py_SIZE(_PyList_CAST(op))

Include/cpython/tupleobject.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ PyAPI_FUNC(void) _PyTuple_MaybeUntrack(PyObject *);
2323
#define PyTuple_GET_ITEM(op, i) (_PyTuple_CAST(op)->ob_item[i])
2424

2525
/* Macro, *only* to be used to fill in brand new tuples */
26-
#define PyTuple_SET_ITEM(op, i, v) ((void)(_PyTuple_CAST(op)->ob_item[i] = v))
26+
#define PyTuple_SET_ITEM(op, i, v) _Py_RVALUE(_PyTuple_CAST(op)->ob_item[i] = (v))
2727

2828
PyAPI_FUNC(void) _PyTuple_DebugMallocStats(FILE *out);

0 commit comments

Comments
 (0)