Skip to content

Commit 97d06e5

Browse files
committed
Merge branch 'master' into justin39/aiter-c
* master: (129 commits) bpo-43452: Micro-optimizations to PyType_Lookup (pythonGH-24804) bpo-43517: Fix false positive in detection of circular imports (python#24895) bpo-43494: Make some minor changes to lnotab notes (pythonGH-24861) Mention that code.co_lnotab is deprecated in what's new for 3.10. (python#24902) bpo-43244: Remove symtable.h header file (pythonGH-24910) bpo-43466: Add --with-openssl-rpath configure option (pythonGH-24820) Fix a typo in c-analyzer (pythonGH-24468) bpo-41561: Add workaround for Ubuntu's custom security level (pythonGH-24915) bpo-43521: Allow ast.unparse with empty sets and NaN (pythonGH-24897) bpo-43244: Remove the PyAST_Validate() function (pythonGH-24911) bpo-43541: Fix PyEval_EvalCodeEx() regression (pythonGH-24918) bpo-43244: Fix test_peg_generators on Windows (pythonGH-24913) bpo-39342: Expose X509_V_FLAG_ALLOW_PROXY_CERTS in ssl module (pythonGH-18011) bpo-43244: Fix test_peg_generator for PyAST_Validate() (pythonGH-24912) bpo-42128: Add 'missing :' syntax error message to match statements (pythonGH-24733) bpo-43244: Add pycore_ast.h header file (pythonGH-24908) bpo-43244: Rename pycore_ast.h to pycore_ast_state.h (pythonGH-24907) Remove unnecessary imports in the grammar parser (pythonGH-24904) bpo-35883: Py_DecodeLocale() escapes invalid Unicode characters (pythonGH-24843) Add PEP 626 to what's new in 3.10. (python#24892) ...
2 parents 259af97 + ee48c7d commit 97d06e5

File tree

315 files changed

+25826
-11587
lines changed

Some content is hidden

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

315 files changed

+25826
-11587
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ jobs:
127127

128128
build_ubuntu:
129129
name: 'Ubuntu'
130-
runs-on: ubuntu-latest
130+
runs-on: ubuntu-20.04
131131
needs: check_source
132132
if: needs.check_source.outputs.run_tests == 'true'
133133
env:

Doc/c-api/exceptions.rst

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -505,29 +505,73 @@ Signal Handling
505505
single: SIGINT
506506
single: KeyboardInterrupt (built-in exception)
507507
508-
This function interacts with Python's signal handling. It checks whether a
509-
signal has been sent to the processes and if so, invokes the corresponding
510-
signal handler. If the :mod:`signal` module is supported, this can invoke a
511-
signal handler written in Python. In all cases, the default effect for
512-
:const:`SIGINT` is to raise the :exc:`KeyboardInterrupt` exception. If an
513-
exception is raised the error indicator is set and the function returns ``-1``;
514-
otherwise the function returns ``0``. The error indicator may or may not be
515-
cleared if it was previously set.
508+
This function interacts with Python's signal handling.
509+
510+
If the function is called from the main thread and under the main Python
511+
interpreter, it checks whether a signal has been sent to the processes
512+
and if so, invokes the corresponding signal handler. If the :mod:`signal`
513+
module is supported, this can invoke a signal handler written in Python.
514+
515+
The function attemps to handle all pending signals, and then returns ``0``.
516+
However, if a Python signal handler raises an exception, the error
517+
indicator is set and the function returns ``-1`` immediately (such that
518+
other pending signals may not have been handled yet: they will be on the
519+
next :c:func:`PyErr_CheckSignals()` invocation).
520+
521+
If the function is called from a non-main thread, or under a non-main
522+
Python interpreter, it does nothing and returns ``0``.
523+
524+
This function can be called by long-running C code that wants to
525+
be interruptible by user requests (such as by pressing Ctrl-C).
526+
527+
.. note::
528+
The default Python signal handler for :const:`SIGINT` raises the
529+
:exc:`KeyboardInterrupt` exception.
516530
517531
518532
.. c:function:: void PyErr_SetInterrupt()
519533
520534
.. index::
535+
module: signal
521536
single: SIGINT
522537
single: KeyboardInterrupt (built-in exception)
523538
524-
Simulate the effect of a :const:`SIGINT` signal arriving. The next time
539+
Simulate the effect of a :const:`SIGINT` signal arriving.
540+
This is equivalent to ``PyErr_SetInterruptEx(SIGINT)``.
541+
542+
.. note::
543+
This function is async-signal-safe. It can be called without
544+
the :term:`GIL` and from a C signal handler.
545+
546+
547+
.. c:function:: int PyErr_SetInterruptEx(int signum)
548+
549+
.. index::
550+
module: signal
551+
single: KeyboardInterrupt (built-in exception)
552+
553+
Simulate the effect of a signal arriving. The next time
525554
:c:func:`PyErr_CheckSignals` is called, the Python signal handler for
526-
:const:`SIGINT` will be called.
555+
the given signal number will be called.
556+
557+
This function can be called by C code that sets up its own signal handling
558+
and wants Python signal handlers to be invoked as expected when an
559+
interruption is requested (for example when the user presses Ctrl-C
560+
to interrupt an operation).
561+
562+
If the given signal isn't handled by Python (it was set to
563+
:data:`signal.SIG_DFL` or :data:`signal.SIG_IGN`), it will be ignored.
564+
565+
If *signum* is outside of the allowed range of signal numbers, ``-1``
566+
is returned. Otherwise, ``0`` is returned. The error indicator is
567+
never changed by this function.
568+
569+
.. note::
570+
This function is async-signal-safe. It can be called without
571+
the :term:`GIL` and from a C signal handler.
572+
573+
.. versionadded:: 3.10
527574
528-
If :const:`SIGINT` isn't handled by Python (it was set to
529-
:data:`signal.SIG_DFL` or :data:`signal.SIG_IGN`), this function does
530-
nothing.
531575
532576
.. c:function:: int PySignal_SetWakeupFd(int fd)
533577

