Skip to content

Commit 5e9c3ee

Browse files
Merge branch 'main' of https://github.com/python/cpython into exceptions
2 parents 85098bc + 4533036 commit 5e9c3ee

File tree

74 files changed

+1600
-778
lines changed

Some content is hidden

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

74 files changed

+1600
-778
lines changed

Doc/library/ctypes.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,36 @@ invalid non-\ ``NULL`` pointers would crash Python)::
870870
ValueError: NULL pointer access
871871
>>>
872872

873+
.. _ctypes-thread-safety:
874+
875+
Thread safety without the GIL
876+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
877+
878+
In Python 3.13, the :term:`GIL` may be disabled on :term:`experimental free threaded <free threading>` builds.
879+
In ctypes, reads and writes to a single object concurrently is safe, but not across multiple objects:
880+
881+
.. code-block:: pycon
882+
883+
>>> number = c_int(42)
884+
>>> pointer_a = pointer(number)
885+
>>> pointer_b = pointer(number)
886+
887+
In the above, it's only safe for one object to read and write to the address at once if the GIL is disabled.
888+
So, ``pointer_a`` can be shared and written to across multiple threads, but only if ``pointer_b``
889+
is not also attempting to do the same. If this is an issue, consider using a :class:`threading.Lock`
890+
to synchronize access to memory:
891+
892+
.. code-block:: pycon
893+
894+
>>> import threading
895+
>>> lock = threading.Lock()
896+
>>> # Thread 1
897+
>>> with lock:
898+
... pointer_a.contents = 24
899+
>>> # Thread 2
900+
>>> with lock:
901+
... pointer_b.contents = 42
902+
873903
874904
.. _ctypes-type-conversions:
875905

Doc/library/fnmatch.rst

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,15 @@ module. See module :mod:`glob` for pathname expansion (:mod:`glob` uses
4646
a period are not special for this module, and are matched by the ``*`` and ``?``
4747
patterns.
4848

49-
Also note that :func:`functools.lru_cache` with the *maxsize* of 32768 is used to
50-
cache the compiled regex patterns in the following functions: :func:`fnmatch`,
51-
:func:`fnmatchcase`, :func:`.filter`.
49+
Unless stated otherwise, "filename string" and "pattern string" either refer to
50+
:class:`str` or ``ISO-8859-1`` encoded :class:`bytes` objects. Note that the
51+
functions documented below do not allow to mix a :class:`!bytes` pattern with
52+
a :class:`!str` filename, and vice-versa.
53+
54+
Finally, note that :func:`functools.lru_cache` with a *maxsize* of 32768
55+
is used to cache the (typed) compiled regex patterns in the following
56+
functions: :func:`fnmatch`, :func:`fnmatchcase`, :func:`.filter`.
57+
5258

5359
.. function:: fnmatch(name, pat)
5460

@@ -78,16 +84,16 @@ cache the compiled regex patterns in the following functions: :func:`fnmatch`,
7884

7985
.. function:: filter(names, pat)
8086

81-
Construct a list from those elements of the :term:`iterable` *names*
82-
that match pattern *pat*.
87+
Construct a list from those elements of the :term:`iterable` of filename
88+
strings *names* that match the pattern string *pat*.
8389
It is the same as ``[n for n in names if fnmatch(n, pat)]``,
8490
but implemented more efficiently.
8591

8692

8793
.. function:: translate(pat)
8894

8995
Return the shell-style pattern *pat* converted to a regular expression for
90-
using with :func:`re.match`.
96+
using with :func:`re.match`. The pattern is expected to be a :class:`str`.
9197

9298
Example:
9399

Doc/library/stdtypes.rst

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,6 +1548,100 @@ objects that compare equal might have different :attr:`~range.start`,
15481548
single: str (built-in class); (see also string)
15491549
pair: object; string
15501550

1551+
.. _text-methods-summary:
1552+
1553+
Text and Binary Sequence Type Methods Summary
1554+
=============================================
1555+
The following table summarizes the text and binary sequence types methods by
1556+
category.
1557+
1558+
1559+
+--------------------------+-------------------------------------------+---------------------------------------------------+
1560+
| Category | :class:`str` methods | :class:`bytes` and :class:`bytearray` methods |
1561+
+==========================+===========================================+===================================================+
1562+
| Formatting | :meth:`str.format` | |
1563+
| +-------------------------------------------+---------------------------------------------------+
1564+
| | :meth:`str.format_map` | |
1565+
| +-------------------------------------------+---------------------------------------------------+
1566+
| | :ref:`f-strings` | |
1567+
| +-------------------------------------------+---------------------------------------------------+
1568+
| | :ref:`old-string-formatting` | :ref:`bytes-formatting` |
1569+
+--------------------------+------------------+------------------------+--------------------+------------------------------+
1570+
| Searching and Replacing | :meth:`str.find` | :meth:`str.rfind` | :meth:`bytes.find` | :meth:`bytes.rfind` |
1571+
| +------------------+------------------------+--------------------+------------------------------+
1572+
| | :meth:`str.index`| :meth:`str.rindex` | :meth:`bytes.index`| :meth:`bytes.rindex` |
1573+
| +------------------+------------------------+--------------------+------------------------------+
1574+
| | :meth:`str.startswith` | :meth:`bytes.startswith` |
1575+
| +-------------------------------------------+---------------------------------------------------+
1576+
| | :meth:`str.endswith` | :meth:`bytes.endswith` |
1577+
| +-------------------------------------------+---------------------------------------------------+
1578+
| | :meth:`str.count` | :meth:`bytes.count` |
1579+
| +-------------------------------------------+---------------------------------------------------+
1580+
| | :meth:`str.replace` | :meth:`bytes.replace` |
1581+
+--------------------------+-------------------+-----------------------+---------------------+-----------------------------+
1582+
| Splitting and Joining | :meth:`str.split` | :meth:`str.rsplit` | :meth:`bytes.split` | :meth:`bytes.rsplit` |
1583+
| +-------------------+-----------------------+---------------------+-----------------------------+
1584+
| | :meth:`str.splitlines` | :meth:`bytes.splitlines` |
1585+
| +-------------------------------------------+---------------------------------------------------+
1586+
| | :meth:`str.partition` | :meth:`bytes.partition` |
1587+
| +-------------------------------------------+---------------------------------------------------+
1588+
| | :meth:`str.rpartition` | :meth:`bytes.rpartition` |
1589+
| +-------------------------------------------+---------------------------------------------------+
1590+
| | :meth:`str.join` | :meth:`bytes.join` |
1591+
+--------------------------+-------------------------------------------+---------------------------------------------------+
1592+
| String Classification | :meth:`str.isalpha` | :meth:`bytes.isalpha` |
1593+
| +-------------------------------------------+---------------------------------------------------+
1594+
| | :meth:`str.isdecimal` | |
1595+
| +-------------------------------------------+---------------------------------------------------+
1596+
| | :meth:`str.isdigit` | :meth:`bytes.isdigit` |
1597+
| +-------------------------------------------+---------------------------------------------------+
1598+
| | :meth:`str.isnumeric` | |
1599+
| +-------------------------------------------+---------------------------------------------------+
1600+
| | :meth:`str.isalnum` | :meth:`bytes.isalnum` |
1601+
| +-------------------------------------------+---------------------------------------------------+
1602+
| | :meth:`str.isidentifier` | |
1603+
| +-------------------------------------------+---------------------------------------------------+
1604+
| | :meth:`str.islower` | :meth:`bytes.islower` |
1605+
| +-------------------------------------------+---------------------------------------------------+
1606+
| | :meth:`str.isupper` | :meth:`bytes.isupper` |
1607+
| +-------------------------------------------+---------------------------------------------------+
1608+
| | :meth:`str.istitle` | :meth:`bytes.istitle` |
1609+
| +-------------------------------------------+---------------------------------------------------+
1610+
| | :meth:`str.isspace` | :meth:`bytes.isspace` |
1611+
| +-------------------------------------------+---------------------------------------------------+
1612+
| | :meth:`str.isprintable` | |
1613+
+--------------------------+-------------------------------------------+---------------------------------------------------+
1614+
| Case Manipulation | :meth:`str.lower` | :meth:`bytes.lower` |
1615+
| +-------------------------------------------+---------------------------------------------------+
1616+
| | :meth:`str.upper` | :meth:`bytes.upper` |
1617+
| +-------------------------------------------+---------------------------------------------------+
1618+
| | :meth:`str.casefold` | |
1619+
| +-------------------------------------------+---------------------------------------------------+
1620+
| | :meth:`str.capitalize` | :meth:`bytes.capitalize` |
1621+
| +-------------------------------------------+---------------------------------------------------+
1622+
| | :meth:`str.title` | :meth:`bytes.title` |
1623+
| +-------------------------------------------+---------------------------------------------------+
1624+
| | :meth:`str.swapcase` | :meth:`bytes.swapcase` |
1625+
+--------------------------+-------------------+-----------------------+---------------------+-----------------------------+
1626+
| Padding and Stripping | :meth:`str.ljust` | :meth:`str.rjust` | :meth:`bytes.ljust` | :meth:`bytes.rjust` |
1627+
| +-------------------+-----------------------+---------------------+-----------------------------+
1628+
| | :meth:`str.center` | :meth:`bytes.center` |
1629+
| +-------------------------------------------+---------------------------------------------------+
1630+
| | :meth:`str.expandtabs` | :meth:`bytes.expandtabs` |
1631+
| +-------------------------------------------+---------------------------------------------------+
1632+
| | :meth:`str.strip` | :meth:`bytes.strip` |
1633+
| +--------------------+----------------------+----------------------+----------------------------+
1634+
| | :meth:`str.lstrip` | :meth:`str.rstrip` | :meth:`bytes.lstrip` | :meth:`bytes.rstrip` |
1635+
+--------------------------+--------------------+----------------------+----------------------+----------------------------+
1636+
| Translation and Encoding | :meth:`str.translate` | :meth:`bytes.translate` |
1637+
| +-------------------------------------------+---------------------------------------------------+
1638+
| | :meth:`str.maketrans` | :meth:`bytes.maketrans` |
1639+
| +-------------------------------------------+---------------------------------------------------+
1640+
| | :meth:`str.encode` | |
1641+
| +-------------------------------------------+---------------------------------------------------+
1642+
| | | :meth:`bytes.decode` |
1643+
+--------------------------+-------------------------------------------+---------------------------------------------------+
1644+
15511645
.. _textseq:
15521646

15531647
Text Sequence Type --- :class:`str`

Doc/whatsnew/3.14.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,22 @@ io
717717
file's bytes in full. (Contributed by Cody Maloney and Victor Stinner in
718718
:gh:`120754` and :gh:`90102`.)
719719

720+
721+
uuid
722+
----
723+
724+
* Improve generation of :class:`~uuid.UUID` objects via their dedicated
725+
functions:
726+
727+
* :func:`~uuid.uuid3` and :func:`~uuid.uuid5` are both roughly 40% faster
728+
for 16-byte names and 20% faster for 1024-byte names. Performance for
729+
longer names remains unchanged.
730+
* :func:`~uuid.uuid4` and :func:`~uuid.uuid8` are 30% and 40% faster
731+
respectively.
732+
733+
(Contributed by Bénédikt Tran in :gh:`128150`.)
734+
735+
720736
Deprecated
721737
==========
722738

Include/cpython/object.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,17 +221,27 @@ struct _typeobject {
221221
PyObject *tp_weaklist; /* not used for static builtin types */
222222
destructor tp_del;
223223

224-
/* Type attribute cache version tag. Added in version 2.6 */
224+
/* Type attribute cache version tag. Added in version 2.6.
225+
* If zero, the cache is invalid and must be initialized.
226+
*/
225227
unsigned int tp_version_tag;
226228

227229
destructor tp_finalize;
228230
vectorcallfunc tp_vectorcall;
229231

230232
/* bitset of which type-watchers care about this type */
231233
unsigned char tp_watched;
234+
235+
/* Number of tp_version_tag values used.
236+
* Set to _Py_ATTR_CACHE_UNUSED if the attribute cache is
237+
* disabled for this type (e.g. due to custom MRO entries).
238+
* Otherwise, limited to MAX_VERSIONS_PER_CLASS (defined elsewhere).
239+
*/
232240
uint16_t tp_versions_used;
233241
};
234242

243+
#define _Py_ATTR_CACHE_UNUSED (30000) // (see tp_versions_used)
244+
235245
/* This struct is used by the specializer
236246
* It should be treated as an opaque blob
237247
* by code other than the specializer and interpreter. */

Include/internal/pycore_emscripten_trampoline.h

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,14 @@
2727

2828
#if defined(__EMSCRIPTEN__) && defined(PY_CALL_TRAMPOLINE)
2929

30-
void _Py_EmscriptenTrampoline_Init(_PyRuntimeState *runtime);
30+
void
31+
_Py_EmscriptenTrampoline_Init(_PyRuntimeState *runtime);
3132

3233
PyObject*
33-
_PyEM_TrampolineCall_JavaScript(PyCFunctionWithKeywords func,
34-
PyObject* self,
35-
PyObject* args,
36-
PyObject* kw);
37-
38-
PyObject*
39-
_PyEM_TrampolineCall_Reflection(PyCFunctionWithKeywords func,
40-
PyObject* self,
41-
PyObject* args,
42-
PyObject* kw);
43-
44-
#define _PyEM_TrampolineCall(meth, self, args, kw) \
45-
((_PyRuntime.wasm_type_reflection_available) ? \
46-
(_PyEM_TrampolineCall_Reflection((PyCFunctionWithKeywords)(meth), (self), (args), (kw))) : \
47-
(_PyEM_TrampolineCall_JavaScript((PyCFunctionWithKeywords)(meth), (self), (args), (kw))))
34+
_PyEM_TrampolineCall(PyCFunctionWithKeywords func,
35+
PyObject* self,
36+
PyObject* args,
37+
PyObject* kw);
4838

4939
#define _PyCFunction_TrampolineCall(meth, self, args) \
5040
_PyEM_TrampolineCall( \
@@ -62,8 +52,6 @@ _PyEM_TrampolineCall_Reflection(PyCFunctionWithKeywords func,
6252

6353
#else // defined(__EMSCRIPTEN__) && defined(PY_CALL_TRAMPOLINE)
6454

65-
#define _Py_EmscriptenTrampoline_Init(runtime)
66-
6755
#define _PyCFunction_TrampolineCall(meth, self, args) \
6856
(meth)((self), (args))
6957

Include/internal/pycore_freelist_state.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ extern "C" {
2222
# define Py_futureiters_MAXFREELIST 255
2323
# define Py_object_stack_chunks_MAXFREELIST 4
2424
# define Py_unicode_writers_MAXFREELIST 1
25+
# define Py_pymethodobjects_MAXFREELIST 20
2526

2627
// A generic freelist of either PyObjects or other data structures.
2728
struct _Py_freelist {
@@ -48,6 +49,7 @@ struct _Py_freelists {
4849
struct _Py_freelist futureiters;
4950
struct _Py_freelist object_stack_chunks;
5051
struct _Py_freelist unicode_writers;
52+
struct _Py_freelist pymethodobjects;
5153
};
5254

5355
#ifdef __cplusplus

Include/internal/pycore_magic_number.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ Known values:
265265
Python 3.14a4 3610 (Add VALUE_WITH_FAKE_GLOBALS format to annotationlib)
266266
Python 3.14a4 3611 (Add NOT_TAKEN instruction)
267267
Python 3.14a4 3612 (Add POP_ITER and INSTRUMENTED_POP_ITER)
268+
Python 3.14a4 3613 (Add LOAD_CONST_MORTAL instruction)
268269
269270
Python 3.15 will start with 3650
270271
@@ -277,7 +278,7 @@ PC/launcher.c must also be updated.
277278
278279
*/
279280

280-
#define PYC_MAGIC_NUMBER 3612
281+
#define PYC_MAGIC_NUMBER 3613
281282
/* This is equivalent to converting PYC_MAGIC_NUMBER to 2 bytes
282283
(little-endian) and then appending b'\r\n'. */
283284
#define PYC_MAGIC_NUMBER_TOKEN \

0 commit comments

Comments
 (0)