From 9d0a704c819ff23c5b2d1ac8f82d8694b802900f Mon Sep 17 00:00:00 2001 From: Asif Saif Uddin Date: Wed, 28 May 2025 09:15:28 +0000 Subject: [PATCH 1/8] Update uuid to uuid7 --- kombu/utils/uuid.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kombu/utils/uuid.py b/kombu/utils/uuid.py index 917eccf32..b4a3646e7 100644 --- a/kombu/utils/uuid.py +++ b/kombu/utils/uuid.py @@ -2,7 +2,7 @@ from __future__ import annotations from typing import Callable -from uuid import UUID, uuid4 +from uuid import UUID, uuid4, uuid7 def uuid(_uuid: Callable[[], UUID] = uuid4) -> str: From e358ed87b2f5fe62353d9244ea8b0e72e69984c8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 28 May 2025 09:15:52 +0000 Subject: [PATCH 2/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- kombu/utils/uuid.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kombu/utils/uuid.py b/kombu/utils/uuid.py index b4a3646e7..917eccf32 100644 --- a/kombu/utils/uuid.py +++ b/kombu/utils/uuid.py @@ -2,7 +2,7 @@ from __future__ import annotations from typing import Callable -from uuid import UUID, uuid4, uuid7 +from uuid import UUID, uuid4 def uuid(_uuid: Callable[[], UUID] = uuid4) -> str: From 6ef75cfc9c2246b0c19d9be0354469cfd20770f5 Mon Sep 17 00:00:00 2001 From: Asif Saif Uddin Date: Wed, 28 May 2025 09:23:18 +0000 Subject: [PATCH 3/8] Update uuid.py --- kombu/utils/uuid.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/kombu/utils/uuid.py b/kombu/utils/uuid.py index 917eccf32..b8bc0f5ec 100644 --- a/kombu/utils/uuid.py +++ b/kombu/utils/uuid.py @@ -2,7 +2,13 @@ from __future__ import annotations from typing import Callable -from uuid import UUID, uuid4 +try: + # Python 3.11 or later + from uuid import UUID, uuid7 +except ImportError: + # Fallback for older Python versions + from uuid import UUID, uuid4 + def uuid(_uuid: Callable[[], UUID] = uuid4) -> str: From 6c2130410a0283e8e4920a2f1fb9e02992ee9f30 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 28 May 2025 09:23:36 +0000 Subject: [PATCH 4/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- kombu/utils/uuid.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kombu/utils/uuid.py b/kombu/utils/uuid.py index b8bc0f5ec..3aa288f9a 100644 --- a/kombu/utils/uuid.py +++ b/kombu/utils/uuid.py @@ -2,9 +2,10 @@ from __future__ import annotations from typing import Callable + try: # Python 3.11 or later - from uuid import UUID, uuid7 + from uuid import UUID except ImportError: # Fallback for older Python versions from uuid import UUID, uuid4 From 8edd4fd4f4568de1f51a040556e2118eef844fe6 Mon Sep 17 00:00:00 2001 From: Asif Saif Uddin Date: Wed, 28 May 2025 09:33:00 +0000 Subject: [PATCH 5/8] Update uuid.py --- kombu/utils/uuid.py | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/kombu/utils/uuid.py b/kombu/utils/uuid.py index 3aa288f9a..45e47460b 100644 --- a/kombu/utils/uuid.py +++ b/kombu/utils/uuid.py @@ -1,22 +1,34 @@ -"""UUID utilities.""" from __future__ import annotations -from typing import Callable +from uuid import uuid4 +from typing import Literal try: # Python 3.11 or later - from uuid import UUID + from uuid import uuid7 except ImportError: # Fallback for older Python versions - from uuid import UUID, uuid4 + 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 generate_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 and 'uuid7' in globals(): + return str(uuid7()) + elif version == 4: + return str(uuid4()) + else: + raise ValueError("Invalid UUID version. Please choose either 4 or 7.") From 1774c0d032ccb52f7fce63770ee46b865050b632 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 28 May 2025 09:34:52 +0000 Subject: [PATCH 6/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- kombu/utils/uuid.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kombu/utils/uuid.py b/kombu/utils/uuid.py index 45e47460b..a5feee9fd 100644 --- a/kombu/utils/uuid.py +++ b/kombu/utils/uuid.py @@ -1,7 +1,7 @@ from __future__ import annotations -from uuid import uuid4 from typing import Literal +from uuid import uuid4 try: # Python 3.11 or later From 42cff94533ca609c41df799217fec0c654009d3f Mon Sep 17 00:00:00 2001 From: Asif Saif Uddin Date: Wed, 28 May 2025 09:36:07 +0000 Subject: [PATCH 7/8] Update kombu/utils/uuid.py --- kombu/utils/uuid.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kombu/utils/uuid.py b/kombu/utils/uuid.py index a5feee9fd..e290dd6c7 100644 --- a/kombu/utils/uuid.py +++ b/kombu/utils/uuid.py @@ -12,7 +12,7 @@ def uuid7(): """Fallback to UUID4 if UUID7 is not available.""" return uuid4() -def generate_uuid(version: Literal[4, 7] = 7) -> str: +def uuid(version: Literal[4, 7] = 7) -> str: """Generate a unique ID based on the specified UUID version (4 or 7). Parameters From 70f8defd39e38016c99b41040a261f9f7e47f3a0 Mon Sep 17 00:00:00 2001 From: Asif Saif Uddin Date: Wed, 28 May 2025 09:40:15 +0000 Subject: [PATCH 8/8] Update kombu/utils/uuid.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- kombu/utils/uuid.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kombu/utils/uuid.py b/kombu/utils/uuid.py index e290dd6c7..66cd160b6 100644 --- a/kombu/utils/uuid.py +++ b/kombu/utils/uuid.py @@ -26,7 +26,7 @@ def uuid(version: Literal[4, 7] = 7) -> str: str A string representation of the generated UUID. """ - if version == 7 and 'uuid7' in globals(): + if version == 7: return str(uuid7()) elif version == 4: return str(uuid4())