Doc/c-api/memory.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ Customize pymalloc Arena Allocator
555555
+--------------------------------------------------+---------------------------------------+
556556
| ``void* alloc(void *ctx, size_t size)`` | allocate an arena of size bytes |
557557
+--------------------------------------------------+---------------------------------------+
558-
| ``void free(void *ctx, size_t size, void *ptr)`` | free an arena |
558+
| ``void free(void *ctx, void *ptr, size_t size)`` | free an arena |
559559
+--------------------------------------------------+---------------------------------------+
560560
561561
.. c:function:: void PyObject_GetArenaAllocator(PyObjectArenaAllocator *allocator)

Doc/c-api/unicode.rst

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,10 @@ Extension modules can continue using them, as they will not be removed in Python
725725
:c:type:`Py_UNICODE` buffer of the given *size* by ASCII digits 0--9
726726
according to their decimal value. Return ``NULL`` if an exception occurs.
727727
728+
.. deprecated-removed:: 3.3 3.11
729+
Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using
730+
:c:func:`Py_UNICODE_TODECIMAL`.
731+
728732
729733
.. c:function:: Py_UNICODE* PyUnicode_AsUnicodeAndSize(PyObject *unicode, Py_ssize_t *size)
730734
@@ -1043,7 +1047,7 @@ These are the generic codec APIs:
10431047
to be used is looked up using the Python codec registry. Return ``NULL`` if an
10441048
exception was raised by the codec.
10451049
1046-
.. deprecated-removed:: 3.3 4.0
1050+
.. deprecated-removed:: 3.3 3.11
10471051
Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using
10481052
:c:func:`PyUnicode_AsEncodedString`.
10491053
@@ -1116,7 +1120,7 @@ These are the UTF-8 codec APIs:
11161120
return a Python bytes object. Return ``NULL`` if an exception was raised by
11171121
the codec.
11181122
1119-
.. deprecated-removed:: 3.3 4.0
1123+
.. deprecated-removed:: 3.3 3.11
11201124
Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using
11211125
:c:func:`PyUnicode_AsUTF8String`, :c:func:`PyUnicode_AsUTF8AndSize` or
11221126
:c:func:`PyUnicode_AsEncodedString`.
@@ -1190,7 +1194,7 @@ These are the UTF-32 codec APIs:
11901194
11911195
Return ``NULL`` if an exception was raised by the codec.
11921196
1193-
.. deprecated-removed:: 3.3 4.0
1197+
.. deprecated-removed:: 3.3 3.11
11941198
Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using
11951199
:c:func:`PyUnicode_AsUTF32String` or :c:func:`PyUnicode_AsEncodedString`.
11961200
@@ -1265,7 +1269,7 @@ These are the UTF-16 codec APIs:
12651269
12661270
Return ``NULL`` if an exception was raised by the codec.
12671271
1268-
.. deprecated-removed:: 3.3 4.0
1272+
.. deprecated-removed:: 3.3 3.11
12691273
Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using
12701274
:c:func:`PyUnicode_AsUTF16String` or :c:func:`PyUnicode_AsEncodedString`.
12711275
@@ -1303,7 +1307,7 @@ These are the UTF-7 codec APIs:
13031307
nonzero, whitespace will be encoded in base-64. Both are set to zero for the
13041308
Python "utf-7" codec.
13051309
1306-
.. deprecated-removed:: 3.3 4.0
1310+
.. deprecated-removed:: 3.3 3.11
13071311
Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using
13081312
:c:func:`PyUnicode_AsEncodedString`.
13091313
@@ -1333,7 +1337,7 @@ These are the "Unicode Escape" codec APIs:
13331337
Encode the :c:type:`Py_UNICODE` buffer of the given *size* using Unicode-Escape and
13341338
return a bytes object. Return ``NULL`` if an exception was raised by the codec.
13351339
1336-
.. deprecated-removed:: 3.3 4.0
1340+
.. deprecated-removed:: 3.3 3.11
13371341
Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using
13381342
:c:func:`PyUnicode_AsUnicodeEscapeString`.
13391343
@@ -1364,7 +1368,7 @@ These are the "Raw Unicode Escape" codec APIs:
13641368
Encode the :c:type:`Py_UNICODE` buffer of the given *size* using Raw-Unicode-Escape
13651369
and return a bytes object. Return ``NULL`` if an exception was raised by the codec.
13661370
1367-
.. deprecated-removed:: 3.3 4.0
1371+
.. deprecated-removed:: 3.3 3.11
13681372
Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using
13691373
:c:func:`PyUnicode_AsRawUnicodeEscapeString` or
13701374
:c:func:`PyUnicode_AsEncodedString`.
@@ -1396,7 +1400,7 @@ ordinals and only these are accepted by the codecs during encoding.
13961400
return a Python bytes object. Return ``NULL`` if an exception was raised by
13971401
the codec.
13981402
1399-
.. deprecated-removed:: 3.3 4.0
1403+
.. deprecated-removed:: 3.3 3.11
14001404
Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using
14011405
:c:func:`PyUnicode_AsLatin1String` or
14021406
:c:func:`PyUnicode_AsEncodedString`.
@@ -1428,7 +1432,7 @@ codes generate errors.
14281432
return a Python bytes object. Return ``NULL`` if an exception was raised by
14291433
the codec.
14301434
1431-
.. deprecated-removed:: 3.3 4.0
1435+
.. deprecated-removed:: 3.3 3.11
14321436
Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using
14331437
:c:func:`PyUnicode_AsASCIIString` or
14341438
:c:func:`PyUnicode_AsEncodedString`.
@@ -1480,7 +1484,7 @@ These are the mapping codec APIs:
14801484
*mapping* object and return the result as a bytes object. Return ``NULL`` if
14811485
an exception was raised by the codec.
14821486
1483-
.. deprecated-removed:: 3.3 4.0
1487+
.. deprecated-removed:: 3.3 3.11
14841488
Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using
14851489
:c:func:`PyUnicode_AsCharmapString` or
14861490
:c:func:`PyUnicode_AsEncodedString`.
@@ -1512,7 +1516,7 @@ The following codec API is special in that maps Unicode to Unicode.
15121516
character *mapping* table to it and return the resulting Unicode object.
15131517
Return ``NULL`` when an exception was raised by the codec.
15141518
1515-
.. deprecated-removed:: 3.3 4.0
1519+
.. deprecated-removed:: 3.3 3.11
15161520
Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using
15171521
:c:func:`PyUnicode_Translate`. or :ref:`generic codec based API
15181522
<codec-registry>`

