9200 Commits

Author SHA1 Message Date
Prakash Sellathurai 1ab8862ea0 gh-151905: fix memory error handling in PyFrame_GetBack (#151906) 2026-06-22 16:41:31 +05:30
AN Long c2661e6189 gh-151845: Fix formatfloat() return-value contract in unicode_format.c (#151846)
Fix formatfloat() return-value contract in unicode_format.c
2026-06-21 20:16:30 +03:00
da-woods a5568d0eb7 gh-141510 Add frozendict fast paths to abstract.c (#150692)
Add frozendict to the fast paths of PyMapping_GetOptionalItem(),
PyMapping_Keys(), PyMapping_Values(), and PyMapping_Items().

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
2026-06-19 08:41:00 +00:00
Maurycy Pawłowski-Wieroński a8d74c062f gh-151436: Fix missing tstate->last_profiled_frame updates (#151437) 2026-06-17 16:49:23 -04:00
Petr Viktorin 16185e9fe2 gh-149044: Improve Py_tp_base[s] docs & error message for non-type bases (GH-151252)
The initial implementation of PEP 820 worsened the error message
when non-types are given as base types in Py_tp_bases & Py_tp_base.
Bring back the 'bases must be types' wording and add a 'got' note for
easier debugging.

Improve slot ID documentation, and soft-deprecate Py_tp_base
(as per the PEP).
2026-06-17 15:27:02 +02:00
Victor Stinner b16d23fc9f gh-151218: Replace sys.flags in PyConfig_Set() (#151402)
PyConfig_Set() and sys.set_int_max_str_digits() now replace
sys.flags (create a new object), instead of modifying sys.flags in-place.

Modifying sys.flags in-place can lead to data races when multiple
threads are reading or writing sys.flags in parallel.

Use _Py_atomic functions to get and set max_str_digits members.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2026-06-16 16:17:33 +00:00
Victor Stinner 0ec7c9d17e gh-146102: Fix type slot_bf_getbuffer() error handling (#151346)
Call PyBuffer_Release() if PyObject_GC_New() fails.

Fix also bytes_join(): only call Py_DECREF(item) after formatting the
error message which uses item.
2026-06-15 11:47:58 +02:00
Victor Stinner b3b7c0025b gh-146102: Don't clear exception on success in odictobject.c (#151347)
Calling PyErr_Clear() on success can mask a pending exception.
Replace it with an assertion checking that no exception is set.
2026-06-15 11:46:52 +02:00
JasonMendoza2008 ecbd31ee39 gh-137759: Replace _PyObject_HashFast() with PyObject_Hash() in setobject.c (#137828)
Replace also _PyObject_HashFast() with PyObject_Hash()
in _collections._count_elements().

Rename _PyObject_HashFast() to _PyObject_HashDictKey(),
and mark it as Py_ALWAYS_INLINE.

Only use _PyObject_HashDictKey() on dictionaries.
2026-06-15 11:31:04 +02:00
Matt Wozniski c37599200f gh-151297: Fix undefined behavior in _PyObject_MiRealloc (GH-151358)
The standard says that a call to `memcpy` must pass a valid source and
destination pointer even if the size is 0, so we must avoid calling
`memcpy` when our source pointer is NULL. If we don't, an optimizing
compiler can decide that the pointer must be non-NULL based on the
presence of UB, and optimize out checks for null pointers.

Specifically, note that the standard says:

    Where an argument declared as size_t n specifies the length of the
    array for a function, n can have the value zero on a call to that
    function. Unless explicitly stated otherwise in the description of
    a particular function in this subclause, pointer arguments on such
    a call shall still have valid values, as described in 7.1.4.

And section 7.1.4 says:

    If an argument to a function has an invalid value (such as a value
    outside the domain of the function, or a pointer outside the address
    space of the program, or a null pointer, or a pointer to
    non-modifiable storage when the corresponding parameter is not
    const-qualified) or a type (after default argument promotion) not
    expected by a function with a variable number of arguments, the
    behavior is undefined.

The specification for `memcpy` doesn't state that it's allowed to be
called with null pointers, and Linux's `/usr/include/string.h` declares
`memcpy` as `__nonnull ((1, 2))`.
2026-06-11 21:21:04 -04:00
Peter Bierma 80f9467434 gh-151065: Copy fix for memory leak from mimalloc upstream (GH-151066)
Applies https://github.com/microsoft/mimalloc/commit/d7a72c4912943e8aaf135e465ca5ea229ea96646 to our copy of mimalloc.
2026-06-11 18:11:52 -04:00
Serhiy Storchaka 65047f2e2f gh-150285: Fix too long docstrings in GenericAlias and __class_getitem__ (GH-151354) 2026-06-11 19:52:58 +03:00
Dino Viehland efb2fffae1 gh-150490: Raise PyType_Modified for insertion into split dictionary (#150489)
Raise PyType_Modified for insertion into split dictionary
2026-06-11 09:38:31 -07:00
Kumar Aditya 6112d70abe gh-151228: fix data race on clearing embedded dict values (#151330) 2026-06-11 21:37:00 +05:30
Thomas Kowalski 1ec6596828 gh-150858: fix data race while changing __qualname__ of a type object(#150859) 2026-06-11 15:07:36 +00:00
Victor Stinner 72e7eddce6 gh-123619: Fix PyUnstable_Object_EnableDeferredRefcount() (#151260)
Return 0 if the object is not tracked by the GC.
2026-06-11 12:55:13 +02:00
tonghuaroot (童话) 84a322aa15 gh-151295: Fix use-after-free in bytes.join()/bytearray.join() via re-entrant __buffer__ (GH-151296) 2026-06-11 07:51:43 +00:00
Lukas Geiger f2a0f82282 gh-150988: Fix refleak in OSError when attrs are set before super().__init__() (#150990)
Co-authored-by: Victor Stinner <vstinner@python.org>
2026-06-10 12:27:11 +00:00
Serhiy Storchaka ca32ebf793 gh-80384: Check that callback is callable at weak reference creation (GH-151145)
* Python functions weakref.ref() and weakref.proxy() now raise TypeError
  if the callback argument is not callable or None.
* C functions PyWeakref_NewRef() and PyWeakref_NewProxy() now raise TypeError
  if the callback argument is not callable, None, or NULL.

Co-authored-by: Maxwell Bernstein <emacs@fb.com>
2026-06-10 13:34:55 +03:00
Omkar Kabde 253904f752 gh-150942: Speed up frame local item collection (gh-151002) 2026-06-07 21:05:53 +09:00
Stephen Rosen 50fe49c879 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

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>

* Correct several class getitem docs

And expand the text for tuples.

Co-authored-by: Jelle Zijlstra <906600+JelleZijlstra@users.noreply.github.com>

* 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

Co-authored-by: Jelle Zijlstra <906600+JelleZijlstra@users.noreply.github.com>

* Apply suggestions from code review

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

Co-authored-by: Alex Waygood <66076021+AlexWaygood@users.noreply.github.com>

* Update Doc/library/re.rst

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>

* Update Objects/enumobject.c

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>

* 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

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>

* 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.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>

* 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

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>

* 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: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Jelle Zijlstra <906600+JelleZijlstra@users.noreply.github.com>
Co-authored-by: Alex Waygood <66076021+AlexWaygood@users.noreply.github.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2026-06-02 21:13:34 +01:00
Bartosz Sławecki 5a2d2736a6 gh-150052: Resolve un-loaded lazily loaded submodules via module.__getattr__ instead of publishing lazy values (#150055) (#150744) 2026-06-02 09:58:51 +01:00
Brij Kapadia f586fd9e30 gh-144774: Add critical section in BaseException.__setstate__ (#150578) 2026-05-30 21:07:27 +05:30
Serhiy Storchaka e1e06be119 gh-150285: Fix too long docstrings in builtins (GH-150293)
* gh-150285: Fix too long docstrings in builtins

* Revert bytes and bytearray class multiline docstrings to make IDLE happy.
2026-05-24 15:03:32 +03:00
Pieter Eendebak dfeeee990b gh-145192: improve performance of PySequence_GetSlice (#145193) 2026-05-23 15:45:50 +05:30
Hai Zhu e7eaed5614 gh-148450: abc.register needs to update type_version when tp_flags is changed (#148623) 2026-05-23 13:55:44 +05:30
sobolevn f621ba16b7 gh-150146: Fix NULL dereference in _Py_subs_parameters (#150147) 2026-05-20 16:27:55 +03:00
Victor Stinner 244300162d gh-149807: Fix hash(frozendict): compute (key, value) pair hash (#149841) 2026-05-20 13:22:57 +02:00
Tim Stumbaugh de9c32fc34 PEP 810 - Update some error strings (#150126) 2026-05-20 00:47:44 +00:00
Peter Bierma 409fa8e1f3 gh-150027: Avoid copying during construction of frozenset objects (GH-150028) 2026-05-19 13:57:37 -04:00
Jelle Zijlstra 08218030a5 gh-148829: Make sentinels' repr and module customizable (#149654)
Implementation of python/peps#4968; still needs SC approval.
2026-05-19 09:18:56 -07:00
Kumar Aditya 00ea77613b gh-149816: fix thread safety of deletion of list slice (#149936) 2026-05-18 22:08:37 +05:30
Kumar Aditya 1692854706 gh-149816: fix dict.clear() race on split-table dict with non-embedded values (#149914) 2026-05-18 21:39:45 +05:30
sobolevn 46afba7b93 gh-149816: Fix a race condition in _PyBytes_FromList with free-threading (#149909) 2026-05-16 08:37:34 +00:00
sobolevn 1fdf033774 gh-149816: Fix race condition in memoryview with free-threading (#149858) 2026-05-15 15:38:51 +03:00
Carlo Bramini fdf064ca81 gh-148461: Use arc4random_buf() in mimalloc on Cygwin (#148462)
See also issue #113141.
2026-05-13 21:09:24 +02:00
Kumar Aditya 94bca40ff0 gh-148906: fix performance scaling of descriptors on free-threading (#148915) 2026-05-13 23:03:59 +05:30
Stan Ulbrych 6a0be131c3 gh-149595: Remove the sys._enablelegacywindowsfsencoding() function (#149596)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2026-05-12 17:11:34 +01:00
Thomas Kowalski f5fb491341 gh-149676: Fix hash(frozendict | frozendict) (#149675)
Fix new_dict_impl() to properly initialize ma_hash on frozendict.

Co-authored-by: Victor Stinner <vstinner@python.org>
2026-05-12 10:47:39 +00:00
Alper 8a4895985f gh-145235: Make dict watcher API thread-safe for free-threaded builds (gh-145233)
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.
2026-05-11 11:39:55 -04:00
Jelle Zijlstra 56171da341 gh-144957: Fix lazy imports + module __getattr__ (GH-149624) 2026-05-11 15:08:12 +02:00
Sergey B Kirpichev ef877318a0 gh-149402: Don't assume single-character type codes (struct/array/ctypes) (#149483)
In the struct docs, section "Format Characters" was renamed to "Type
Codes".

Co-authored-by: Victor Stinner <vstinner@python.org>
2026-05-11 13:05:50 +00:00
Neko Asakura d2d24e46d3 gh-100239: expose sq_repeat helpers for BINARY_OP_EXTEND (#148791) 2026-05-08 11:12:20 +00:00
Neko Asakura 49918f5b0c gh-149481: skip FOR_ITER inline specialization for Python __next__ (#149491)
Co-authored-by: Savannah Ostrowski <savannah@python.org>
Co-authored-by: Stan Ulbrych <stan@python.org>
2026-05-07 23:02:04 +00:00
Mark Shannon 70bd1c2dd2 GH-143732: SEND specialization (GH-148963)
* SEND specialization. Adds 2 new specialized instructions:

* SEND_VIRTUAL: for sends to virtual iterators e.g lists and tuples
* SEND_ASYNC_GEN: for sends to async generators

Tweak FOR_ITER_VIRTUAL so that SEND_VIRTUAL and FOR_ITER_VIRTUAL use equivalent guards
2026-05-05 15:19:16 +01:00
Anuj Nitin Bharambe f6d16a0d70 gh-149216: Notify type watchers on heap type deallocation (GH-149236)
Authored-by: Anuj Bharambe <anujnitinb@gmail.com>
2026-05-05 11:24:07 +01:00
Petr Viktorin 508b49845d gh-149044: Implement PEP 820 – PySlot: Unified slot system for the C API (GH-149055)
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
2026-05-05 09:18:04 +02:00
Victor Stinner 5dd5c8b5a6 gh-148675: Remove F and D formats from array and memoryview (GH-149368) 2026-05-04 17:26:30 +02:00
Victor Stinner 6e6f9053e3 gh-148675: Add Zd/Zf formats to array, ctypes, memoryview, struct (#148676)
* Add Zd/Zf format support to array, memoryview and struct.
* ctypes: Replace F/D/G complex format with Zf/Zd/Zg.
* Modify array, ctypes and struct modules to support format strings
  longer than 1 character (such as "Zd").
* Change array.typecodes type from str to tuple.
2026-05-04 16:14:23 +02:00
Kumar Aditya 5847931d11 gh-143732: allow dict subclasses to be specialized (GH-148128) 2026-05-04 09:39:03 +01:00