Commit graph

8923 commits

Author SHA1 Message Date
Alex Waygood
7756f59892
[3.14] gh-150319: Replace all documentation which says "See PEP 585" (#150325) (#150813)
gh-150319: Replace all documentation which says "See PEP 585" (#150325)

* Replace all documentation which says "See PEP 585"

The following classes in the stdlib get simple updates:

- array.array
- asyncio.Future
- asyncio.Task
- collections.defaultdict
- collections.deque
- contextvars.ContextVar
- contextvars.Token
- ctypes.Array
- os.DirEntry
- re.Match
- re.Pattern
- string.templatelib.Interpolation
- string.templatelib.Template
- types.MappingProxyType
- queue.SimpleQueue
- weakref.ref

The following classes are documented publicly as functions, and are
therefore updated internally (`__class_getitem__.__doc__`) but not in the
public docs:

- functools.partial
- itertools.chain

The following builtin types have updates to `__class_getitem__.__doc__`
but not to any documentation pages:

- BaseExceptionGroup
- coroutines (from generators)
- dict
- enumerate
- frozendict
- frozenset
- generators (and async generators)
- list
- memoryview
- set
- slice
- tuple

Special cases:

- union objects are now documented as "supporting class-level []",
  rather than anything to do with generics.

- Templates might be generic over a single type (union, in theory) or
  over a TypeVarTuple. As this is not currently fully settled, it is
  marked with a comment and a mild hint that it is a single type is used
  (namely, "type" is singular rather than "types", plural)

* Apply suggestions from code review



* Correct several class getitem docs

And expand the text for tuples.



* Add notes on generic typing of builtins

* Fix typo in tuple.__class_getitem__ docstring

* Typo fix: malformed refs

Fix `generic` links which weren't marked as `:ref:`.

* Strike unnecessary docs on generic-ness



* Apply suggestions from code review

These are applied at both the originally indicated locations and in the
corresponding docstring definitions.



* Update Doc/library/re.rst



* Update Objects/enumobject.c



* Remove tuple generic doc in 'stdtypes' page

This is covered in more detail in the cross-linked typing documentation.
The other copy of this documentation -- in the docstring for
`tuple.__class_getitem__` -- is left in place.

* Fix whitespace around new doc of generics

Per review, do not introduce or remove whitespace such that section
breaks are altered by the introduction of doc on various generic types.

In most cases, this is a removal of an extra line.

In one case (Arrays), it is the reintroduction of a line.

Additionally, two other minor fixes are included:
- incorrect indent on 'defaultdicts'
- make `mappingproxy.__class_getitem__.__doc__` consistent with other
  mapping type generic docs



* Move placement of memoryview generic note

Previous placement was at the end of the main docstring, which is
consistent with other types but places it after a section on various
methods (which makes it read somewhat inconsistently). Moving it up
helps resolve.



* Ensure sphinxdoc does not start sentences lowercase

Lowercase class names at the start of sentences are marked out with the
`class` role. In the case of `deque`, documentation already refers to
these as `Deques`, so this form is preferred.

* Apply suggestions from code review



* Fix line endings and wrap more tightly

Line endings fixed by pre-commit ; also re-wrapped the MappingProxyType
text which was too long.

* Use 'ContextVars' style in sphinx doc

---------

Co-authored-by: Stephen Rosen <sirosen@globus.org>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Jelle Zijlstra <906600+JelleZijlstra@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2026-06-02 22:22:46 +00:00
Serhiy Storchaka
730fc6a858
[3.14] gh-150285: Fix too long docstrings in builtins (GH-150293) (GH-150466)
(cherry picked from commit e1e06be119)
2026-05-26 10:05:49 +00:00
Hai Zhu
86ffaf125f
[3.14] gh-148450: abc.register needs to update type_version when tp_flags is changed (GH-148623) (#150308) 2026-05-23 12:01:57 +00:00
sobolevn
1d4f9ab0c6
[3.14] gh-149816: Fix a race condition in _PyBytes_FromList with free-threading (GH-149909) (#149912)
(cherry picked from commit 46afba7b93)
2026-05-21 09:53:54 +00:00
Miss Islington (bot)
afb12ccbef
[3.14] gh-150146: Fix NULL dereference in _Py_subs_parameters (GH-150147) (#150154)
gh-150146: Fix NULL dereference in `_Py_subs_parameters` (GH-150147)
(cherry picked from commit f621ba16b7)

Co-authored-by: sobolevn <mail@sobolevn.me>
2026-05-20 13:54:20 +00:00
Miss Islington (bot)
76ecef8099
[3.14] gh-149816: Fix race condition in memoryview with free-threading (GH-149858) (#149876)
gh-149816: Fix race condition in `memoryview` with free-threading (GH-149858)
(cherry picked from commit 1fdf033774)

Co-authored-by: sobolevn <mail@sobolevn.me>
2026-05-15 13:04:32 +00:00
Sam Gross
d6b6fd70c4
[3.14] gh-145235: Make dict watcher API thread-safe for free-threaded builds (gh-145233) (#149691)
In free-threaded builds, concurrent calls to PyDict_AddWatcher, PyDict_ClearWatcher, PyDict_Watch, and PyDict_Unwatch can race on the shared callback array and the per-dict watcher tags. This change adds a mutex to serialize watcher registration and removal, atomic operations for tag updates, and atomic acquire/release synchronization for callback dispatch in _PyDict_SendEvent.

(cherry picked from commit 8a4895985f)

Co-authored-by: Alper <alperyoney@fb.com>
2026-05-12 13:21:31 -04:00
Stan Ulbrych
454401c8e9
[3.14] gh-148390: fix undefined behavior of memoryview(...).cast("?") (GH-148454) (GH-148667)
(cherry picked from commit 69e0a78e6e)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2026-05-01 17:43:59 +02:00
Sam Gross
26c6e3d7e3
[3.14] gh-113956: Make intern_common thread-safe in free-threaded build (gh-148886) (#148927)
Avoid racing with the owning thread's refcount operations when
immortalizing an interned string: if we don't own it and its refcount
isn't merged, intern a copy we own instead. Use atomic stores in
_Py_SetImmortalUntracked so concurrent atomic reads are race-free.

(cherry picked from commit 4629c2215a)
2026-04-23 19:12:19 +00:00
Miss Islington (bot)
67100b3e92
[3.14] gh-148222: Fix NULL dereference bugs in genericaliasobject.c (GH-148226) (#148705)
gh-148222: Fix NULL dereference bugs in genericaliasobject.c (GH-148226)
(cherry picked from commit 634568d030)

Co-authored-by: Prakash Sellathurai <prakashsellathurai@gmail.com>
2026-04-18 00:47:06 +00:00
Miss Islington (bot)
a89b2419e0
[3.14] gh-148393: Use atomic ops on _ma_watcher_tag in free threading build (gh-148397) (#148451)
Fixes data races between dict mutation and watch/unwatch on the same dict.
(cherry picked from commit 3ab94d6842)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2026-04-12 15:05:34 +00:00
Miss Islington (bot)
a9d122fb05
[3.14] gh-148208: Fix recursion depth leak in PyObject_Print (GH-148209) (#148412)
gh-148208: Fix recursion depth leak in `PyObject_Print` (GH-148209)
(cherry picked from commit e2fa10e04d)

Co-authored-by: Wulian233 <1055917385@qq.com>
2026-04-12 00:52:21 +00:00
Kumar Aditya
f36da66c71
[3.14] gh-148037: remove critical section from PyCode_Addr2Line (GH… (#148353)
[3.14] gh-148037: remove critical section from `PyCode_Addr2Line` (GH-148103)
(cherry picked from commit d3b7b93cbb)
2026-04-10 23:59:38 +05:30
Miss Islington (bot)
bb78ec8fa8
[3.14] gh-148274: properly handle result from PyObject_VisitManagedDict (GH-148275) (#148295)
gh-148274: properly handle result from `PyObject_VisitManagedDict` (GH-148275)
(cherry picked from commit ee2775cfae)

Co-authored-by: Max Bachmann <kontakt@maxbachmann.de>
2026-04-09 13:49:09 +00:00
Miss Islington (bot)
61c919cf1b
[3.14] gh-148074: Fix typeobject.c missing error return (GH-148075) (#148095)
gh-148074: Fix `typeobject.c` missing error return (GH-148075)
(cherry picked from commit c398490fbf)

Co-authored-by: Wulian233 <1055917385@qq.com>
2026-04-04 16:01:34 +00:00
Miss Islington (bot)
25b48b84b8
[3.14] gh-143050: Correct PyLong_FromString() to use _PyLong_Negate() (GH-145901) (#147331)
gh-143050: Correct PyLong_FromString() to use _PyLong_Negate() (GH-145901)

The long_from_string_base() might return a small integer, when the
_pylong.py is used to do conversion.  Hence, we must be careful here to
not smash it "small int" bit by using the _PyLong_FlipSign().
(cherry picked from commit db5936c5b8)

Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2026-03-31 16:14:12 +02:00
Miss Islington (bot)
e387bac1a4
[3.14] gh-126835: Fix _PY_IS_SMALL_INT() macro (GH-146631) (#147187)
gh-126835: Fix _PY_IS_SMALL_INT() macro (GH-146631)
(cherry picked from commit adf2c47911)

Co-authored-by: Victor Stinner <vstinner@python.org>
2026-03-31 13:27:11 +00:00
Miss Islington (bot)
e5ec90e021
[3.14] gh-146615: Fix format specifiers in Objects/ directory (GH-146620) (GH-146651)
(cherry picked from commit bbf7fb2c15)

Co-authored-by: sunmy2019 <59365878+sunmy2019@users.noreply.github.com>
2026-03-31 09:17:58 +00:00
Miss Islington (bot)
ed557e6a5f
[3.14] gh-146615: Fix crash in __get__() for METH_METHOD descriptors with invalid type argument (GH-146634) (GH-146647)
(cherry picked from commit 72d29ea363)

Co-authored-by: sunmy2019 <59365878+sunmy2019@users.noreply.github.com>
2026-03-31 08:20:00 +00:00
Miss Islington (bot)
3c434f7f0f
[3.14] gh-146250: Fix memory leak in re-initialization of SyntaxError (GH-146251) (#146517)
Co-authored-by: Brij Kapadia <97006829+bkap123@users.noreply.github.com>
2026-03-30 16:14:58 +00:00
Sergey Miryanov
ed38c20dd3
[3.14] Fix possible memory leak in OrderedDict popitem (GH-145247) (#146537) 2026-03-27 21:40:50 +00:00
Sam Gross
f2b5131d1a
[3.14] gh-146041: Avoid lock in sys.intern() for already interned strings (gh-146072) (#146390)
Fix free-threading scaling bottleneck in sys.intern and `PyObject_SetAttr` by
avoiding the interpreter-wide lock when the string is already interned and
immortalized.

(cherry picked from commit 60093096ba)
2026-03-24 21:42:19 -04:00
dr-carlos
dd4ea46917
[3.14] gh-141732: Fix ExceptionGroup repr changing when original exception sequence is mutated (GH-141736) (GH-144445)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2026-03-23 23:31:32 +01:00
Serhiy Storchaka
796513306f
[3.14] gh-146056: Fix repr() for lists and tuples containing NULLs (GH-146129) (GH-146155)
(cherry picked from commit 0f2246b155)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2026-03-22 09:25:02 +02:00
Victor Stinner
6e73225c32
[3.14] gh-146196: Fix Undefined Behavior in _PyUnicodeWriter_WriteASCIIString() (#146201) (#146220)
gh-146196: Fix Undefined Behavior in _PyUnicodeWriter_WriteASCIIString() (#146201)

Avoid calling memcpy(data + writer->pos, NULL, 0)
which has an undefined behavior.


(cherry picked from commit cd10a2e65c)

Co-authored-by: Shamil <ashm.tech@proton.me>
2026-03-20 16:26:18 +00:00
Sam Gross
fa3143a1d2
[3.14] gh-145779: Improve classmethod/staticmethod scaling in free-threaded build (gh-145826) (#146088)
Add special cases for classmethod and staticmethod descriptors in
_PyObject_GetMethodStackRef() to avoid calling tp_descr_get, which
avoids reference count contention on the bound method and underlying
callable. This improves scaling when calling classmethods and
staticmethods from multiple threads.

Also refactor method_vectorcall in classobject.c into a new
_PyObject_VectorcallPrepend() helper so that it can be used by
PyObject_VectorcallMethod as well.

(cherry picked from commit e0f7c1097e)
2026-03-19 10:49:12 -04:00
Victor Stinner
7f29c1d0da
[3.14] gh-146092: Fix error handling in _BINARY_OP_ADD_FLOAT opcode (#146119)
Fix error handling in _PyFloat_FromDouble_ConsumeInputs() used by
_BINARY_OP_ADD_FLOAT, _BINARY_OP_SUBTRACT_FLOAT and
_BINARY_OP_MULTIPLY_FLOAT opcodes. PyStackRef_FromPyObjectSteal()
must not be called with a NULL pointer.

Fix also _BINARY_OP_INPLACE_ADD_UNICODE opcode.
2026-03-19 12:14:33 +01:00
Victor Stinner
8eeb800faf
[3.14] gh-146092: Handle _PyFrame_GetFrameObject() failures properly (#146124) (#146132)
gh-146092: Handle _PyFrame_GetFrameObject() failures properly (#146124)

* Fix _PyFrame_GetLocals() and _PyFrame_GetLocals() error handling.
* _PyEval_ExceptionGroupMatch() now fails on _PyFrame_GetLocals()
  error.

(cherry picked from commit e1e4852133)
2026-03-18 17:57:08 +00:00
Sam Gross
b3c2ef5f31
[3.14] gh-134043: use stackrefs for dict lookup in _PyObject_GetMethodStackRef (GH-136412) (#146077)
(cherry picked from commit cbe6ebe15b)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2026-03-17 16:59:26 -04:00
Serhiy Storchaka
a005f323b7
[3.14] gh-144545: Improve handling of default values in Argument Clinic (GH-146016) (GH-146052)
* Add the c_init_default attribute which is used to initialize the C variable
  if the default is not explicitly provided.
* Add the c_default_init() method which is used to derive c_default from
  default if c_default is not explicitly provided.
* Explicit c_default and py_default are now almost always have precedence
  over the generated value.
* Add support for bytes literals as default values.
* Improve support for str literals as default values (support non-ASCII
  and non-printable characters and special characters like backslash or quotes).
* Fix support for str and bytes literals containing trigraphs, "/*" and "*/".
* Improve support for default values in converters "char" and "int(accept={str})".
* Converter "int(accept={str})" now requires 1-character string instead of
  integer as default value.
* Add support for non-None default values in converter "Py_buffer": NULL,
  str and bytes literals.
* Improve error handling for invalid default values.
* Rename Null to NullType for consistency.
(cherry picked from commit 99e2c5eccd)
2026-03-17 10:55:15 +00:00
Miss Islington (bot)
cccd9dd3e4
[3.14] gh-145376: Fix GC tracking in structseq.__replace__ (GH-145820) (#145922)
gh-145376: Fix GC tracking in `structseq.__replace__` (GH-145820)
(cherry picked from commit 00a25859a9)

Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
2026-03-16 14:38:15 +05:30
Miss Islington (bot)
1749b3c686
[3.14] gh-143636: fix a crash when calling `__replace__ on invalid SimpleNamespace` instances (GH-143655) (#145938)
gh-143636: fix a crash when calling ``__replace__`` on invalid `SimpleNamespace` instances (GH-143655)
(cherry picked from commit 97968564b6)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2026-03-14 10:35:41 +00:00
Thomas Kowalski
c3ea6c291e
[3.14] gh-145713: make bytearray.resize thread-safe on free-threading (#145714) (#145799)
gh-145713: make bytearray.resize thread-safe on free-threading (#145714)


(cherry picked from commit c3955e049f)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2026-03-13 20:34:24 +05:30
bkap123
2af2a38302
[3.14] gh-145036: Fix data race for list capacity in free-threading (GH-145365) (#145881)
(cherry picked from commit 9e0802330c)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2026-03-12 22:06:12 -04:00
Miss Islington (bot)
cedff2d617
[3.14] gh-145685: Improve scaling of type attribute lookups (gh-145774) (#145874)
Avoid locking in the PyType_Lookup cache-miss path if the type's
tp_version_tag is already valid.

(cherry picked from commit cd52172831)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2026-03-12 14:33:05 -04:00
Sam Gross
6d28aaf24d
[3.14] gh-145685: Avoid contention on TYPE_LOCK in super() lookups (gh-145775) (#145804)
(cherry picked from commit bdf6de8c3f)
2026-03-11 11:50:13 +00:00
Miss Islington (bot)
e7bc1526ca
[3.14] gh-145685: Update find_name_in_mro() to return a _PyStackRef (gh-145693) (#145769)
(cherry picked from commit f26eca7732)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2026-03-10 15:25:46 -04:00
Sam Gross
54024655ae
[3.14] gh-145685: Stop the world when updating MRO of existing types (gh-145707) (#145715)
We already have a stop-the-world pause elsewhere in this code path
(type_set_bases) and this makes will make it easier to avoid contention
on the TYPE_LOCK when looking up names in the MRO hierarchy.

Also use deferred reference counting for non-immortal MROs.
(cherry picked from commit 0b65c88c2a)
2026-03-10 09:31:52 -04:00
Miss Islington (bot)
ba1ea3a85a
[3.14] gh-145615: Fix mimalloc page leak in the free-threaded build (gh-145626) (#145691)
Fix three issues that caused mimalloc pages to be leaked until the
owning thread exited:

1. In _PyMem_mi_page_maybe_free(), move pages out of the full queue
   when relying on QSBR to defer freeing the page. Pages in the full
   queue are never searched by mi_page_queue_find_free_ex(), so a page
   left there is unusable for allocations.

2. Move _PyMem_mi_page_clear_qsbr() from _mi_page_free_collect() to
   _mi_page_thread_free_collect() where it only fires when all blocks
   on the page are free (used == 0). The previous placement was too
   broad: it cleared QSBR state whenever local_free was non-NULL, but
   _mi_page_free_collect() is called from non-allocation paths (e.g.,
   page visiting in mi_heap_visit_blocks) where the page is not being
   reused.

3. In _PyMem_mi_page_maybe_free(), use the page's heap tld to find the
   correct thread state for QSBR list insertion instead of
   PyThreadState_GET(). During stop-the-world pauses, the function may
   process pages belonging to other threads, so the current thread
   state is not necessarily the owner of the page.

(cherry picked from commit d76df75f51)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2026-03-09 14:17:57 -04:00
Sam Gross
20438820ff
[3.14] gh-145566: Skip stop-the-world when reassigning __class__ on newly created objects (gh-145567) (#145605)
Co-authored-by: Sam Gross <colesbury@gmail.com>
2026-03-06 14:35:00 -05:00
Miss Islington (bot)
7b3e6bde26
[3.14] gh-144981: Make PyUnstable_Code_SetExtra/GetExtra thread-safe (GH-144980) (#145052)
Co-authored-by: Alper <alperyoney@fb.com>
2026-03-05 08:26:09 -05:00
Miss Islington (bot)
26a0dbad63
[3.14] gh-130327: Always traverse managed dictionaries, even when inline values are available (GH-130469) (#145438)
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
2026-03-02 19:57:10 +00:00
Sam Gross
7f9fcba66d
[3.14] gh-130555: Fix use-after-free in dict.clear() with embedded values (gh-145268) (#145431) 2026-03-02 13:59:35 -05:00
Miss Islington (bot)
d76c56e958
[3.14] gh-145142: Make str.maketrans safe under free-threading (gh-145157) (#145320)
Co-authored-by: VanshAgarwal24036 <148854295+VanshAgarwal24036@users.noreply.github.com>
2026-02-27 16:33:46 +00:00
Miss Islington (bot)
06b6243084
[3.14] gh-145092: Fix compiler warning for memchr() and wcschr() returning const pointer (GH-145093) (GH-145102)
(cherry picked from commit faea32b729)

Co-authored-by: Rudi Heitbaum <rudi@heitbaum.com>
2026-02-22 08:28:17 +00:00
Miss Islington (bot)
6006005893
[3.14] gh-144446: Fix some frame object thread-safety issues (gh-144479) (#144546)
Fix thread-safety issues when accessing frame attributes while another
thread is executing the frame:

- Add critical section to frame_repr() to prevent races when accessing
  the frame's code object and line number

- Add _Py_NO_SANITIZE_THREAD to PyUnstable_InterpreterFrame_GetLasti()
  to allow intentional racy reads of instr_ptr.

- Fix take_ownership() to not write to the original frame's f_executable
(cherry picked from commit 5bb3bbb9c6)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2026-02-06 15:25:36 +00:00
Victor Stinner
160810de89
[3.14] gh-144330: Initialize classmethod and staticmethod in new (#144498)
gh-144330: Initialize classmethod and staticmethod in new

Initialize cm_callable and sm_callable to None in classmethod and
staticmethod constructor.

Co-authored-by: Aniket Singh Yadav <singhyadavaniket43@gmail.com>
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
2026-02-06 10:21:02 +01:00
Sam Gross
06f9c8ca1c
[3.14] gh-144295: Fix data race in dict method lookup and global load (gh-144312) (#144346)
In `_Py_dict_lookup_threadsafe_stackref`, call `ensure_shared_on_read()` to
prevent a race between the lookup and concurrent dict resizes, which may free
the PyDictKeysObject (i.e., it ensures that the resize uses QSBR).

(cherry picked from commit e666a01ef4)
2026-01-30 12:15:47 -05:00
Miss Islington (bot)
27256ca382
[3.14] gh-102809: No longer mention Misc/gdbinit in the code (GH-143980) (#144044)
gh-102809: No longer mention `Misc/gdbinit` in the code (GH-143980)

Fix misleading comment on `PyObject_Dump`.
(cherry picked from commit f84ea11071)

Co-authored-by: Bartosz Sławecki <bartosz@ilikepython.com>
2026-01-19 18:01:21 +00:00
Miss Islington (bot)
601ccb7f89
[3.14] gh-141805: Fix crash after concurrent addition objects with the same hash to set (GH-143815) (GH-143849)
This happens when the set contained several elements with the same hash,
and then some of them were removed.
(cherry picked from commit b8e925b4f8)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2026-01-15 09:31:16 +02:00