Doc/data/stable_abi.dat

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ PyCFunction_Call
3636
PyCFunction_GetFlags
3737
PyCFunction_GetFunction
3838
PyCFunction_GetSelf
39+
PyCFunction_New
3940
PyCFunction_NewEx
4041
PyCFunction_Type
4142
PyCMethod_New
@@ -144,6 +145,7 @@ PyErr_SetFromErrnoWithFilenameObjects
144145
PyErr_SetImportError
145146
PyErr_SetImportErrorSubclass
146147
PyErr_SetInterrupt
148+
PyErr_SetInterruptEx
147149
PyErr_SetNone
148150
PyErr_SetObject
149151
PyErr_SetString
@@ -774,7 +776,6 @@ Py_SetPath
774776
Py_SetProgramName
775777
Py_SetPythonHome
776778
Py_SetRecursionLimit
777-
Py_SymtableString
778779
Py_UTF8Mode
779780
Py_VaBuildValue
780781
Py_XNewRef

Doc/faq/design.rst

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,8 @@ Why isn't there a switch or case statement in Python?
259259
-----------------------------------------------------
260260

261261
You can do this easily enough with a sequence of ``if... elif... elif... else``.
262-
There have been some proposals for switch statement syntax, but there is no
263-
consensus (yet) on whether and how to do range tests. See :pep:`275` for
264-
complete details and the current status.
262+
For literal values, or constants within a namespace, you can also use a
263+
``match ... case`` statement.
265264

