Skip to content

Commit 3ff08f6

Browse files
authored
typing: refactor to follow typeshed (#67)
1 parent 926d2c2 commit 3ff08f6

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

python/uuid_utils/__init__.pyi

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1+
import builtins
12
import sys
23
from enum import Enum
34

45
from _typeshed import Unused
56
from typing_extensions import TypeAlias
67

78
# Because UUID has properties called int and bytes we need to rename these temporarily.
8-
_Int: TypeAlias = int
9-
_Bytes: TypeAlias = bytes
109
_FieldsType: TypeAlias = tuple[int, int, int, int, int, int]
1110

1211
__version__: str
@@ -74,44 +73,44 @@ class UUID:
7473
def __init__(
7574
self,
7675
hex: str | None = None,
77-
bytes: _Bytes | None = None,
78-
bytes_le: _Bytes | None = None,
76+
bytes: builtins.bytes | None = None,
77+
bytes_le: builtins.bytes | None = None,
7978
fields: _FieldsType | None = None,
80-
int: _Int | None = None,
81-
version: _Int | None = None,
79+
int: builtins.int | None = None,
80+
version: builtins.int | None = None,
8281
*,
8382
is_safe: SafeUUID = ...,
8483
) -> None: ...
8584
@property
8685
def is_safe(self) -> SafeUUID: ...
8786
@property
88-
def bytes(self) -> _Bytes: ...
87+
def bytes(self) -> builtins.bytes: ...
8988
@property
90-
def bytes_le(self) -> _Bytes: ...
89+
def bytes_le(self) -> builtins.bytes: ...
9190
@property
92-
def clock_seq(self) -> _Int: ...
91+
def clock_seq(self) -> builtins.int: ...
9392
@property
94-
def clock_seq_hi_variant(self) -> _Int: ...
93+
def clock_seq_hi_variant(self) -> builtins.int: ...
9594
@property
96-
def clock_seq_low(self) -> _Int: ...
95+
def clock_seq_low(self) -> builtins.int: ...
9796
@property
9897
def fields(self) -> _FieldsType: ...
9998
@property
10099
def hex(self) -> str: ...
101100
@property
102-
def int(self) -> _Int: ...
101+
def int(self) -> builtins.int: ...
103102
@property
104-
def node(self) -> _Int: ...
103+
def node(self) -> builtins.int: ...
105104
@property
106-
def time(self) -> _Int: ...
105+
def time(self) -> builtins.int: ...
107106
@property
108-
def time_hi_version(self) -> _Int: ...
107+
def time_hi_version(self) -> builtins.int: ...
109108
@property
110-
def time_low(self) -> _Int: ...
109+
def time_low(self) -> builtins.int: ...
111110
@property
112-
def time_mid(self) -> _Int: ...
111+
def time_mid(self) -> builtins.int: ...
113112
@property
114-
def timestamp(self) -> _Int:
113+
def timestamp(self) -> builtins.int:
115114
"""Get UUID timestamp milliseconds since epoch.
116115
Only works for UUID versions 1, 6 and 7, otherwise raises ValueError."""
117116
...
@@ -121,8 +120,8 @@ class UUID:
121120
@property
122121
def variant(self) -> str: ...
123122
@property
124-
def version(self) -> _Int | None: ...
125-
def __int__(self) -> _Int: ...
123+
def version(self) -> builtins.int | None: ...
124+
def __int__(self) -> builtins.int: ...
126125
def __eq__(self, other: object) -> bool: ...
127126
def __lt__(self, other: UUID) -> bool: ...
128127
def __le__(self, other: UUID) -> bool: ...
@@ -135,7 +134,7 @@ if sys.version_info >= (3, 9):
135134
else:
136135
def getnode(*, getters: Unused = None) -> int: ... # undocumented
137136

138-
def uuid1(node: _Int | None = None, clock_seq: _Int | None = None) -> UUID:
137+
def uuid1(node: int | None = None, clock_seq: int | None = None) -> UUID:
139138
"""Generate a UUID from a host ID, sequence number, and the current time.
140139
If 'node' is not given, getnode() is used to obtain the hardware
141140
address. If 'clock_seq' is given, it is used as the sequence number;
@@ -165,19 +164,19 @@ else:
165164
...
166165

167166
def uuid6(
168-
node: _Int | None = None, timestamp: _Int | None = None, nanos: _Int | None = None
167+
node: int | None = None, timestamp: int | None = None, nanos: int | None = None
169168
) -> UUID:
170169
"""Generate a version 6 UUID using the given timestamp and a host ID.
171170
This is similar to version 1 UUIDs,
172171
except that it is lexicographically sortable by timestamp.
173172
"""
174173
...
175174

176-
def uuid7(timestamp: _Int | None = None, nanos: _Int | None = None) -> UUID:
175+
def uuid7(timestamp: int | None = None, nanos: int | None = None) -> UUID:
177176
"""Generate a version 7 UUID using a time value and random bytes."""
178177
...
179178

180-
def uuid8(bytes: _Bytes) -> UUID:
179+
def uuid8(bytes: bytes) -> UUID:
181180
"""Generate a custom UUID comprised almost entirely of user-supplied bytes."""
182181
...
183182

0 commit comments

Comments
 (0)