Skip to content

Commit

Permalink
Merge branch 'main' into bpo_44133
Browse files Browse the repository at this point in the history
* 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)
  ...
  • Loading branch information
shihai1991 committed Dec 1, 2021
2 parents 0230c8b + 0aa0bd0 commit 6edb6f5
Show file tree
Hide file tree
Showing 46 changed files with 1,345 additions and 318 deletions.
7 changes: 6 additions & 1 deletion Doc/c-api/exceptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,6 @@ Querying the error indicator
to an exception that was *already caught*, not to an exception that was
freshly raised. This function steals the references of the arguments.
To clear the exception state, pass ``NULL`` for all three arguments.
For general rules about the three arguments, see :c:func:`PyErr_Restore`.
.. note::
Expand All @@ -493,6 +492,12 @@ Querying the error indicator
.. versionadded:: 3.3
.. versionchanged:: 3.11
The ``type`` and ``traceback`` arguments are no longer used and
can be NULL. The interpreter now derives them from the exception
instance (the ``value`` argument). The function still steals
references of all three arguments.
Signal Handling
===============
Expand Down
22 changes: 22 additions & 0 deletions Doc/howto/logging-cookbook.rst
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,17 @@ alternative there, as well as adapting the above script to use your alternative
serialization.


Running a logging socket listener in production
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

To run a logging listener in production, you may need to use a process-management tool
such as `Supervisor <http://supervisord.org/>`_. `Here
<https://gist.github.com/vsajip/4b227eeec43817465ca835ca66f75e2b>`_ is a Gist which
provides the bare-bones files to run the above functionality using Supervisor: you
will need to change the `/path/to/` parts in the Gist to reflect the actual paths you
want to use.


.. _context-info:

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

Deploying Web applications using Gunicorn and uWSGI
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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


Using file rotation
-------------------
Expand Down
22 changes: 18 additions & 4 deletions Doc/library/dataclasses.rst
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,10 @@ Module contents
Converts the dataclass ``instance`` to a dict (by using the
factory function ``dict_factory``). Each dataclass is converted
to a dict of its fields, as ``name: value`` pairs. dataclasses, dicts,
lists, and tuples are recursed into. For example::
lists, and tuples are recursed into. Other objects are copied with
:func:`copy.deepcopy`.

Example of using :func:`asdict` on nested dataclasses::

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

Raises :exc:`TypeError` if ``instance`` is not a dataclass instance.
To create a shallow copy, the following workaround may be used::

dict((field.name, getattr(instance, field.name)) for field in fields(instance))

:func:`asdict` raises :exc:`TypeError` if ``instance`` is not a dataclass
instance.

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

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

Continuing from the previous example::

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

Raises :exc:`TypeError` if ``instance`` is not a dataclass instance.
To create a shallow copy, the following workaround may be used::

tuple(getattr(instance, field.name) for field in dataclasses.fields(instance))

:func:`astuple` raises :exc:`TypeError` if ``instance`` is not a dataclass
instance.

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

Expand Down
4 changes: 2 additions & 2 deletions Doc/library/datetime.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2359,8 +2359,8 @@ requires, and these work on all platforms with a standard C implementation.
| | decimal number. | | \(9) |
+-----------+--------------------------------+------------------------+-------+
| ``%f`` | Microsecond as a decimal | 000000, 000001, ..., | \(5) |
| | number, zero-padded on the | 999999 | |
| | left. | | |
| | number, zero-padded to 6 | 999999 | |
| | digits. | | |
+-----------+--------------------------------+------------------------+-------+
| ``%z`` | UTC offset in the form | (empty), +0000, | \(6) |
| | ``±HHMM[SS[.ffffff]]`` (empty | -0400, +1030, | |
Expand Down
7 changes: 7 additions & 0 deletions Doc/library/math.rst
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,13 @@ Power and logarithmic functions
or ``pow(math.e, x)``.


.. function:: exp2(x)

Return *2* raised to the power *x*.

.. versionadded:: 3.11


.. function:: expm1(x)

Return *e* raised to the power *x*, minus 1. Here *e* is the base of natural
Expand Down
24 changes: 21 additions & 3 deletions Doc/library/sqlite3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,27 @@ Module functions and constants

By default you will not get any tracebacks in user-defined functions,
aggregates, converters, authorizer callbacks etc. If you want to debug them,
you can call this function with *flag* set to ``True``. Afterwards, you will
get tracebacks from callbacks on ``sys.stderr``. Use :const:`False` to
disable the feature again.
you can call this function with *flag* set to :const:`True`. Afterwards, you
will get tracebacks from callbacks on :data:`sys.stderr`. Use :const:`False`
to disable the feature again.

Register an :func:`unraisable hook handler <sys.unraisablehook>` for an
improved debug experience::

>>> import sqlite3
>>> sqlite3.enable_callback_tracebacks(True)
>>> cx = sqlite3.connect(":memory:")
>>> cx.set_trace_callback(lambda stmt: 5/0)
>>> cx.execute("select 1")
Exception ignored in: <function <lambda> at 0x10b4e3ee0>
Traceback (most recent call last):
File "<stdin>", line 1, in <lambda>
ZeroDivisionError: division by zero
>>> import sys
>>> sys.unraisablehook = lambda unraisable: print(unraisable)
>>> cx.execute("select 1")
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>)
<sqlite3.Cursor object at 0x10b1fe840>


.. _sqlite3-connection-objects:
Expand Down
11 changes: 8 additions & 3 deletions Doc/library/sys.rst
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,14 @@ always available.
``(type, value, traceback)``. Their meaning is: *type* gets the type of the
exception being handled (a subclass of :exc:`BaseException`); *value* gets
the exception instance (an instance of the exception type); *traceback* gets
a :ref:`traceback object <traceback-objects>` which encapsulates the call
stack at the point where the exception originally occurred.

a :ref:`traceback object <traceback-objects>` which typically encapsulates
the call stack at the point where the exception last occurred.

.. versionchanged:: 3.11
The ``type`` and ``traceback`` fields are now derived from the ``value``
(the exception instance), so when an exception is modified while it is
being handled, the changes are reflected in the results of subsequent
calls to :func:`exc_info`.

.. data:: exec_prefix

Expand Down
6 changes: 6 additions & 0 deletions Doc/reference/simple_stmts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,12 @@ and information about handling exceptions is in section :ref:`try`.
The ``__suppress_context__`` attribute to suppress automatic display of the
exception context.

.. versionchanged:: 3.11
If the traceback of the active exception is modified in an :keyword:`except`
clause, a subsequent ``raise`` statement re-raises the exception with the
modified traceback. Previously, the exception was re-raised with the
traceback it had when it was caught.

.. _break:

The :keyword:`!break` statement
Expand Down
56 changes: 55 additions & 1 deletion Doc/using/configure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ General Options
Set the Python executable suffix to *SUFFIX*.

The default suffix is ``.exe`` on Windows and macOS (``python.exe``
executable), and an empty string on other platforms (``python`` executable).
executable), ``.wasm`` on Emscripten (``python.wasm`` executable), and
an empty string on other platforms (``python`` executable).

.. versionchanged:: 3.11
The default suffix on Emscripten platform is ``.wasm``.

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

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


Cross Compiling Options
-----------------------

Cross compiling, also known as cross building, can be used to build Python
for another CPU architecture or platform. Cross compiling requires a Python
interpreter and the :program:`_freeze_module` binary from another build. The
version of the build Python and :program:`_freeze_module` command must be
the same as the cross compiled host Python.

.. cmdoption:: --build=BUILD

configure for building on BUILD, usually guessed by :program:`config.guess`.

.. cmdoption:: --host=HOST

cross-compile to build programs to run on HOST (target platform)

.. cmdoption:: --with-freeze-module=Programs/_freeze_module

path to ``_freeze_module`` binary for cross compiling.

.. versionadded:: 3.11

.. cmdoption:: --with-build-python=python3.xx

path to build ``python`` binary for cross compiling

.. versionadded:: 3.11

.. cmdoption:: CONFIG_SITE=file

An environment variable that points to a file with configure overrides.

Example *config.site* file::

# config.site-aarch64
ac_cv_buggy_getaddrinfo=no
ac_cv_file__dev_ptmx=yes
ac_cv_file__dev_ptc=no


Cross compiling example::

CONFIG_SITE=config.site-aarch64 ../configure \
--build=x86_64-pc-linux-gnu \
--host=aarch64-unknown-linux-gnu \
--with-freeze-module=../x86_64/Programs/_freeze_module \
--with-build-python=../x86_64/python


Python Build System
===================

Expand Down
36 changes: 35 additions & 1 deletion Doc/whatsnew/3.11.rst
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@ Other CPython Implementation Changes
hash-based pyc files now use ``siphash13``, too.
(Contributed by Inada Naoki in :issue:`29410`.)

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

New Modules
===========

Expand All @@ -203,6 +209,8 @@ fractions

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

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


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

* :mod:`sqlite3` C callbacks now use unraisable exceptions if callback
tracebacks are enabled. Users can now register an
:func:`unraisable hook handler <sys.unraisablehook>` to improve their debug
experience.
(Contributed by Erlend E. Aasland in :issue:`45828`.)


