Version 1.1.0

- Made compatible with Python 3.8 (uses 3.10 typing from __future__)
- Made uuid7.time() also verify variant, to more reliably reject invalid UUIDs
This commit is contained in:
Leo Vasanko 2025-07-04 14:51:29 -06:00
parent 94f31c7d0b
commit 14a3fe63fe
2 changed files with 4 additions and 3 deletions

View File

@ -1,9 +1,9 @@
[project] [project]
name = "uuid7-standard" name = "uuid7-standard"
version = "1.0.0" version = "1.1.0"
description = "UUIDv7 with the final standard. Not to be confused with the uuid7 package on pypi, based on a draft version that was very different." description = "UUIDv7 with the final standard. Not to be confused with the uuid7 package on pypi, based on a draft version that was very different."
readme = "README.md" readme = "README.md"
requires-python = ">=3.10" requires-python = ">=3.8"
dependencies = [] dependencies = []
authors = [ authors = [
{name = "Leo Vasanko"}, {name = "Leo Vasanko"},

View File

@ -1,3 +1,4 @@
from __future__ import annotations
from datetime import datetime from datetime import datetime
from datetime import timezone as _tz from datetime import timezone as _tz
from secrets import token_bytes as _token_bytes from secrets import token_bytes as _token_bytes
@ -28,7 +29,7 @@ def time(u: UUID | str) -> datetime:
""" """
if not isinstance(u, UUID): if not isinstance(u, UUID):
u = UUID(u) u = UUID(u)
if u.version != 7: if u.version != 7 or u.variant != "specified in RFC 4122":
raise ValueError("Not a UUIDv7") raise ValueError("Not a UUIDv7")
ts = int.from_bytes(u.bytes[:6], "big") ts = int.from_bytes(u.bytes[:6], "big")
return datetime.fromtimestamp(ts / 1000, tz=_tz.utc) return datetime.fromtimestamp(ts / 1000, tz=_tz.utc)