Skip to content

Commit 325c6c0

Browse files
authored
Merge branch 'main' into fix-json-str-subclass-separators
2 parents c79e48e + 5dbe2ac commit 325c6c0

87 files changed

Lines changed: 4231 additions & 891 deletions

File tree

Some content is hidden

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

‎Doc/c-api/gcsupport.rst‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,13 @@ The :c:member:`~PyTypeObject.tp_traverse` handler must have the following type:
253253
returned immediately.
254254
Otherwise, return zero.
255255
256+
The garbage collector can call :c:member:`~PyTypeObject.tp_traverse` more
257+
than once for the same object during a collection. If the object's
258+
references do not change, each traversal must visit the same references.
259+
In particular, do not skip a reference because a lock is busy.
260+
If one traversal visits a reference and a later traversal skips it, the
261+
collector can clear an object that is still reachable.
262+
256263
A typical :c:member:`!tp_traverse` function calls the :c:func:`Py_VISIT`
257264
convenience macro on each of the instance's members that are Python
258265
objects that the instance owns.
@@ -318,14 +325,6 @@ The :c:member:`~PyTypeObject.tp_traverse` handler must have the following type:
318325
For a list of safe functions, see a
319326
:ref:`separate section <duringgc-functions>` below.
320327
321-
If an error occurs during traversal, ignore it and return 0.
322-
If ``tp_traverse`` fails to visit some strong references, garbage reference
323-
cycles involving the skipped references will not be reliably broken,
324-
but correctness won't be affected.
325-
For example, if traversal requires a lock that cannot be acquired promptly,
326-
skip the traversal.
327-
The garbage collector will visit your object again in a future pass.
328-
329328
.. note::
330329
331330
The :c:func:`Py_VISIT` call may be skipped for those members that provably

‎Doc/library/decimal.rst‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,6 +1777,8 @@ condition.
17771777
0 ** 0
17781778
x ** (non-integer)
17791779
x ** Infinity
1780+
NaN >= 0
1781+
NaN < 0
17801782

17811783

17821784
.. class:: Overflow
@@ -1906,6 +1908,8 @@ expanding the precision sufficiently to avoid loss of significance:
19061908
Decimal('0.0060000')
19071909

19081910

1911+
.. _decimal-notes-specials:
1912+
19091913
Special values
19101914
^^^^^^^^^^^^^^
19111915

‎Doc/library/logging.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ wire).
919919
:param exc_info: An exception tuple with the current exception information,
920920
as returned by :func:`sys.exc_info`,
921921
or ``None`` if no exception information is available.
922-
:type exc_info: tuple[type[BaseException], BaseException, types.TracebackType] | None
922+
:type exc_info: tuple[type[BaseException], BaseException, types.TracebackType | None] | tuple[None, None, None] | None
923923

924924
:param func: The name of the function or method
925925
from which the logging call was invoked.

‎Doc/library/tkinter.rst‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ demonstrating a simple Tk interface, letting you know that :mod:`!tkinter` is
1717
properly installed on your system, and also showing what version of Tcl/Tk is
1818
installed, so you can read the Tcl/Tk documentation specific to that version.
1919

20-
Tkinter supports a range of Tcl/Tk versions, built either with or without
20+
Tkinter supports a range of Tcl/Tk versions, which must be built with
2121
thread support.
2222
Tcl/Tk 8.5.12 is the minimum supported version; the official Python binary
2323
release bundles Tcl/Tk 9.0.
@@ -27,6 +27,9 @@ supported versions.
2727
.. versionchanged:: 3.11
2828
Support for Tcl/Tk versions older than 8.5.12 was removed.
2929

30+
.. versionchanged:: next
31+
Support for Tcl/Tk built without thread support was removed.
32+
3033
Tkinter is not a thin wrapper, but adds a fair amount of its own logic to
3134
make the experience more pythonic. This documentation will concentrate on these
3235
additions and changes, and refer to the official Tcl/Tk documentation for
@@ -476,18 +479,11 @@ interpreter will fail.
476479

477480
A number of special cases exist:
478481

479-
* Tcl/Tk libraries built without thread support are now rare: Tcl/Tk 9.0 (the
480-
bundled version) is always thread-aware, so this case only arises with some
481-
older 8.x builds. When the library is not thread-aware,
482-
:mod:`!tkinter` calls the library from the originating Python thread, even
483-
if this is different than the thread that created the Tcl interpreter. A global
484-
lock ensures only one call occurs at a time.
485-
486482
* While :mod:`!tkinter` allows you to create more than one instance of a :class:`Tk`
487483
object (with its own interpreter), all interpreters that are part of the same
488484
thread share a common event queue, which gets ugly fast. In practice, don't create
489485
more than one instance of :class:`Tk` at a time. Otherwise, it's best to create
490-
them in separate threads and ensure you're running a thread-aware Tcl/Tk build.
486+
them in separate threads.
491487

492488
* Blocking event handlers are not the only way to prevent the Tcl interpreter from
493489
reentering the event loop. It is even possible to run multiple nested event loops

