8484 Commits
Author SHA1 Message Date
Miss Islington (bot)andRishi Raj 036d2d648c [3.13] gh-157892: Fix error check on _Py_hashtable_set() in intern_static() (GH-157898) (#158299)
_Py_hashtable_set() returns -1 on failure, so the "< -1" check could never be true and the Py_FatalError() call was unreachable.
(cherry picked from commit a4eb936727)

Co-authored-by: Rishi Raj <180109771+rishiraj38@users.noreply.github.com>
2026-09-29 22:02:38 +00:00
Miss Islington (bot)andSamartha 5634116591 [3.13] gh-157621: Clear weakrefs for ParamSpec attributes (GH-157622) (#157655)
gh-157621: Clear weakrefs for ParamSpec attributes (GH-157622)
(cherry picked from commit b215552a32)

Co-authored-by: Samartha <samarthat9@gmail.com>
2026-09-29 23:35:56 +02:00
ff03e45625 [3.13] gh-158254: Detect keys changing during reverse dict iteration (GH-158255) (GH-158269)
A reverse dict iterator only checked that the dict's size was unchanged,
so after the keys were replaced with the same number of keys it kept
yielding entries for the new keys. It could yield more items than the
dict had when it was created, and __length_hint__() then wrapped around.

Add the check the forward iterators already have: finding an entry after
the expected number of items raises "dictionary keys changed during
iteration".
(cherry picked from commit 042a7c1505)

Co-authored-by: Joshua Bronson <jabronson@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-27 03:17:41 +00:00
bb8572f90a [3.13] gh-155526: Don't check errno in abs(complex) (GH-155527) (#157341) (#157558)
[3.15] gh-155526: Don't check errno in abs(complex) (GH-155527) (#157341)



(cherry picked from commit 340cfbaf67)

Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Co-authored-by: hpkfft.com <paul@hpkfft.com>
2026-09-24 00:09:46 +02:00
Miss Islington (bot)andVictor Stinner a47148386b [3.13] gh-156939: Fix xmlcharrefreplace() buffer overflow (GH-157109) (#157234)
* gh-156939: Fix xmlcharrefreplace() buffer overflow (GH-157109)

Write into a temporary buffer to not write the trailing NUL byte
into the writer. Previously, the NUL byte was written outsize
the writer buffer.
(cherry picked from commit 939865532c)

Co-authored-by: Victor Stinner <vstinner@python.org>

* Replace _Py_MAX_UNICODE with MAX_UNICODE

---------

Co-authored-by: Victor Stinner <vstinner@python.org>
2026-09-15 15:01:25 +00:00
a728f1cffa [3.13] gh-156995: Fix _PyBytes_Resize() in Free Threading (#156996) (#157373) (#157436)
[3.14] gh-156995: Fix _PyBytes_Resize() in Free Threading (#156996) (#157373)

_PyBytes_Resize(&obj, 1) no longer returns a single byte singleton if
the reference count is greater than 1.

(cherry picked from commit fd569ea941)

Co-authored-by: Stan Ulbrych <stan@python.org>
Co-authored-by: Cody Maloney <cmaloney@users.noreply.github.com>
2026-09-13 20:18:34 +02:00
Miss Islington (bot)andDaniel Scherzer 997d79d318 [3.13] Fix a stray newline in the cell type docstring (GH-157240) (#157277)
(cherry picked from commit 34439b8a25)

Co-authored-by: Daniel Scherzer <daniel.e.scherzer@gmail.com>
2026-09-10 16:21:01 +00:00
c28b121a4f [3.13] gh-155292: Don't consider Unicode codepoint attributes outside RFC 3454 (GH-155293) (GH-156020) (GH-156922)
Due to a bug, some Unicode codepoint attributes were considered
for characters not yet defined in Unicode 3.2.0 or attributes
which changed in later Unicode versions. RFC 3454 (StringPrep)
requires using Unicode 3.2.0 strictly.

(cherry picked from commit 7e109d084d)
The cherry-pick needed reworking as GH-144815 wasn't backported to 3.14
and below, so unassigned characters don't have bidi values.
(cherry picked from commit 1e54caa096)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Seth Larson <seth@python.org>
Co-authored-by: Stan Ulbrych <89152624+stanfromireland@users.noreply.github.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>

---------

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Seth Larson <seth@python.org>
Co-authored-by: Stan Ulbrych <89152624+stanfromireland@users.noreply.github.com>
2026-09-09 16:28:35 +02:00
Miss Islington (bot)andDarius Houle 649e421ffc [3.13] gh-155752: Do not crash when GenericAlias parameters change during substitution (GH-155761) (#155772)
gh-155752: Do not crash when GenericAlias parameters change during substitution (GH-155761)

An alias argument can gain __typing_subst__ after __parameters__ has been cached, including during a preparation or substitution callback. Check that the argument is present before indexing the substitution arguments.
(cherry picked from commit c0006faf4f)

Co-authored-by: Darius Houle <dariushoule@gmail.com>
2026-09-07 22:01:32 -04:00
Miss Islington (bot)andSergey Miryanov 9ce6acd7e2 [3.13] GH-146096: Fix segfault in BaseExceptionGroup repr (GH-146141) (GH-156903)
(cherry picked from commit ced64605be)

Co-authored-by: Sergey Miryanov <sergey.miryanov@gmail.com>
2026-09-04 11:25:06 +02:00
Serhiy Storchaka acdb9a7859 [3.13] gh-156189: Fix a crash when deleting frame.f_trace_opcodes (GH-156190)
The setter passed the value to PyBool_Check() without checking it for
NULL.
2026-08-21 15:30:44 +00:00
stevensandStan Ulbrych 45169108b7 [3.13] gh-155952: Fix <unrepresentable> Argument Clinic defaults in several signatures (#156170)
(cherry picked from commit 5a7fd42138)

Co-authored-by: Stan Ulbrych <stan@python.org>
2026-08-21 13:25:13 +01:00
Miss Islington (bot)andtonghuaroot 49fe8bd657 [3.13] gh-153578: Fix out-of-bounds write in bytearray.extend() with a reentrant __buffer__ (GH-153579) (GH-156009)
bytearray.extend() clamped only the high bound of the append range to the
current size after acquiring the argument's buffer, so a __buffer__ that shrinks
the bytearray left the low bound past the high bound and ran a negative-size
memmove. Clamp the low bound too, matching bytearray.__iadd__.
(cherry picked from commit e675e37421)

Co-authored-by: tonghuaroot (童话) <tonghuaroot@gmail.com>
2026-08-19 10:07:10 +00:00
Serhiy Storchaka acdecb345d [3.13] gh-113318: Fix @getter and @setter in Argument Clinic (GH-155778) (GH-156012)
(cherry picked from commit 915970ce9d)
2026-08-18 13:09:10 +00:00
Miss Islington (bot)andBhuvansh 2af2564a7b [3.13] gh-154709: Fix out-of-bounds access in dict reverse iterator (GH-154721) (GH-154890)
(cherry picked from commit 3fd36fadbe)

Co-authored-by: Bhuvansh <bhuvanshkataria@gmail.com>
2026-07-29 17:45:46 +00:00
sobolevn 0942455021 [3.13] gh-154275: Do not crash on deeply nested __parameters__ in GenericAlias (GH-154277) (#154340)
* [3.13] gh-154275: Do not crash on deeply nested `__parameters__` in `GenericAlias` (GH-154277)
(cherry picked from commit 1034e07b7d)

Co-authored-by: sobolevn <mail@sobolevn.me>
2026-07-21 10:29:57 +00:00
Miss Islington (bot)andSanthosh .I 🦇 35a21feeaf [3.13] gh-151912: Fix segfault in type() with NULL tp_new metaclasses (GH-151916) (#153706)
gh-151912: Fix segfault in `type()` with NULL `tp_new` metaclasses (GH-151916)
(cherry picked from commit f160f16373)

Co-authored-by: Santhosh .I 🦇 <santhoshilaiyaraja2006@gmail.com>
2026-07-14 22:16:47 +05:30
Gregory P. Smith 9dc1ae0918 [3.13] gh-148660: Fix use-after-free in OrderedDict.copy() on reentrant mutation (GH-151573) (#152542)
OrderedDict.copy() walks the internal linked list while building the new
dict. The loop body can run arbitrary Python (a key's __eq__/__hash__, or
a subclass __getitem__/__setitem__) which can clear the source dict and
free the nodes being iterated.

Detect this the same way OrderedDict.__eq__ already does (gh-119004):
snapshot od_state before the loop, hold a strong reference to the key and
read the hash before any reentrant call, and raise RuntimeError if the
state changed before advancing to the next node.

(cherry picked from commit 7d128e319f)
2026-06-28 19:56:52 -07:00
Donghee Na 668860b846 [3.13] gh-152235: Defer GC tracking in set.union and set.difference (gh-152290) (gh-152319)
(cherry picked from commit 5a549e82b8)
2026-06-26 17:54:19 +00:00
Miss Islington (bot)andDonghee Na 80dddd23cd [3.13] gh-152235: Defer GC tracking in more set operations (gh-152273) (gh-152280)
gh-152235: Defer GC tracking in more set operations (gh-152273)
(cherry picked from commit a87d24a69d)

Co-authored-by: Donghee Na <donghee.na@python.org>
2026-06-27 01:47:23 +09:00
Donghee Na 998587cd74 [3.13] gh-152235: Defer GC tracking of set and frozenset to end of connstruction (gh-152272)
[3.13] gh-152235: Defer GC tracking of set and frozenset to end of construction (gh-152237)
(cherry picked from commit 908f438e19)
2026-06-26 12:35:30 +00:00
Jelle Zijlstra d43f47bdca [3.13] gh-151955: Allow more ParamSpec bounds (#152122)
gh-151955: Allow more ParamSpec and TypeVarTuple bounds (#151956)

(cherry picked from commit 0fb82b46df)
2026-06-24 20:08:56 +00:00
Prakash Sellathurai 117b76a190 [3.13] gh-151905: fix memory error handling in PyFrame_GetBack (GH-151906) (#152065)
[3.13] gh-151905: fix memory error handling in PyFrame_GetBack
(pythonGH-151906)

Signed-off-by: Prakash Sellathurai <prakashsellathurai@gmail.com>
2026-06-24 11:40:07 +00:00
abf5016b4d [3.13] gh-151126: Add missing PyErr_NoMemory() in type_from_slots_or_spec (GH-151582)
(cherry picked from commit 7928a8b730)

Co-authored-by: Ivy Xu <fakeshadow1337@gmail.com>
Co-authored-by: Stan Ulbrych <stan@python.org>
2026-06-23 15:12:29 +00:00
Miss Islington (bot)andPeter Bierma 8754abc358 [3.13] gh-151065: Copy fix for memory leak from mimalloc upstream (GH-151066) (GH-151385)
Applies https://github.com/microsoft/mimalloc/commit/d7a72c4912943e8aaf135e465ca5ea229ea96646 to our copy of mimalloc.
(cherry picked from commit 80f9467434)

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
2026-06-11 21:18:14 -04:00
Miss Islington (bot)andSerhiy Storchaka c4f3d8c343 [3.13] gh-150285: Fix too long docstrings in GenericAlias and __class_getitem__ (GH-151354) (GH-151369)
(cherry picked from commit 65047f2e2f)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2026-06-11 17:11:49 +00:00
Miss Islington (bot)andtonghuaroot 5c17ae6c1c [3.13] gh-151295: Fix use-after-free in bytes.join()/bytearray.join() via re-entrant __buffer__ (GH-151296) (GH-151306)
(cherry picked from commit 84a322aa15)

Co-authored-by: tonghuaroot (童话) <tonghuaroot@gmail.com>
2026-06-11 11:30:49 +03:00
a1f9bd2346 [3.13] gh-150988: Fix refleak in OSError when attrs are set before super().__init__() (GH-150990) (#151242)
gh-150988: Fix refleak in `OSError` when attrs are set before `super().__init__()` (GH-150990)
(cherry picked from commit f2a0f82282)

Co-authored-by: Lukas Geiger <lukas.geiger94@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2026-06-10 12:51:12 +00:00
7c5734c791 [3.13] gh-150319: Replace all documentation which says "See PEP 585" (#150325) (#150814)
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:26:33 +00:00
Serhiy Storchaka 43b6b483b2 [3.13] gh-150285: Fix too long docstrings in builtins (GH-150293) (GH-150466) (GH-150472)
(cherry picked from commit 730fc6a858)
(cherry picked from commit e1e06be119)
2026-05-26 10:34:50 +00:00
Hai Zhu 5d03b24827 [3.13] gh-148450: abc.register needs to update type_version when tp_flags is changed (GH-148623) (#150307) 2026-05-23 17:20:16 +05:30
sobolevn 32feeff72d [3.13] gh-150146: Fix NULL dereference in _Py_subs_parameters (GH-150147) (#150155)
* [3.13] 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 14:04:17 +00:00
05956df2c2 [3.13] gh-148390: fix undefined behavior of memoryview(...).cast("?") (GH-148454) (GH-149299)
(cherry picked from commit 69e0a78e6e)
(cherry picked from commit 454401c8e9)

Co-authored-by: Stan Ulbrych <stan@python.org>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2026-05-08 17:50:00 +02:00
Prakash Sellathurai 0ca5390b60 [3.13] gh-148222: Fix NULL dereference bugs in genericaliasobject.c (GH-148226) (#148717)
(cherry picked from commit 634568d030)
2026-04-18 07:54:21 -07:00
Victor StinnerandSergey B Kirpichev 01af34a364 [3.13] gh-143050: Correct PyLong_FromString() to use _PyLong_Negate() (#145901) (#147437)
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().

Co-authored-by: Victor Stinner <vstinner@python.org>
(cherry picked from commit db5936c5b8)

Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
2026-03-31 17:06:38 +02:00
Miss Islington (bot)andsunmy2019 52bc5c26a7 [3.13] gh-146615: Fix crash in __get__() for METH_METHOD descriptors with invalid type argument (GH-146634) (GH-146648)
(cherry picked from commit 72d29ea363)

Co-authored-by: sunmy2019 <59365878+sunmy2019@users.noreply.github.com>
2026-03-31 09:22:59 +00:00
Serhiy Storchakaandsunmy2019 499df18d80 [3.13] gh-146615: Fix format specifiers in Objects/ directory (GH-146620) (GH-146655)
(cherry picked from commit bbf7fb2c15)

Co-authored-by: sunmy2019 <59365878+sunmy2019@users.noreply.github.com>
2026-03-31 08:44:51 +00:00
AN LongandBrij Kapadia c09ccd9c42 [3.13] gh-146250: Fix memory leak in re-initialization of SyntaxError (GH-146251) (#146519)
* [3.13] gh-146250: Fix memory leak in re-initialization of `SyntaxError` (GH-146251)
(cherry picked from commit 0de4e08a59)

Co-authored-by: Brij Kapadia <97006829+bkap123@users.noreply.github.com>

* Minimize the changes

* Minimize the changes

* Minimize the changes

---------

Co-authored-by: Brij Kapadia <97006829+bkap123@users.noreply.github.com>
2026-03-30 21:36:52 +05:30
Sergey Miryanov ef8475f492 [3.13] Fix possible memory leak in OrderedDict popitem (GH-145247) (#146538) 2026-03-27 21:40:23 +00:00
Serhiy StorchakaandVictor Stinner fab82679d3 [3.13] gh-146056: Fix repr() for lists containing NULLs (GH-146129) (GH-146155) (GH-146271)
(cherry picked from commit 0f2246b155)
(cherry picked from commit 796513306f)

Co-authored-by: Victor Stinner <vstinner@python.org>
2026-03-22 08:06:17 +00:00
Miss Islington (bot)andVictor Stinner 53b544a6a7 [3.13] gh-146092: Handle _PyFrame_GetFrameObject() failures properly (GH-146124) (GH-146132) (#146138)
[3.14] gh-146092: Handle _PyFrame_GetFrameObject() failures properly (GH-146124) (GH-146132)

gh-146092: Handle _PyFrame_GetFrameObject() failures properly (GH-146124)

* Fix _PyFrame_GetLocals() and _PyFrame_GetLocals() error handling.
* _PyEval_ExceptionGroupMatch() now fails on _PyFrame_GetLocals()
  error.
(cherry picked from commit 8eeb800faf)


(cherry picked from commit e1e4852133)

Co-authored-by: Victor Stinner <vstinner@python.org>
2026-03-18 21:23:26 +01:00
Miss Islington (bot)andPieter Eendebak 1d6e037b62 [3.13] gh-145376: Fix GC tracking in structseq.__replace__ (GH-145820) (#145924)
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:24 +05:30
Bénédikt Tran cd2e47135c [3.13] gh-143636: fix a crash when calling `__replace__ on invalid SimpleNamespace` instances (GH-143655) (#145940)
[3.13] gh-143636: fix a crash when calling ``__replace__`` on invalid `SimpleNamespace` instances (GH-143655)

(cherry picked from commit 97968564b6)
2026-03-14 11:00:56 +00:00
Sam GrossandPeter Bierma 702d085783 [3.13] gh-130327: Always traverse managed dictionaries, even when inline values are available (GH-130469) (#145440)
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
2026-03-02 20:03:08 +00:00
Sam Gross d567f451e1 [3.13] gh-130555: Fix use-after-free in dict.clear() with embedded values (gh-145268) (#145430) 2026-03-02 13:59:52 -05:00
Miss Islington (bot)andRudi Heitbaum 22af3d5104 [3.13] gh-145092: Fix compiler warning for memchr() and wcschr() returning const pointer (GH-145093) (GH-145101)
(cherry picked from commit faea32b729)

Co-authored-by: Rudi Heitbaum <rudi@heitbaum.com>
2026-02-22 08:28:24 +00:00
b6c6cd6321 [3.13] gh-144330: Initialize classmethod and staticmethod in new (GH-144498) (#144537)
[3.14] gh-144330: Initialize classmethod and staticmethod in new (GH-144498)

gh-144330: Initialize classmethod and staticmethod in new

Initialize cm_callable and sm_callable to None in classmethod and
staticmethod constructor.
(cherry picked from commit 160810de89)

Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Aniket Singh Yadav <singhyadavaniket43@gmail.com>
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
2026-02-06 09:48:55 +00:00
Petr Viktorin fdac87ae39 [3.13] gh-127773: Disable attribute cache on incompatible MRO entries (GH-127924) (GH-143729) 2026-01-26 16:31:52 +01:00
Miss Islington (bot)andBartosz Sławecki 7bca3dd1e6 [3.13] gh-102809: No longer mention Misc/gdbinit in the code (GH-143980) (#144045)
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 17:59:44 +00:00
sobolevn aa5ad50597 [3.13] gh-143635: Fix crash in ga_repr_items_list (GH-143670) (#143852)
(cherry picked from commit bdba5f0db2)
2026-01-15 15:27:31 +00:00