Skip to content

Commit 89e4668

Browse files
authored
Merge branch 'main' into current-executor
2 parents 01ecf18 + a0bc0c4 commit 89e4668

File tree

75 files changed

+1732
-595
lines changed

Some content is hidden

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

75 files changed

+1732
-595
lines changed

.github/workflows/jit.yml

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -126,29 +126,30 @@ jobs:
126126
make all --jobs 4
127127
./python -m test --multiprocess 0 --timeout 4500 --verbose2 --verbose3
128128
129-
jit-with-disabled-gil:
130-
name: Free-Threaded (Debug)
131-
needs: interpreter
132-
runs-on: ubuntu-24.04
133-
timeout-minutes: 90
134-
strategy:
135-
fail-fast: false
136-
matrix:
137-
llvm:
138-
- 19
139-
steps:
140-
- uses: actions/checkout@v4
141-
with:
142-
persist-credentials: false
143-
- uses: actions/setup-python@v5
144-
with:
145-
python-version: '3.11'
146-
- name: Build with JIT enabled and GIL disabled
147-
run: |
148-
sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)" ./llvm.sh ${{ matrix.llvm }}
149-
export PATH="$(llvm-config-${{ matrix.llvm }} --bindir):$PATH"
150-
./configure --enable-experimental-jit --with-pydebug --disable-gil
151-
make all --jobs 4
152-
- name: Run tests
153-
run: |
154-
./python -m test --multiprocess 0 --timeout 4500 --verbose2 --verbose3
129+
# XXX: GH-133171
130+
# jit-with-disabled-gil:
131+
# name: Free-Threaded (Debug)
132+
# needs: interpreter
133+
# runs-on: ubuntu-24.04
134+
# timeout-minutes: 90
135+
# strategy:
136+
# fail-fast: false
137+
# matrix:
138+
# llvm:
139+
# - 19
140+
# steps:
141+
# - uses: actions/checkout@v4
142+
# with:
143+
# persist-credentials: false
144+
# - uses: actions/setup-python@v5
145+
# with:
146+
# python-version: '3.11'
147+
# - name: Build with JIT enabled and GIL disabled
148+
# run: |
149+
# sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)" ./llvm.sh ${{ matrix.llvm }}
150+
# export PATH="$(llvm-config-${{ matrix.llvm }} --bindir):$PATH"
151+
# ./configure --enable-experimental-jit --with-pydebug --disable-gil
152+
# make all --jobs 4
153+
# - name: Run tests
154+
# run: |
155+
# ./python -m test --multiprocess 0 --timeout 4500 --verbose2 --verbose3

Doc/c-api/object.rst

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,38 @@ Object Protocol
613613
614614
.. versionadded:: 3.14
615615
616+
.. c:function:: int PyUnstable_Object_IsUniqueReferencedTemporary(PyObject *obj)
617+
618+
Check if *obj* is a unique temporary object.
619+
Returns ``1`` if *obj* is known to be a unique temporary object,
620+
and ``0`` otherwise. This function cannot fail, but the check is
621+
conservative, and may return ``0`` in some cases even if *obj* is a unique
622+
temporary object.
623+
624+
If an object is a unique temporary, it is guaranteed that the current code
625+
has the only reference to the object. For arguments to C functions, this
626+
should be used instead of checking if the reference count is ``1``. Starting
627+
with Python 3.14, the interpreter internally avoids some reference count
628+
modifications when loading objects onto the operands stack by
629+
:term:`borrowing <borrowed reference>` references when possible, which means
630+
that a reference count of ``1`` by itself does not guarantee that a function
631+
argument uniquely referenced.
632+
633+
In the example below, ``my_func`` is called with a unique temporary object
634+
as its argument::
635+
636+
my_func([1, 2, 3])
637+
638+
In the example below, ``my_func`` is **not** called with a unique temporary
639+
object as its argument, even if its refcount is ``1``::
640+
641+
my_list = [1, 2, 3]
642+
my_func(my_list)
643+
644+
See also the function :c:func:`Py_REFCNT`.
645+
646+
.. versionadded:: 3.14
647+
616648
.. c:function:: int PyUnstable_IsImmortal(PyObject *obj)
617649
618650
This function returns non-zero if *obj* is :term:`immortal`, and zero

Doc/c-api/refcounting.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ of Python objects.
2323
2424
Use the :c:func:`Py_SET_REFCNT()` function to set an object reference count.
2525
26+
See also the function :c:func:`PyUnstable_Object_IsUniqueReferencedTemporary()`.
27+
2628
.. versionchanged:: 3.10
2729
:c:func:`Py_REFCNT()` is changed to the inline static function.
2830