‎Doc/reference/expressions.rst‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2129,12 +2129,15 @@ built-in types.
21292129
involved, they compare mathematically (algorithmically) correct without loss
21302130
of precision.
21312131

2132-
The not-a-number values ``float('NaN')`` and ``decimal.Decimal('NaN')`` are
2132+
The not-a-number floating-point numbers, like ``float('NaN')``, are
21332133
special. Any ordered comparison of a number to a not-a-number value is false.
21342134
A counter-intuitive implication is that not-a-number values are not equal to
21352135
themselves. For example, if ``x = float('NaN')``, ``3 < x``, ``x < 3`` and
21362136
``x == x`` are all false, while ``x != x`` is true. This behavior is
2137-
compliant with IEEE 754.
2137+
compliant with IEEE 754. Similar behavior holds for
2138+
:class:`decimal.Decimal`'s not-a-number values, like ``Decimal('NaN')``.
2139+
Refer to the :ref:`Special values <decimal-notes-specials>` section
2140+
of the :mod:`decimal` documentation.
21382141

21392142
* ``None`` and :data:`NotImplemented` are singletons. :PEP:`8` advises that
21402143
comparisons for singletons should always be done with ``is`` or ``is not``,

‎Doc/whatsnew/3.16.rst‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,6 +1525,12 @@ Build changes
15251525

15261526
(Contributed by Stefano Rivera in :gh:`131372`.)
15271527

1528+
* The paths in the installed ``build-details.json`` file (:pep:`739`) are
1529+
now relative to the file's location instead of absolute, so the file stays
1530+
correct when the installation is moved.
1531+
1532+
(Contributed by Itamar Oren in :gh:`119696`.)
1533+
15281534
* Add the :option:`--with-curses` :program:`configure` option to select the
15291535
curses backend for the :mod:`curses` and :mod:`curses.panel` modules.
15301536
In addition to ``ncursesw`` and ``ncurses``, it can now build against the
@@ -1555,6 +1561,12 @@ Build changes
15551561

15561562
(Contributed by Russell Keith-Magee in :gh:`159385`.)
15571563

1564+
* :mod:`tkinter` now requires Tcl/Tk built with thread support.
1565+
This only affects Tcl/Tk 8, since Tcl/Tk 9 is always built with
1566+
thread support.
1567+
1568+
(Contributed by Michiel de Hoon in :gh:`140494`.)
1569+
15581570

15591571
.. _whatsnew316-apple-platforms:
15601572

‎Include/cpython/pyatomic.h‎

Lines changed: 124 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
// Operations are sequentially consistent unless they have a suffix indicating
55
// otherwise. If in doubt, prefer the sequentially consistent operations.
66
//
7-
// The "_relaxed" suffix for load and store operations indicates the "relaxed"
8-
// memory order. They don't provide synchronization, but (roughly speaking)
9-
// guarantee somewhat sane behavior for races instead of undefined behavior.
10-
// In practice, they correspond to "normal" hardware load and store
7+
// The "_relaxed" suffix indicates the "relaxed" memory order. Relaxed
8+
// operations don't provide synchronization, but (roughly speaking) guarantee
9+
// somewhat sane behavior for races instead of undefined behavior. In practice,
10+
// relaxed loads and stores correspond to "normal" hardware load and store
1111
// instructions, so they are almost as inexpensive as plain loads and stores
12-
// in C.
12+
// in C. Relaxed read-modify-write operations, such as
13+
// _Py_atomic_add_*_relaxed, are still atomic, but do not order surrounding
14+
// memory accesses.
1315
//
1416
// Note that atomic read-modify-write operations like _Py_atomic_add_* return
1517
// the previous value of the atomic variable, not the new value.
@@ -49,12 +51,27 @@
4951
// expected = obj
5052
// return False
5153
//
54+
// def _Py_atomic_compare_exchange_relaxed(obj, expected, desired):
55+
// # relaxed consistency
56+
// if obj == expected:
57+
// obj = desired
58+
// return True
59+
// else:
60+
// expected = obj
61+
// return False
62+
//
5263
// def _Py_atomic_add(obj, value):
5364
// # sequential consistency
5465
// old_obj = obj
5566
// obj += value
5667
// return old_obj
5768
//
69+
// def _Py_atomic_add_relaxed(obj, value):
70+
// # relaxed consistency
71+
// old_obj = obj
72+
// obj += value
73+
// return old_obj
74+
//
5875
// def _Py_atomic_and(obj, value):
5976
// # sequential consistency
6077
// old_obj = obj
@@ -130,6 +147,50 @@ static inline Py_ssize_t
130147
_Py_atomic_add_ssize(Py_ssize_t *obj, Py_ssize_t value);
131148

132149

150+
// --- _Py_atomic_add_relaxed ------------------------------------------------
151+
// Atomically adds `value` to `obj` and returns the previous value
152+
// (relaxed consistency, i.e., no ordering)
153+
154+
static inline int
155+
_Py_atomic_add_int_relaxed(int *obj, int value);
156+
157+
static inline int8_t
158+
_Py_atomic_add_int8_relaxed(int8_t *obj, int8_t value);
159+
160+
static inline int16_t
161+
_Py_atomic_add_int16_relaxed(int16_t *obj, int16_t value);
162+
163+
static inline int32_t
164+
_Py_atomic_add_int32_relaxed(int32_t *obj, int32_t value);
165+
166+
static inline int64_t
167+
_Py_atomic_add_int64_relaxed(int64_t *obj, int64_t value);
168+
169+
static inline intptr_t
170+
_Py_atomic_add_intptr_relaxed(intptr_t *obj, intptr_t value);
171+
172+
static inline unsigned int
173+
_Py_atomic_add_uint_relaxed(unsigned int *obj, unsigned int value);
174+
175+
static inline uint8_t
176+
_Py_atomic_add_uint8_relaxed(uint8_t *obj, uint8_t value);
177+
178+
static inline uint16_t
179+
_Py_atomic_add_uint16_relaxed(uint16_t *obj, uint16_t value);
180+
181+
static inline uint32_t
182+
_Py_atomic_add_uint32_relaxed(uint32_t *obj, uint32_t value);
183+
184+
static inline uint64_t
185+
_Py_atomic_add_uint64_relaxed(uint64_t *obj, uint64_t value);
186+
187+
static inline uintptr_t
188+
_Py_atomic_add_uintptr_relaxed(uintptr_t *obj, uintptr_t value);
189+
190+
static inline Py_ssize_t
191+
_Py_atomic_add_ssize_relaxed(Py_ssize_t *obj, Py_ssize_t value);
192+
193+
133194
// --- _Py_atomic_compare_exchange -------------------------------------------
134195
// Performs an atomic compare-and-exchange.
135196
//
@@ -185,6 +246,64 @@ static inline int
185246
_Py_atomic_compare_exchange_ptr(void *obj, void *expected, void *value);
186247

187248

249+
// --- _Py_atomic_compare_exchange_relaxed -----------------------------------
250+
// Performs an atomic compare-and-exchange (relaxed consistency, i.e., no
251+
// ordering on either success or failure).
252+
//
253+
// - If `*obj` and `*expected` are equal, store `desired` into `*obj`
254+
// and return 1 (success).
255+
// - Otherwise, store the `*obj` current value into `*expected`
256+
// and return 0 (failure).
257+
//
258+
// These correspond to the C11 atomic_compare_exchange_strong_explicit()
259+
// function with memory_order_relaxed for both the success and failure
260+
// memory orders.
261+
262+
static inline int
263+
_Py_atomic_compare_exchange_int_relaxed(int *obj, int *expected, int desired);
264+
265+
static inline int
266+
_Py_atomic_compare_exchange_int8_relaxed(int8_t *obj, int8_t *expected, int8_t desired);
267+
268+
static inline int
269+
_Py_atomic_compare_exchange_int16_relaxed(int16_t *obj, int16_t *expected, int16_t desired);
270+
271+
static inline int
272+
_Py_atomic_compare_exchange_int32_relaxed(int32_t *obj, int32_t *expected, int32_t desired);
273+
274+
static inline int
275+
_Py_atomic_compare_exchange_int64_relaxed(int64_t *obj, int64_t *expected, int64_t desired);
276+
277+
static inline int
278+
_Py_atomic_compare_exchange_intptr_relaxed(intptr_t *obj, intptr_t *expected, intptr_t desired);
279+
280+
static inline int
281+
_Py_atomic_compare_exchange_uint_relaxed(unsigned int *obj, unsigned int *expected, unsigned int desired);
282+
283+
static inline int
284+
_Py_atomic_compare_exchange_uint8_relaxed(uint8_t *obj, uint8_t *expected, uint8_t desired);
285+
286+
static inline int
287+
_Py_atomic_compare_exchange_uint16_relaxed(uint16_t *obj, uint16_t *expected, uint16_t desired);
288+
289+
static inline int
290+
_Py_atomic_compare_exchange_uint32_relaxed(uint32_t *obj, uint32_t *expected, uint32_t desired);
291+
292+
static inline int
293+
_Py_atomic_compare_exchange_uint64_relaxed(uint64_t *obj, uint64_t *expected, uint64_t desired);
294+
295+
static inline int
296+
_Py_atomic_compare_exchange_uintptr_relaxed(uintptr_t *obj, uintptr_t *expected, uintptr_t desired);
297+
298+
static inline int
299+
_Py_atomic_compare_exchange_ssize_relaxed(Py_ssize_t *obj, Py_ssize_t *expected, Py_ssize_t desired);
300+
301+
// NOTE: `obj` and `expected` are logically `void**` types, but we use `void*`
302+
// so that we can pass types like `PyObject**` without a cast.
303+
static inline int
304+
_Py_atomic_compare_exchange_ptr_relaxed(void *obj, void *expected, void *value);
305+
306+
188307
// --- _Py_atomic_exchange ---------------------------------------------------
189308
// Atomically replaces `*obj` with `value` and returns the previous value of `*obj`.
190309

0 commit comments

Comments
 (0)