sys
---

* :func:`sys.exc_info` now derives the ``type`` and ``traceback`` fields
from the ``value`` (the exception instance), so when an exception is
modified while it is being handled, the changes are reflected in
the results of subsequent calls to :func:`exc_info`.
(Contributed by Irit Katriel in :issue:`45711`.)


threading
---------
Expand Down Expand Up @@ -572,6 +595,17 @@ New Features
suspend and resume tracing and profiling.
(Contributed by Victor Stinner in :issue:`43760`.)

* :c:func:`PyErr_SetExcInfo()` no longer uses the ``type`` and ``traceback``
arguments, the interpreter now derives those values from the exception
instance (the ``value`` argument). The function still steals references
of all three arguments.
(Contributed by Irit Katriel in :issue:`45711`.)

* :c:func:`PyErr_GetExcInfo()` now derives the ``type`` and ``traceback``
fields of the result from the exception instance (the ``value`` field).
(Contributed by Irit Katriel in :issue:`45711`.)


Porting to Python 3.11
----------------------

Expand Down
2 changes: 1 addition & 1 deletion Include/cpython/cellobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ PyAPI_FUNC(PyObject *) PyCell_Get(PyObject *);
PyAPI_FUNC(int) PyCell_Set(PyObject *, PyObject *);

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

#ifdef __cplusplus
}
Expand Down
2 changes: 1 addition & 1 deletion Include/cpython/listobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ PyAPI_FUNC(void) _PyList_DebugMallocStats(FILE *out);
#define _PyList_CAST(op) (assert(PyList_Check(op)), (PyListObject *)(op))

#define PyList_GET_ITEM(op, i) (_PyList_CAST(op)->ob_item[i])
#define PyList_SET_ITEM(op, i, v) ((void)(_PyList_CAST(op)->ob_item[i] = (v)))
#define PyList_SET_ITEM(op, i, v) _Py_RVALUE(_PyList_CAST(op)->ob_item[i] = (v))
#define PyList_GET_SIZE(op) Py_SIZE(_PyList_CAST(op))
2 changes: 1 addition & 1 deletion Include/cpython/tupleobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ PyAPI_FUNC(void) _PyTuple_MaybeUntrack(PyObject *);
#define PyTuple_GET_ITEM(op, i) (_PyTuple_CAST(op)->ob_item[i])

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

PyAPI_FUNC(void) _PyTuple_DebugMallocStats(FILE *out);
10 changes: 5 additions & 5 deletions Include/internal/pycore_asdl.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ asdl_ ## NAME ## _seq *_Py_asdl_ ## NAME ## _seq_new(Py_ssize_t size, PyArena *a
return seq; \
}

#define asdl_seq_GET_UNTYPED(S, I) (S)->elements[(I)]
#define asdl_seq_GET(S, I) (S)->typed_elements[(I)]
#define asdl_seq_LEN(S) ((S) == NULL ? 0 : (S)->size)
#define asdl_seq_GET_UNTYPED(S, I) _Py_RVALUE((S)->elements[(I)])
#define asdl_seq_GET(S, I) _Py_RVALUE((S)->typed_elements[(I)])
#define asdl_seq_LEN(S) _Py_RVALUE(((S) == NULL ? 0 : (S)->size))

#ifdef Py_DEBUG
# define asdl_seq_SET(S, I, V) \
Expand All @@ -91,7 +91,7 @@ asdl_ ## NAME ## _seq *_Py_asdl_ ## NAME ## _seq_new(Py_ssize_t size, PyArena *a
(S)->typed_elements[_asdl_i] = (V); \
} while (0)
#else
# define asdl_seq_SET(S, I, V) ((void)((S)->typed_elements[I] = (V)))
# define asdl_seq_SET(S, I, V) _Py_RVALUE((S)->typed_elements[I] = (V))
#endif

#ifdef Py_DEBUG
Expand All @@ -103,7 +103,7 @@ asdl_ ## NAME ## _seq *_Py_asdl_ ## NAME ## _seq_new(Py_ssize_t size, PyArena *a
(S)->elements[_asdl_i] = (V); \
} while (0)
#else
# define asdl_seq_SET_UNTYPED(S, I, V) ((void)((S)->elements[I] = (V)))
# define asdl_seq_SET_UNTYPED(S, I, V) _Py_RVALUE((S)->elements[I] = (V))
#endif

#ifdef __cplusplus
Expand Down
Loading

0 comments on commit 6edb6f5

Please sign in to comment.