Skip to content

Commit 5b47391

Browse files
committed
update typehints
1 parent 3f78c55 commit 5b47391

File tree

2 files changed

+16
-23
lines changed

2 files changed

+16
-23
lines changed

python/uuid_utils/__init__.pyi

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import sys
33
from typing import Final
44
from uuid import SafeUUID
55

6-
from typing_extensions import TypeAlias
6+
from typing_extensions import LiteralString, TypeAlias
77

88
# Because UUID has properties called int and bytes we need to rename these temporarily.
99
_FieldsType: TypeAlias = tuple[int, int, int, int, int, int]
@@ -65,6 +65,9 @@ class UUID:
6565
otherwise raises ValueError.
6666
"""
6767

68+
is_safe: Final[SafeUUID]
69+
int: Final[builtins.int]
70+
6871
def __init__(
6972
self,
7073
hex: str | None = None,
@@ -77,8 +80,6 @@ class UUID:
7780
is_safe: SafeUUID = ...,
7881
) -> None: ...
7982
@property
80-
def is_safe(self) -> SafeUUID: ...
81-
@property
8283
def bytes(self) -> builtins.bytes: ...
8384
@property
8485
def bytes_le(self) -> builtins.bytes: ...
@@ -93,8 +94,6 @@ class UUID:
9394
@property
9495
def hex(self) -> str: ...
9596
@property
96-
def int(self) -> builtins.int: ...
97-
@property
9897
def node(self) -> builtins.int: ...
9998
@property
10099
def time(self) -> builtins.int: ...
@@ -182,14 +181,14 @@ def uuid8(bytes: bytes) -> UUID:
182181
"""Generate a custom UUID comprised almost entirely of user-supplied bytes."""
183182
...
184183

185-
NAMESPACE_DNS: UUID
186-
NAMESPACE_URL: UUID
187-
NAMESPACE_OID: UUID
188-
NAMESPACE_X500: UUID
189-
RESERVED_NCS: str
190-
RFC_4122: str
191-
RESERVED_MICROSOFT: str
192-
RESERVED_FUTURE: str
184+
NAMESPACE_DNS: Final[UUID]
185+
NAMESPACE_URL: Final[UUID]
186+
NAMESPACE_OID: Final[UUID]
187+
NAMESPACE_X500: Final[UUID]
188+
RESERVED_NCS: Final[LiteralString]
189+
RFC_4122: Final[LiteralString]
190+
RESERVED_MICROSOFT: Final[LiteralString]
191+
RESERVED_FUTURE: Final[LiteralString]
193192
NIL: Final[UUID]
194193
MAX: Final[UUID]
195194

python/uuid_utils/compat/__init__.pyi

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,7 @@ from uuid import (
1414
getnode,
1515
)
1616

17-
from typing_extensions import TypeAlias
18-
19-
# Because UUID has properties called int and bytes we need to rename these temporarily.
20-
_Int: TypeAlias = int
21-
_Bytes: TypeAlias = bytes
22-
23-
def uuid1(node: _Int | None = None, clock_seq: _Int | None = None) -> UUID:
17+
def uuid1(node: int | None = None, clock_seq: int | None = None) -> UUID:
2418
"""Generate a UUID from a host ID, sequence number, and the current time.
2519
If 'node' is not given, getnode() is used to obtain the hardware
2620
address. If 'clock_seq' is given, it is used as the sequence number;
@@ -50,18 +44,18 @@ else:
5044
"""Generate a UUID from the SHA-1 hash of a namespace UUID and a name."""
5145
...
5246

53-
def uuid6(node: _Int | None = None, timestamp: _Int | None = None) -> UUID:
47+
def uuid6(node: int | None = None, timestamp: int | None = None) -> UUID:
5448
"""Generate a version 6 UUID using the given timestamp and a host ID.
5549
This is similar to version 1 UUIDs,
5650
except that it is lexicographically sortable by timestamp.
5751
"""
5852
...
5953

60-
def uuid7(timestamp: _Int | None = None, nanos: _Int | None = None) -> UUID:
54+
def uuid7(timestamp: int | None = None, nanos: int | None = None) -> UUID:
6155
"""Generate a version 7 UUID using a time value and random bytes."""
6256
...
6357

64-
def uuid8(bytes: _Bytes) -> UUID:
58+
def uuid8(bytes: bytes) -> UUID:
6559
"""Generate a custom UUID comprised almost entirely of user-supplied bytes.."""
6660
...
6761

0 commit comments

Comments
 (0)