Doc/library/argparse.rst

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ ArgumentParser objects
7474
prefix_chars='-', fromfile_prefix_chars=None, \
7575
argument_default=None, conflict_handler='error', \
7676
add_help=True, allow_abbrev=True, exit_on_error=True, \
77-
suggest_on_error=False)
77+
*, suggest_on_error=False, color=False)
7878
7979
Create a new :class:`ArgumentParser` object. All parameters should be passed
8080
as keyword arguments. Each parameter has its own more detailed description
@@ -111,14 +111,15 @@ ArgumentParser objects
111111
* add_help_ - Add a ``-h/--help`` option to the parser (default: ``True``)
112112

113113
* allow_abbrev_ - Allows long options to be abbreviated if the
114-
abbreviation is unambiguous. (default: ``True``)
114+
abbreviation is unambiguous (default: ``True``)
115115

116116
* exit_on_error_ - Determines whether or not :class:`!ArgumentParser` exits with
117117
error info when an error occurs. (default: ``True``)
118118

119119
* suggest_on_error_ - Enables suggestions for mistyped argument choices
120120
and subparser names (default: ``False``)
121121

122+
* color_ - Allow color output (default: ``False``)
122123

123124
.. versionchanged:: 3.5
124125
*allow_abbrev* parameter was added.
@@ -130,6 +131,9 @@ ArgumentParser objects
130131
.. versionchanged:: 3.9
131132
*exit_on_error* parameter was added.
132133

134+
.. versionchanged:: 3.14
135+
*suggest_on_error* and *color* parameters were added.
136+
133137
The following sections describe how each of these are used.
134138

135139

@@ -594,7 +598,8 @@ subparser names, the feature can be enabled by setting ``suggest_on_error`` to
594598
``True``. Note that this only applies for arguments when the choices specified
595599
are strings::
596600

597-
>>> parser = argparse.ArgumentParser(description='Process some integers.', suggest_on_error=True)
601+
>>> parser = argparse.ArgumentParser(description='Process some integers.',
602+
suggest_on_error=True)
598603
>>> parser.add_argument('--action', choices=['sum', 'max'])
599604
>>> parser.add_argument('integers', metavar='N', type=int, nargs='+',
600605
... help='an integer for the accumulator')
@@ -612,6 +617,33 @@ keyword argument::
612617
.. versionadded:: 3.14
613618

614619

620+
color
621+
^^^^^
622+
623+
By default, the help message is printed in plain text. If you want to allow
624+
color in help messages, you can enable it by setting ``color`` to ``True``::
625+
626+
>>> parser = argparse.ArgumentParser(description='Process some integers.',
627+
... color=True)
628+
>>> parser.add_argument('--action', choices=['sum', 'max'])
629+
>>> parser.add_argument('integers', metavar='N', type=int, nargs='+',
630+
... help='an integer for the accumulator')
631+
>>> parser.parse_args(['--help'])
632+
633+
Even if a CLI author has enabled color, it can be
634+
:ref:`controlled using environment variables <using-on-controlling-color>`.
635+
636+
If you're writing code that needs to be compatible with older Python versions
637+
and want to opportunistically use ``color`` when it's available, you
638+
can set it as an attribute after initializing the parser instead of using the
639+
keyword argument::
640+
641+
>>> parser = argparse.ArgumentParser(description='Process some integers.')
642+
>>> parser.color = True
643+
644+
.. versionadded:: next
645+
646+
615647
The add_argument() method
616648
-------------------------
617649

Doc/library/ctypes.rst

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2172,10 +2172,20 @@ Utility functions
21722172

21732173
.. function:: POINTER(type, /)
21742174

2175-
Create and return a new ctypes pointer type. Pointer types are cached and
2175+
Create or return a ctypes pointer type. Pointer types are cached and
21762176
reused internally, so calling this function repeatedly is cheap.
21772177
*type* must be a ctypes type.
21782178

2179+
.. impl-detail::
2180+
2181+
The resulting pointer type is cached in the ``__pointer_type__``
2182+
attribute of *type*.
2183+
It is possible to set this attribute before the first call to
2184+
``POINTER`` in order to set a custom pointer type.
2185+
However, doing this is discouraged: manually creating a suitable
2186+
pointer type is difficult without relying on implementation
2187+
details that may change in future Python versions.
2188+
21792189

21802190
.. function:: pointer(obj, /)
21812191

@@ -2340,6 +2350,16 @@ Data types
23402350
library. *name* is the name of the symbol that exports the data, *library*
23412351
is the loaded shared library.
23422352

