Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
4ab0483
Issue #gh-139122: Reimplement base UUID type, uuid4(), and uuid7() in C
1st1 Sep 17, 2025
d80180d
Address @picnixz's review
1st1 Sep 19, 2025
ff3e317
Regen the clinic files
1st1 Sep 19, 2025
a7e9690
Clarify the type name
1st1 Sep 19, 2025
c1e5290
Fix news
1st1 Sep 19, 2025
50fb64a
Trim the NEWS file down
1st1 Sep 19, 2025
62c3fda
Use PyObject* in getters
1st1 Sep 19, 2025
22c0d61
Codegen string literals and use them
1st1 Sep 19, 2025
623d1ab
Ensure total compatibility of C/Python implementations of uuid4 / uuid7
1st1 Sep 21, 2025
32a8911
Stop importing unused SafeUUID members
1st1 Sep 21, 2025
7880664
Drop SafeUUID.unknown
1st1 Sep 21, 2025
f80ef75
Drop more things that can be imported dynamically
1st1 Sep 21, 2025
860e7f7
Remove circular import; import 'uuid' from '_uuid' lazily
1st1 Sep 21, 2025
faee029
Regen files
1st1 Sep 22, 2025
a0c3007
Get module state assuming there could be subclasses of UUID
1st1 Sep 22, 2025
f2687b4
More ergonomic int cast code
1st1 Sep 22, 2025
a1f5fcc
gh-139122: Fix UUID subclass allocation and freelist type ownership
1st1 Oct 19, 2026
3eff5a4
gh-139122: Match UUID state restoration mapping semantics
1st1 Oct 19, 2026
634151a
gh-139122: Fix UUID time hook error handling and reference updates
1st1 Oct 19, 2026
5627dbe
gh-139122: Align C UUID constructor inputs with Python
1st1 Oct 19, 2026
f1b2eae
gh-139122: Make UUID narrowing and entropy lock requirements explicit
1st1 Oct 19, 2026
b86a52f
gh-139122: Preserve UUID fields length errors
1st1 Oct 20, 2026
fdfaefe
gh-139122: Clarify version-specific UUID layouts
1st1 Oct 20, 2026
9d693e5
gh-139122: Apply UUID review cleanup
1st1 Oct 20, 2026
511783c
gh-139122: Fix concurrent UUID entropy refills and UUIDv7 state updates
1st1 Oct 20, 2026
e1085f0
gh-139122: Avoid subclass module-state lookup during UUID deallocation
1st1 Oct 20, 2026
69166ce
gh-139122: Mark UUID testing hook as an explicit re-export
1st1 Oct 20, 2026
c4d400d
gh-139122: Document UUID performance improvements in What’s New
1st1 Oct 20, 2026
fe8c947
gh-139122: Match Python UUID prefix and brace parsing
1st1 Oct 21, 2026
b6d7ff2
gh-139122: Assert UUID type association is a module during deallocation
1st1 Oct 21, 2026
7267353
gh-139122: Propagate SafeUUID lookup errors in is_safe getter
1st1 Oct 21, 2026
0802f7b
gh-139122: Honor subclass string conversion in UUID repr
1st1 Oct 21, 2026
54e040a
Apply batched suggestions from code review
1st1 Oct 21, 2026
f42e84a
gh-139122: Normalize line endings in UUID review suggestions
1st1 Oct 21, 2026
95b8544
gh-139122: Test UUID state restoration with frozendict
1st1 Oct 21, 2026
ce35192
gh-139122: Use shared hex conversion helper for UUID.hex
1st1 Oct 21, 2026
8ebad36
gh-139122: Format UUIDs directly into the result string
1st1 Oct 21, 2026
9e40767
gh-139122: Narrow UUID exception assertions and clean up test spacing
1st1 Oct 21, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Doc/library/uuid.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ which relays any information about the UUID's safety, using this enumeration:
variant and version number set according to :rfc:`9562`, overriding bits in the
given *hex*, *bytes*, *bytes_le*, *fields*, or *int*.

.. versionchanged:: next
Passing an object other than :class:`bytes` as *bytes* or *bytes_le*
now consistently raises :exc:`TypeError`. Previously, some invalid inputs
raised :exc:`AssertionError` or :exc:`ValueError`.

Comparison of UUID objects are made by way of comparing their
:attr:`UUID.int` attributes. Comparison with a non-UUID object
raises a :exc:`TypeError`.
Expand Down
40 changes: 40 additions & 0 deletions Doc/whatsnew/3.16.rst
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,18 @@ unicodedata
* The Unicode database has been updated to Unicode 18.0.0.


uuid
----

* :class:`uuid.UUID`, :func:`uuid.uuid4`, and :func:`uuid.uuid7` now have
C implementations, with a pure Python fallback.
In microbenchmarks, UUIDv4 and UUIDv7 generation are approximately 15 and
30 times faster, respectively, than the pure Python implementations.
UUID construction and string conversion are also faster; see
:ref:`whatsnew316-uuid-optimizations` for the benchmark results.
(Contributed by Yury Selivanov in :gh:`139123`.)


xml
---

Expand Down Expand Up @@ -953,6 +965,28 @@ re
:gh:`152056`.)


.. _whatsnew316-uuid-optimizations:

uuid
----

* C implementations accelerate UUID generation, construction, and string
conversion. Microbenchmarks comparing the C and pure Python implementations
measured the following speedups:

================================ =======
Operation Speedup
================================ =======
:func:`uuid.uuid4` generation 15.01x
:func:`uuid.uuid7` generation 29.64x
:class:`uuid.UUID` from a string 6.76x
:class:`uuid.UUID` from bytes 5.16x
:func:`str` conversion of a UUID 6.66x
================================ =======

(Contributed by Yury Selivanov in :gh:`139123`.)


Removed
========

Expand Down Expand Up @@ -1151,6 +1185,12 @@ that may require changes to your code.
:exc:`TypeError`.
(Contributed by Serhiy Storchaka in :gh:`152587`.)

* :class:`uuid.UUID` now consistently raises :exc:`TypeError` when the
Comment thread
1st1 marked this conversation as resolved.
*bytes* or *bytes_le* argument is not a :class:`bytes` object.
Previously, some invalid inputs raised :exc:`AssertionError` or
:exc:`ValueError`.
(Contributed by Yury Selivanov in :gh:`139123`.)

* :mod:`xml.dom.minidom` now raises :exc:`~xml.dom.InvalidCharacterErr`
for a name which is not a valid XML name,
:exc:`~xml.dom.WrongDocumentErr`
Expand Down
6 changes: 6 additions & 0 deletions Include/internal/pycore_global_objects_fini_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Include/internal/pycore_global_strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(byte_size)
STRUCT_FOR_ID(byteorder)
STRUCT_FOR_ID(bytes)
STRUCT_FOR_ID(bytes_le)
STRUCT_FOR_ID(bytes_per_sep)
STRUCT_FOR_ID(c_call)
STRUCT_FOR_ID(c_exception)
Expand Down Expand Up @@ -543,6 +544,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(hash_name)
STRUCT_FOR_ID(header)
STRUCT_FOR_ID(headers)
STRUCT_FOR_ID(hex)
STRUCT_FOR_ID(hi)
STRUCT_FOR_ID(hook)
STRUCT_FOR_ID(host)
Expand Down Expand Up @@ -576,13 +578,15 @@ struct _Py_global_strings {
STRUCT_FOR_ID(insert_comments)
STRUCT_FOR_ID(insert_pis)
STRUCT_FOR_ID(instructions)
STRUCT_FOR_ID(int)
STRUCT_FOR_ID(intern)
STRUCT_FOR_ID(intersection)
STRUCT_FOR_ID(interval)
STRUCT_FOR_ID(io)
STRUCT_FOR_ID(is_compress)
STRUCT_FOR_ID(is_raw)
STRUCT_FOR_ID(is_running)
STRUCT_FOR_ID(is_safe)
STRUCT_FOR_ID(is_struct)
STRUCT_FOR_ID(isatty)
STRUCT_FOR_ID(isinstance)
Expand Down Expand Up @@ -756,6 +760,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(query)
STRUCT_FOR_ID(queuetype)
STRUCT_FOR_ID(quotetabs)
STRUCT_FOR_ID(random_func)
STRUCT_FOR_ID(raw)
STRUCT_FOR_ID(read)
STRUCT_FOR_ID(read1)
Expand Down Expand Up @@ -870,6 +875,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(threading)
STRUCT_FOR_ID(throw)
STRUCT_FOR_ID(time)
STRUCT_FOR_ID(time_func)
STRUCT_FOR_ID(timeout)
STRUCT_FOR_ID(timer)
STRUCT_FOR_ID(times)
Expand Down
4 changes: 2 additions & 2 deletions Include/internal/pycore_pylifecycle.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ extern const char* _Py_gitversion(void);
// Export for '_asyncio' shared extension
PyAPI_FUNC(int) _Py_IsInterpreterFinalizing(PyInterpreterState *interp);

/* Random */
extern int _PyOS_URandom(void *buffer, Py_ssize_t size);
// Export for '_uuid' shared extension
PyAPI_FUNC(int) _PyOS_URandom(void *buffer, Py_ssize_t size);

// Export for '_random' shared extension
PyAPI_FUNC(int) _PyOS_URandomNonblock(void *buffer, Py_ssize_t size);
Expand Down
6 changes: 6 additions & 0 deletions Include/internal/pycore_runtime_init_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Include/internal/pycore_unicodeobject_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading