1269 Commits

Author SHA1 Message Date
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
Kumar Aditya 29917d51ab gh-148907: fix performance regression in PyType_GetModuleByDef on free-threading (#148908) 2026-04-23 16:42:57 +05:30
Kumar Aditya 458aca9237 gh-131798: fold super method lookups in JIT (#148231) 2026-04-09 13:25:01 +05:30
Petr Viktorin 8923ca418c gh-145921: Add "_DuringGC" functions for tp_traverse (GH-145925)
There are newly documented restrictions on tp_traverse:

    The traversal function must not have any side effects.
    It must not modify the reference counts of any Python
    objects nor create or destroy any Python objects.

* Add several functions that are guaranteed side-effect-free,
  with a _DuringGC suffix.
* Use these in ctypes
* Consolidate tp_traverse docs in gcsupport.rst, moving unique
  content from typeobj.rst there

Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2026-04-08 09:15:11 +02:00
Wulian233 c398490fbf gh-148074: Fix typeobject.c missing error return (#148075) 2026-04-04 21:04:55 +05:30
sunmy2019 bbf7fb2c15 gh-146615: Fix format specifiers in Objects/ directory (GH-146620) 2026-03-31 10:59:48 +03:00
Kumar Aditya 8e10bd77ea gh-146587: fix type slot assignment incase of multiple slots for same name (#146593) 2026-03-30 18:07:38 +05:30
Sergey Miryanov a933e9ccee GH-145247: Use _PyTuple_FromPair[Steal] in Objects (#145884)
Co-authored-by: Victor Stinner <vstinner@python.org>
2026-03-28 00:01:01 +00:00
Kumar Aditya 495178ab05 gh-146453: fix _PyType_LookupByVersion for types with fixed pre-defined version tags (#146454) 2026-03-26 14:36:55 +05:30
Sergey Miryanov f105265538 GH-132042: Fix calculation of slotdef index in update_one_slot() (#145880) 2026-03-12 23:16:53 +01:00
Sam Gross cd52172831 gh-145685: Improve scaling of type attribute lookups (gh-145774)
Avoid locking in the PyType_Lookup cache-miss path if the type's
tp_version_tag is already valid.
2026-03-12 13:30:36 -04:00
Sam Gross bdf6de8c3f gh-145685: Avoid contention on TYPE_LOCK in super() lookups (gh-145775) 2026-03-11 07:19:32 -04:00
Sam Gross f26eca7732 gh-145685: Update find_name_in_mro() to return a _PyStackRef (gh-145693) 2026-03-10 12:47:12 -04:00
Sam Gross 0b65c88c2a gh-145685: Stop the world when updating MRO of existing types (gh-145707)
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.
2026-03-09 18:41:07 -04:00
Sam Gross 1d091a336e gh-145566: Skip stop-the-world when reassigning __class__ on newly created objects (gh-145567) 2026-03-06 12:01:06 -05:00
Victor Stinner 95f56b1206 gh-141510: Return frozendict unmodified in PyDict_Copy() (#145505)
Add also the internal _PyDict_CopyAsDict() function.
2026-03-04 19:11:00 +00:00
Sam Gross 8a7eb8b2ab gh-145500: Delete _PyType_GetMRO (gh-145501) 2026-03-04 13:32:43 -05:00
Stan Ulbrych f8d2f9fe67 gh-145118: Add frozendict support to type() (#145124) 2026-03-02 20:45:03 +01:00
Sam Gross d891b2bbd1 gh-139103: Improve namedtuple scaling in free-threaded build (gh-144332)
Add `_Py_type_getattro_stackref`, a variant of type attribute lookup
that returns `_PyStackRef` instead of `PyObject*`. This allows returning
deferred references in the free-threaded build, reducing reference count
contention when accessing type attributes.

This significantly improves scaling of namedtuple instantiation across
multiple threads.

* Add blurb

* Rename PyObject_GetAttrStackRef to _PyObject_GetAttrStackRef

* Apply suggestion from @vstinner

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

* Apply suggestion from @vstinner

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

* format

* Update Include/internal/pycore_function.h

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

---------

Co-authored-by: Victor Stinner <vstinner@python.org>
2026-02-06 09:43:05 -05:00
Sam Gross 93b27e7f6d gh-139103: use METH_FASTCALL for tp_new_wrapper (#144406) 2026-02-03 16:02:06 +05:30
Sergey B Kirpichev 15c9f2491d gh-115231: Fill __module__ for built-in staticmethods (#115232)
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Victor Stinner <vstinner@python.org>
2026-02-02 12:34:02 +01:00
Manuel Jacob 03e6457096 Remove outdated comment about excess_args warning in object.__init__ (#143669)
The code emitting a warning was removed in 96384b93aa.
2026-01-11 10:27:11 +03:00
Serhiy Storchaka 4d21297d28 gh-41779: Allow defining any __slots__ for a class derived from tuple (GH-141763) 2026-01-06 11:36:00 +02:00
Dino Viehland da8199f884 gh-123241: Don't modify ref count during visitation (GH-142232) 2025-12-11 09:54:29 +01:00
Uwe L. Korn f6f456f950 gh-142038: Expand guard for types_world_is_stopped() to fix debug builds without assertions (#142039) 2025-12-03 15:24:17 +01:00
Serhiy Storchaka 4bcab461c2 gh-41779: Allow defining the __dict__ and __weakref__ __slots__ for any class (GH-141755) 2025-11-19 17:11:37 +00:00
Edward Xu ce79154176 gh-139103: fix free-threading dataclass.__init__ perf issue (gh-141596)
The dataclasses `__init__` function is generated dynamically by a call to `exec()` and so doesn't have deferred reference counting enabled. Enable deferred reference counting on functions when assigned as an attribute to type objects to avoid reference count contention when creating dataclass instances.
2025-11-19 00:57:59 +00:00
Victor Stinner 3bacae5598 gh-131510: Use PyUnstable_Unicode_GET_CACHED_HASH() (GH-141520)
Replace code that directly accesses PyASCIIObject.hash with
PyUnstable_Unicode_GET_CACHED_HASH().

Remove redundant "assert(PyUnicode_Check(op))" from
PyUnstable_Unicode_GET_CACHED_HASH(), _PyASCIIObject_CAST() already
implements the check.
2025-11-14 11:13:24 +01:00
Edward Xu b83f379a97 gh-133467: Fix typeobject tp_base race in free threading (gh-140549) 2025-11-05 16:20:40 -05:00
Petr Viktorin 589a03a8ce gh-140550: Initial implementation of PEP 793 – PyModExport (GH-140556)
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2025-11-05 12:31:42 +01:00
Sergey Miryanov da65f38a94 gh-134786: raise error if Py_TPFLAGS_MANAGED_WEAKREF or Py_TPFLAGS_MANAGED_DICT is used without Py_TPFLAGS_HAVE_GC set (#135863) 2025-11-02 16:34:49 +05:30
Kumar Aditya df07364106 gh-140544: use faster _PyInterpreterState_GET for type lock (#140584) 2025-10-25 14:53:26 +00:00
Emma Smith a8edca62fc gh-132835: Add defensive NULL checks to MRO resolution (GH-134763)
Currently, there are a few places where tp_mro could theoretically
become NULL, but do not in practice. This commit adds defensive checks for
NULL values to ensure that any changes do not introduce a crash and that
state invariants are upheld.

The assertions added in this commit are all instances where a NULL value would get passed to something not expecting a NULL, so it is better to catch an assertion failure than crash later on.

There are a few cases where it is OK for the return of lookup_tp_mro to be NULL, such as when passed to is_subtype_with_mro, which handles this explicitly.
2025-10-21 14:48:29 -07:00
Peter Bierma 71db05a12d gh-140406: Fix memory leak upon __hash__ returning a non-integer (GH-140411) 2025-10-21 08:10:01 -04:00
Neil Schemenauer 1e1f435196 gh-140126: Fix compile error if --with-assertions is enabled (#140133)
The `types_world_is_stopped()` function needs to be defined if NDEBUG
is not defined.
2025-10-14 23:34:30 +00:00
Sergey Miryanov e6e376a760 gh-132042: Remove resolve_slotdups() to speedup class creation (#132156)
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: sobolevn <mail@sobolevn.me>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2025-10-03 11:58:00 +02:00
da-woods ac5c5d42a2 gh-119494: Fix error messages for deleting/setting type attributes (#119495) 2025-09-18 22:08:49 +01:00
Dino Viehland 299de38e61 gh-131776: Expose functions called from the interpreter loop via PyAPI_FUNC (#134242) 2025-09-17 08:04:02 -07:00
Serhiy Storchaka 29d026f93e gh-37817: Allow assignment to __bases__ of direct subclasses of builtin classes (GH-137585) 2025-09-15 16:40:28 +00:00
Petr Viktorin 7dfa048bbb gh-135228: Create __dict__ and __weakref__ descriptors for object (GH-136966)
This partially reverts #137047, keeping the tests for GC collectability of the
original class that dataclass adds `__slots__` to.
The reference leaks solved there are instead solved by having the `__dict__` &
`__weakref__` descriptors not tied to (and referencing) their class.

Instead, they're shared between all classes that need them (within
an interpreter).
The `__objclass__` ol the descriptors is set to `object`, since these
descriptors work with *any* object. (The appropriate checks were already
made in the get/set code, so the `__objclass__` check was redundant.)

The repr of these descriptors (and any others whose `__objclass__` is `object`)
now doesn't mention the objclass.

This change required adjustment of introspection code that checks
`__objclass__` to determine an object's “own” (i.e. not inherited) `__dict__`.
Third-party code that does similar introspection of the internals will also
need adjusting.


Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2025-08-18 14:25:51 +02:00
Semyon Moroz 968f6e523a gh-130821: Add type information to error messages for invalid return type (GH-130835) 2025-08-14 11:04:41 +03:00
Sam Gross 485b16b4f7 gh-137238: Fix data race in _Py_slot_tp_getattr_hook (gh-137240)
Replacing the slot isn't thread-safe if the GIL is disabled. Don't
require that the slot has been replaced when specializing.
2025-08-05 09:32:22 -04:00
Kumar Aditya e99bc7fd44 gh-133467: fix data race in type_set_name (#137302)
Fix data race in `type_set_name` by assigning name under stop the world pause making it thread safe in free-threading.
2025-08-01 13:40:40 +00:00
Nathan Goldbaum 89c220b93c gh-133296: Publicly expose critical section API that accepts PyMutex (gh-135899)
This makes the following APIs public:

* `Py_BEGIN_CRITICAL_SECTION_MUTEX(mutex),`
* `Py_BEGIN_CRITICAL_SECTION2_MUTEX(mutex1, mutex2)`
* `void PyCriticalSection_BeginMutex(PyCriticalSection *c, PyMutex *mutex)`
* `void PyCriticalSection2_BeginMutex(PyCriticalSection2 *c, PyMutex *mutex1, PyMutex *mutex2)`

The macros are identical to the corresponding `Py_BEGIN_CRITICAL_SECTION` and
`Py_BEGIN_CRITICAL_SECTION2` macros (e.g., they include braces), but they
accept a `PyMutex` instead of an object.

The new macros are still paired with the existing END macros
(`Py_END_CRITICAL_SECTION`, `Py_END_CRITICAL_SECTION2`).
2025-07-21 17:25:43 -04:00
Weilin Du 561212a033 Doc: More duplicate word fixes (GH-136299) 2025-07-11 21:18:47 +03:00
Kumar Aditya b582d751b4 gh-129824: fix data races in subinterpreters under TSAN (#135794)
This fixes the data races in typeobject.c in subinterpreters under free-threading. The type flags and slots are only modified in the main interpreter as all static types are first initialised in main interpreter.
2025-07-04 03:48:55 +00:00
Serhiy Storchaka c45f4f3ebe gh-78465: Fix error message for cls.__new__(cls, ...) where cls is not instantiable (GH-135981)
Previous error message suggested to use cls.__new__(), which
obviously does not work. Now the error message is the same as for
cls(...).
2025-06-27 14:35:55 +03:00
Donghee Na 52be7f445e gh-133931: Introduce _PyObject_XSetRefDelayed to replace Py_XSETREF (gh-134377) 2025-06-18 08:36:02 +09:00
Mark Shannon 9fbd66a93d GH-133912: Fix PyObject_GenericSetDict to handle inline values (GH-134725) 2025-05-28 19:03:41 +01:00