2353+
Common class variables of ctypes data types:
2354+
2355+
.. attribute:: __pointer_type__
2356+
2357+
The pointer type that was created by calling
2358+
:func:`POINTER` for corresponding ctypes data type. If a pointer type
2359+
was not yet created, the attribute is missing.
2360+
2361+
.. versionadded:: next
2362+
23432363
Common instance variables of ctypes data types:
23442364

23452365
.. attribute:: _b_base_

Doc/library/struct.rst

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -260,24 +260,17 @@ platform-dependent.
260260
+--------+--------------------------+--------------------+----------------+------------+
261261
| ``d`` | :c:expr:`double` | float | 8 | \(4) |
262262
+--------+--------------------------+--------------------+----------------+------------+
263+
| ``F`` | :c:expr:`float complex` | complex | 8 | \(10) |
264+
+--------+--------------------------+--------------------+----------------+------------+
265+
| ``D`` | :c:expr:`double complex` | complex | 16 | \(10) |
266+
+--------+--------------------------+--------------------+----------------+------------+
263267
| ``s`` | :c:expr:`char[]` | bytes | | \(9) |
264268
+--------+--------------------------+--------------------+----------------+------------+
265269
| ``p`` | :c:expr:`char[]` | bytes | | \(8) |
266270
+--------+--------------------------+--------------------+----------------+------------+
267271
| ``P`` | :c:expr:`void \*` | integer | | \(5) |
268272
+--------+--------------------------+--------------------+----------------+------------+
269273

270-
Additionally, if IEC 60559 compatible complex arithmetic (Annex G of the
271-
C11 standard) is supported, the following format characters are available:
272-
273-
+--------+--------------------------+--------------------+----------------+------------+
274-
| Format | C Type | Python type | Standard size | Notes |
275-
+========+==========================+====================+================+============+
276-
| ``F`` | :c:expr:`float complex` | complex | 8 | \(10) |
277-
+--------+--------------------------+--------------------+----------------+------------+
278-
| ``D`` | :c:expr:`double complex` | complex | 16 | \(10) |
279-
+--------+--------------------------+--------------------+----------------+------------+
280-
281274
.. versionchanged:: 3.3
282275
Added support for the ``'n'`` and ``'N'`` formats.
283276

@@ -364,9 +357,14 @@ Notes:
364357
``'0c'`` means 0 characters).
365358

366359
(10)
367-
For the ``'E'`` and ``'C'`` format characters, the packed representation uses
360+
For the ``'F'`` and ``'D'`` format characters, the packed representation uses
368361
the IEEE 754 binary32 and binary64 format for components of the complex
369362
number, regardless of the floating-point format used by the platform.
363+
Note that complex types (``F`` and ``D``) are available unconditionally,
364+
despite complex types being an optional feature in C.
365+
As specified in the C11 standard, each complex type is represented by a
366+
two-element C array containing, respectively, the real and imaginary parts.
367+
370368

371369
A format character may be preceded by an integral repeat count. For example,
372370
the format string ``'4h'`` means exactly the same as ``'hhhh'``.

Doc/library/turtle.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
=================================
2-
:mod:`turtle` --- Turtle graphics
3-
=================================
1+
==================================
2+
:mod:`!turtle` --- Turtle graphics
3+
==================================
44

55
.. module:: turtle
66
:synopsis: An educational framework for simple graphics applications

Doc/library/typing.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
========================================
2-
:mod:`typing` --- Support for type hints
3-
========================================
1+
=========================================
2+
:mod:`!typing` --- Support for type hints
3+
=========================================
44

55
.. testsetup:: *
66

Doc/whatsnew/3.14.rst

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ If you encounter :exc:`NameError`\s or pickling errors coming out of
8989
:mod:`multiprocessing` or :mod:`concurrent.futures`, see the
9090
:ref:`forkserver restrictions <multiprocessing-programming-forkserver>`.
9191

92+
The interpreter avoids some reference count modifications internally when
93+
it's safe to do so. This can lead to different values returned from
94+
:func:`sys.getrefcount` and :c:func:`Py_REFCNT` compared to previous versions
95+
of Python. See :ref:`below <whatsnew314-refcount>` for details.
9296

9397
New features
9498
============
@@ -803,11 +807,16 @@ ctypes
803807
loaded by the current process.
804808
(Contributed by Brian Ward in :gh:`119349`.)
805809

