Skip to content

Add Python 3.14 and free-threaded (3.14t) support - #44

Merged
binyamin555 merged 1 commit into
mainfrom
feat/python-3.14
Oct 27, 2026
Merged

binyamin555 merged 1 commit into
mainfrom
feat/python-3.14

Conversation

@binyamin555

Copy link
Copy Markdown
Member

Summary

  • Builds, tests and publishes wheels for Python 3.14 and the free-threaded 3.14t build.
  • Fixes several bugs in the C++ slot implementations, including segfaults and reference leaks.

Free-threading

  • All free-threading code is behind #ifdef Py_GIL_DISABLED, via TYPE_MUTATION_LOCK() / TYPE_MUTATION_UNLOCK() (a PyMutex) and STORE_SLOT() (an atomic pointer store). On regular builds they compile to nothing / a plain assignment.
  • The module calls PyUnstable_Module_SetGIL(Py_MOD_GIL_NOT_USED), so importing extype doesn't re-enable the GIL.
  • extend_type_with now sets the attribute before enabling the slot, so a slot is never active without a method behind it.
  • README documents the thread-safety expectations: apply extensions at import time.

Bug fixes

Each of these was reproduced on main before fixing:

  • Reference leaks in every slot implementation (PyTuple_Pack / PyObject_GetAttrString results never released).
  • __getitem__ was called without the key.
  • __setitem__ / __delitem__ failed because the None return value was converted to an integer.
  • __index__ was implemented as a binary function for a unary slot → segfault.
  • sq_item, sq_ass_item, sq_repeat, sq_inplace_repeat take a Py_ssize_t, but got object-based implementations → segfault. They now have dedicated implementations.
  • __iadd__ on sequence-only types used sq_inplace_repeat instead of sq_inplace_concat.
  • __hash__ returning -1 caused a SystemError; it now maps to -2 like Python does.
  • __bool__ continued after setting an error.
  • get_type_dict added an extra reference on 3.12+.
  • Writing directly into the type dict didn't invalidate the type attribute cache, which could segfault once the replaced method was freed. New set_type_attribute writes the attribute and calls PyType_Modified.
  • del _T in extension_utils.py breaks lazily evaluated annotations on 3.14 (typing.get_type_hints(extension) raised NameError, and flake8 on 3.14 fails CI on it).

CI / packaging

  • Added 3.14 to all workflow matrices, and 3.14t to the Windows/macOS publish jobs and all test workflows. On Linux, cibuildwheel already builds cp314t from the 3.14 entry (checked with --print-build-identifiers).
  • The Windows publish job now runs on windows-latest, since the windows-2019 runner is retired.

Testing

  • New tests/test_slot_implementations.py: regression tests for the bugs above. Six of the seven fail or crash on main.
  • New tests/test_free_threading.py: checks that the GIL stays disabled, and runs extensions concurrently with readers and with other writers.
  • Locally on Windows: all tests pass on 3.9, 3.12, 3.14 and 3.14t. The threading tests passed 50 out of 50 runs on 3.14t. Linux and macOS are covered by CI only.

🤖 Generated with Claude Code

- Build and test on Python 3.14 and 3.14t in CI and the publish workflow
- Declare GIL-free support and serialize type mutations on free-threaded
  builds (guarded by Py_GIL_DISABLED)
- Fix reference leaks in all slot implementations
- Fix __getitem__ not receiving the key, __setitem__/__delitem__ failing,
  __index__ and Py_ssize_t sequence slots crashing, __iadd__ using the
  wrong sequence slot, __hash__ returning -1 and __bool__ error handling
- Invalidate the type attribute cache when extending a type, which could
  crash after the replaced method was freed
- Remove `del _T`, which breaks lazily evaluated annotations on 3.14
- Run the Windows publish job on windows-latest (windows-2019 is retired)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@binyamin555
binyamin555 merged commit e021000 into main Oct 27, 2026
27 checks passed
@binyamin555
binyamin555 deleted the feat/python-3.14 branch October 27, 2026 13:50
@neriyaco neriyaco mentioned this pull request Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants