Skip to content
Draft
Changes from all commits
Commits
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
39 changes: 29 additions & 10 deletions kombu/utils/uuid.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
"""UUID utilities."""
from __future__ import annotations

from typing import Callable
from uuid import UUID, uuid4
from typing import Literal
from uuid import uuid4

try:
# Python 3.11 or later

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Python 3.11 or later
# Python 3.14 or later

from uuid import uuid7
except ImportError:
# Fallback for older Python versions
def uuid7():
"""Fallback to UUID4 if UUID7 is not available."""
return uuid4()

def uuid(_uuid: Callable[[], UUID] = uuid4) -> str:
"""Generate unique id in UUID4 format.
See Also
--------
For now this is provided by :func:`uuid.uuid4`.
def uuid(version: Literal[4, 7] = 7) -> str:
"""Generate a unique ID based on the specified UUID version (4 or 7).
Parameters
----------
version : Literal[4, 7]
The UUID version to use for generating the unique ID. Defaults to 7.
If UUID7 is unavailable, it falls back to UUID4 regardless of the input.
Returns
-------
str
A string representation of the generated UUID.
"""
return str(_uuid())
if version == 7:
return str(uuid7())
elif version == 4:
return str(uuid4())

Check warning on line 32 in kombu/utils/uuid.py

View check run for this annotation

Codecov / codecov/patch

kombu/utils/uuid.py#L32

Added line #L32 was not covered by tests
else:
raise ValueError("Invalid UUID version. Please choose either 4 or 7.")

Check warning on line 34 in kombu/utils/uuid.py

View check run for this annotation

Codecov / codecov/patch

kombu/utils/uuid.py#L34

Added line #L34 was not covered by tests
Loading