Skip to content

Commit b4861f8

Browse files
committed
Merge branch 'main' into bpo-42260
2 parents e76f299 + 6266e4a commit b4861f8

File tree

103 files changed

+2695
-1480
lines changed

Some content is hidden

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

103 files changed

+2695
-1480
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*.so.*
1111
*.dylib
1212
*.dll
13+
*.wasm
1314
*.orig
1415
*.pyc
1516
*.pyd
@@ -59,7 +60,6 @@ Lib/distutils/command/*.pdb
5960
Lib/lib2to3/*.pickle
6061
Lib/test/data/*
6162
!Lib/test/data/README
62-
/_bootstrap_python
6363
/Makefile
6464
/Makefile.pre
6565
Mac/Makefile

Doc/howto/annotations.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ Manually Un-Stringizing Stringized Annotations
156156
require annotating with string values that specifically
157157
*can't* be evaluated. For example:
158158

159-
* :pep:`604` union types using `|`, before support for this
159+
* :pep:`604` union types using ``|``, before support for this
160160
was added to Python 3.10.
161161
* Definitions that aren't needed at runtime, only imported
162162
when :const:`typing.TYPE_CHECKING` is true.

Doc/howto/logging-cookbook.rst

Lines changed: 22 additions & 0 deletions
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/asyncio-stream.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ TCP echo client using the :func:`asyncio.open_connection` function::
352352

353353
print(f'Send: {message!r}')
354354
writer.write(message.encode())
355+
await writer.drain()
355356

356357
data = await reader.read(100)
357358
print(f'Received: {data.decode()!r}')

Doc/library/contextlib.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,9 @@ Functions and classes provided:
130130
either as decorators or with :keyword:`async with` statements::
131131

132132
import time
133+
from contextlib import asynccontextmanager
133134

135+
@asynccontextmanager
134136
async def timeit():
135137
now = time.monotonic()
136138
try:

Doc/library/dataclasses.rst

Lines changed: 18 additions & 4 deletions
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/math.rst

Lines changed: 7 additions & 0 deletions
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

Lines changed: 21 additions & 3 deletions
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/reference/executionmodel.rst

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,25 @@ Binding of names
5656

5757
.. index:: single: from; import statement
5858

59-
The following constructs bind names: formal parameters to functions,
60-
:keyword:`import` statements, class and function definitions (these bind the
61-
class or function name in the defining block), and targets that are identifiers
62-
if occurring in an assignment, :keyword:`for` loop header, or after
63-
:keyword:`!as` in a :keyword:`with` statement or :keyword:`except` clause.
64-
The :keyword:`!import` statement
65-
of the form ``from ... import *`` binds all names defined in the imported
66-
module, except those beginning with an underscore. This form may only be used
67-
at the module level.
59+
The following constructs bind names:
60+
61+
* formal parameters to functions,
62+
* class definitions,
63+
* function definitions,
64+
* assignment expressions,
65+
* :ref:`targets <assignment>` that are identifiers if occurring in
66+
an assignment:
67+
68+
+ :keyword:`for` loop header,
69+
+ after :keyword:`!as` in a :keyword:`with` statement, :keyword:`except`
70+
clause or in the as-pattern in structural pattern matching,
71+
+ in a capture pattern in structural pattern matching
72+
73+
* :keyword:`import` statements.
74+
75+
The :keyword:`!import` statement of the form ``from ... import *`` binds all
76+
names defined in the imported module, except those beginning with an underscore.
77+
This form may only be used at the module level.
6878

6979
A target occurring in a :keyword:`del` statement is also considered bound for
7080
this purpose (though the actual semantics are to unbind the name).

Doc/using/configure.rst

Lines changed: 55 additions & 1 deletion
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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ fractions
203203

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

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

251-
252253
* Add :meth:`~sqlite3.Connection.setlimit` and
253254
:meth:`~sqlite3.Connection.getlimit` to :class:`sqlite3.Connection` for
254255
setting and getting SQLite limits by connection basis.
@@ -258,6 +259,12 @@ sqlite3
258259
threading mode the underlying SQLite library has been compiled with.
259260
(Contributed by Erlend E. Aasland in :issue:`45613`.)
260261

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

262269
threading
263270
---------

Grammar/python.gram

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,8 @@ invalid_expression:
10841084
# !(NAME STRING) is not matched so we don't show this error with some invalid string prefixes like: kf"dsfsdf"
10851085
# Soft keywords need to also be ignored because they can be parsed as NAME NAME
10861086
| !(NAME STRING | SOFT_KEYWORD) a=disjunction b=expression_without_invalid {
1087-
_PyPegen_check_legacy_stmt(p, a) ? NULL : RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "invalid syntax. Perhaps you forgot a comma?") }
1087+
_PyPegen_check_legacy_stmt(p, a) ? NULL : p->tokens[p->mark-1]->level == 0 ? NULL :
1088+
RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "invalid syntax. Perhaps you forgot a comma?") }
10881089
| a=disjunction 'if' b=disjunction !('else'|':') { RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "expected 'else' after 'if' expression") }
10891090

10901091
invalid_named_expression:

Include/cpython/frameobject.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ struct _frame {
1212
int f_lineno; /* Current line number. Only valid if non-zero */
1313
char f_trace_lines; /* Emit per-line trace events? */
1414
char f_trace_opcodes; /* Emit per-opcode trace events? */
15-
char f_own_locals_memory; /* This frame owns the memory for the locals */
15+
char f_owns_frame; /* This frame owns the frame */
16+
/* The frame data, if this frame object owns the frame */
17+
PyObject *_f_frame_data[1];
1618
};
1719

1820
/* Standard object interface */
@@ -26,7 +28,7 @@ PyAPI_FUNC(PyFrameObject *) PyFrame_New(PyThreadState *, PyCodeObject *,
2628

2729
/* only internal use */
2830
PyFrameObject*
29-
_PyFrame_New_NoTrack(struct _interpreter_frame *, int);
31+
_PyFrame_New_NoTrack(PyCodeObject *code);
3032

3133

3234
/* The rest of the interface is specific for frame objects */

Include/internal/pycore_frame.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ static inline void _PyFrame_StackPush(InterpreterFrame *f, PyObject *value) {
6969

7070
#define FRAME_SPECIALS_SIZE ((sizeof(InterpreterFrame)-1)/sizeof(PyObject *))
7171

72-
InterpreterFrame *
73-
_PyInterpreterFrame_HeapAlloc(PyFunctionObject *func, PyObject *locals);
72+
InterpreterFrame *_PyFrame_Copy(InterpreterFrame *frame);
7473

7574
static inline void
7675
_PyFrame_InitializeSpecials(
@@ -139,8 +138,8 @@ _PyFrame_GetFrameObject(InterpreterFrame *frame)
139138
* take should be set to 1 for heap allocated
140139
* frames like the ones in generators and coroutines.
141140
*/
142-
int
143-
_PyFrame_Clear(InterpreterFrame * frame, int take);
141+
void
142+
_PyFrame_Clear(InterpreterFrame * frame);
144143

145144
int
146145
_PyFrame_Traverse(InterpreterFrame *frame, visitproc visit, void *arg);

Include/internal/pycore_gc.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ extern Py_ssize_t _PyGC_CollectNoFail(PyThreadState *tstate);
167167

168168

169169
// Functions to clear types free lists
170-
extern void _PyFrame_ClearFreeList(PyInterpreterState *interp);
171170
extern void _PyTuple_ClearFreeList(PyInterpreterState *interp);
172171
extern void _PyFloat_ClearFreeList(PyInterpreterState *interp);
173172
extern void _PyList_ClearFreeList(PyInterpreterState *interp);

0 commit comments

Comments
 (0)