-
-
Notifications
You must be signed in to change notification settings - Fork 959
Update uuid to uuid7 #2303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
auvipy
wants to merge
8
commits into
main
Choose a base branch
from
uuid
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Update uuid to uuid7 #2303
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9d0a704
Update uuid to uuid7
auvipy e358ed8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 6ef75cf
Update uuid.py
auvipy 6c21304
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 8edd4fd
Update uuid.py
auvipy 1774c0d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 42cff94
Update kombu/utils/uuid.py
auvipy 70f8def
Update kombu/utils/uuid.py
auvipy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
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 generate_uuid(version: Literal[4, 7] = 7) -> str: | ||
"""Generate a unique ID based on the specified UUID version (4 or 7). | ||
auvipy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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()) | ||
auvipy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
elif version == 4: | ||
return str(uuid4()) | ||
else: | ||
raise ValueError("Invalid UUID version. Please choose either 4 or 7.") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.