810+
* Move :func:`ctypes.POINTER` types cache from a global internal cache
811+
(``_pointer_type_cache``) to the :attr:`ctypes._CData.__pointer_type__`
812+
attribute of the corresponding :mod:`ctypes` types.
813+
This will stop the cache from growing without limits in some situations.
814+
(Contributed by Sergey Miryanov in :gh:`100926`).
815+
806816
* The :class:`ctypes.py_object` type now supports subscription,
807817
making it a :term:`generic type`.
808818
(Contributed by Brian Schubert in :gh:`132168`.)
809819

810-
811820
datetime
812821
--------
813822

@@ -1309,8 +1318,8 @@ struct
13091318
------
13101319

13111320
* Support the :c:expr:`float complex` and :c:expr:`double complex` C types in
1312-
the :mod:`struct` module (formatting characters ``'F'`` and ``'D'``,
1313-
respectively) if the compiler has C11 complex arithmetic.
1321+
the :mod:`struct` module (formatting characters ``'F'`` and ``'D'``
1322+
respectively).
13141323
(Contributed by Sergey B Kirpichev in :gh:`121249`.)
13151324

13161325

@@ -1372,6 +1381,9 @@ tkinter
13721381
arguments passed by keyword.
13731382
(Contributed by Zhikang Yan in :gh:`126899`.)
13741383

1384+
* Add ability to specify name for :class:`!tkinter.OptionMenu` and
1385+
:class:`!tkinter.ttk.OptionMenu`.
1386+
(Contributed by Zhikang Yan in :gh:`130482`.)
13751387

13761388
turtle
13771389
------
@@ -1672,6 +1684,13 @@ Deprecated
16721684
:func:`codecs.open` is now deprecated. Use :func:`open` instead.
16731685
(Contributed by Inada Naoki in :gh:`133036`.)
16741686

1687+
* :mod:`ctypes`:
1688+
Calling :func:`ctypes.POINTER` on a string is deprecated.
1689+
Use :ref:`ctypes-incomplete-types` for self-referential structures.
1690+
Also, the internal ``ctypes._pointer_type_cache`` is deprecated.
1691+
See :func:`ctypes.POINTER` for updated implementation details.
1692+
(Contributed by Sergey Myrianov in :gh:`100926`.)
1693+
16751694
* :mod:`functools`:
16761695
Calling the Python implementation of :func:`functools.reduce` with *function*
16771696
or *sequence* as keyword arguments is now deprecated.
@@ -2212,6 +2231,11 @@ New features
22122231
take a C integer and produce a Python :class:`bool` object. (Contributed by
22132232
Pablo Galindo in :issue:`45325`.)
22142233

2234+
* Add :c:func:`PyUnstable_Object_IsUniqueReferencedTemporary` to determine if an object
2235+
is a unique temporary object on the interpreter's operand stack. This can
2236+
be used in some cases as a replacement for checking if :c:func:`Py_REFCNT`
2237+
is ``1`` for Python objects passed as arguments to C API functions.
2238+
22152239

22162240
Limited C API changes
22172241
---------------------
@@ -2246,6 +2270,17 @@ Porting to Python 3.14
22462270
a :exc:`UnicodeError` object.
22472271
(Contributed by Bénédikt Tran in :gh:`127691`.)
22482272

2273+
.. _whatsnew314-refcount:
2274+
2275+
* The interpreter internally avoids some reference count modifications when
2276+
loading objects onto the operands stack by :term:`borrowing <borrowed reference>`
2277+
references when possible. This can lead to smaller reference count values
2278+
compared to previous Python versions. C API extensions that checked
2279+
:c:func:`Py_REFCNT` of ``1`` to determine if an function argument is not
2280+
referenced by any other code should instead use
2281+
:c:func:`PyUnstable_Object_IsUniqueReferencedTemporary` as a safer replacement.
2282+
2283+
22492284
* Private functions promoted to public C APIs:
22502285

22512286
* ``_PyBytes_Join()``: :c:func:`PyBytes_Join`.

Include/cpython/object.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,11 @@ PyAPI_FUNC(PyRefTracer) PyRefTracer_GetTracer(void**);
476476
*/
477477
PyAPI_FUNC(int) PyUnstable_Object_EnableDeferredRefcount(PyObject *);
478478

479+
/* Determine if the object exists as a unique temporary variable on the
480+
* topmost frame of the interpreter.
481+
*/
482+
PyAPI_FUNC(int) PyUnstable_Object_IsUniqueReferencedTemporary(PyObject *);
483+
479484
/* Check whether the object is immortal. This cannot fail. */
480485
PyAPI_FUNC(int) PyUnstable_IsImmortal(PyObject *);
481486

0 commit comments

Comments
 (0)