266265
For cases where you need to choose from a very large number of possibilities,
267266
you can create a dictionary mapping case values to functions to call. For
@@ -601,7 +600,15 @@ test cases at all.
601600
Why is there no goto?
602601
---------------------
603602

604-
You can use exceptions to provide a "structured goto" that even works across
603+
In the 1970s people realized that unrestricted goto could lead
604+
to messy "spaghetti" code that was hard to understand and revise.
605+
In a high-level language, it is also unneeded as long as there
606+
are ways to branch (in Python, with ``if`` statements and ``or``,
607+
``and``, and ``if-else`` expressions) and loop (with ``while``
608+
and ``for`` statements, possibly containing ``continue`` and ``break``).
609+
610+
One can also use exceptions to provide a "structured goto"
611+
that works even across
605612
function calls. Many feel that exceptions can conveniently emulate all
606613
reasonable uses of the "go" or "goto" constructs of C, Fortran, and other
607614
languages. For example::

Doc/howto/descriptor.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,8 +1139,8 @@ If you have ever wondered where *self* comes from in regular methods or where
11391139
*cls* comes from in class methods, this is it!
11401140

11411141

1142-
Static methods
1143-
--------------
1142+
Other kinds of methods
1143+
----------------------
11441144

11451145
Non-data descriptors provide a simple mechanism for variations on the usual
11461146
patterns of binding functions into methods.
@@ -1163,6 +1163,10 @@ This chart summarizes the binding and its two most useful variants:
11631163
| classmethod | f(type(obj), \*args) | f(cls, \*args) |
11641164
+-----------------+----------------------+------------------+
11651165

1166+
1167+
Static methods
1168+
--------------
1169+
11661170
Static methods return the underlying function without changes. Calling either
11671171
``c.f`` or ``C.f`` is the equivalent of a direct lookup into
11681172
``object.__getattribute__(c, "f")`` or ``object.__getattribute__(C, "f")``. As a

Doc/library/_thread.rst

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,27 @@ This module defines the following constants and functions:
6161
:func:`sys.unraisablehook` is now used to handle unhandled exceptions.
6262

6363

64-
.. function:: interrupt_main()
64+
.. function:: interrupt_main(signum=signal.SIGINT, /)
6565

66-
Simulate the effect of a :data:`signal.SIGINT` signal arriving in the main
67-
thread. A thread can use this function to interrupt the main thread.
66+
Simulate the effect of a signal arriving in the main thread.
67+
A thread can use this function to interrupt the main thread, though
68+
there is no guarantee that the interruption will happen immediately.
6869

69-
If :data:`signal.SIGINT` isn't handled by Python (it was set to
70+
If given, *signum* is the number of the signal to simulate.
71+
If *signum* is not given, :data:`signal.SIGINT` is simulated.
72+
73+
If the given signal isn't handled by Python (it was set to
7074
:data:`signal.SIG_DFL` or :data:`signal.SIG_IGN`), this function does
7175
nothing.
7276

77+
.. versionchanged:: 3.10
78+
The *signum* argument is added to customize the signal number.
79+
80+
.. note::
81+
This does not emit the corresponding signal but schedules a call to
82+
the associated handler (if it exists).
83+
If you want to truly emit the signal, use :func:`signal.raise_signal`.
84+
7385

7486
.. function:: exit()
7587

0 commit comments

Comments
 (0)