Skip to content

Commit aed8c3f

Browse files
authoredJul 8, 2023
Replace aliases by builtins.* in uuid (python#10422)
These aliases were used because the class has properties called `int` and `bytes`. I think it is better to use the shadowed types from the builtins module. This should not change anything from the type checking side but it improves the IDE experience[^1]. [^1]: I was using uuid recently and the aliases showed up in vscode, I thought they were uuid special types and had to look in the stub to know what they are.
1 parent e7ba032 commit aed8c3f

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed
 

Diff for: ‎stdlib/uuid.pyi

+19-21
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1+
import builtins
12
import sys
23
from _typeshed import Unused
34
from enum import Enum
45
from typing_extensions import TypeAlias
56

6-
# Because UUID has properties called int and bytes we need to rename these temporarily.
7-
_Int: TypeAlias = int
8-
_Bytes: TypeAlias = bytes
97
_FieldsType: TypeAlias = tuple[int, int, int, int, int, int]
108

119
class SafeUUID(Enum):
@@ -17,49 +15,49 @@ class UUID:
1715
def __init__(
1816
self,
1917
hex: str | None = None,
20-
bytes: _Bytes | None = None,
21-
bytes_le: _Bytes | None = None,
18+
bytes: builtins.bytes | None = None,
19+
bytes_le: builtins.bytes | None = None,
2220
fields: _FieldsType | None = None,
23-
int: _Int | None = None,
24-
version: _Int | None = None,
21+
int: builtins.int | None = None,
22+
version: builtins.int | None = None,
2523
*,
2624
is_safe: SafeUUID = ...,
2725
) -> None: ...
2826
@property
2927
def is_safe(self) -> SafeUUID: ...
3028
@property
31-
def bytes(self) -> _Bytes: ...
29+
def bytes(self) -> builtins.bytes: ...
3230
@property
33-
def bytes_le(self) -> _Bytes: ...
31+
def bytes_le(self) -> builtins.bytes: ...
3432
@property
35-
def clock_seq(self) -> _Int: ...
33+
def clock_seq(self) -> builtins.int: ...
3634
@property
37-
def clock_seq_hi_variant(self) -> _Int: ...
35+
def clock_seq_hi_variant(self) -> builtins.int: ...
3836
@property
39-
def clock_seq_low(self) -> _Int: ...
37+
def clock_seq_low(self) -> builtins.int: ...
4038
@property
4139
def fields(self) -> _FieldsType: ...
4240
@property
4341
def hex(self) -> str: ...
4442
@property
45-
def int(self) -> _Int: ...
43+
def int(self) -> builtins.int: ...
4644
@property
47-
def node(self) -> _Int: ...
45+
def node(self) -> builtins.int: ...
4846
@property
49-
def time(self) -> _Int: ...
47+
def time(self) -> builtins.int: ...
5048
@property
51-
def time_hi_version(self) -> _Int: ...
49+
def time_hi_version(self) -> builtins.int: ...
5250
@property
53-
def time_low(self) -> _Int: ...
51+
def time_low(self) -> builtins.int: ...
5452
@property
55-
def time_mid(self) -> _Int: ...
53+
def time_mid(self) -> builtins.int: ...
5654
@property
5755
def urn(self) -> str: ...
5856
@property
5957
def variant(self) -> str: ...
6058
@property
61-
def version(self) -> _Int | None: ...
62-
def __int__(self) -> _Int: ...
59+
def version(self) -> builtins.int | None: ...
60+
def __int__(self) -> builtins.int: ...
6361
def __eq__(self, other: object) -> bool: ...
6462
def __lt__(self, other: UUID) -> bool: ...
6563
def __le__(self, other: UUID) -> bool: ...
@@ -72,7 +70,7 @@ if sys.version_info >= (3, 9):
7270
else:
7371
def getnode(*, getters: Unused = None) -> int: ... # undocumented
7472

75-
def uuid1(node: _Int | None = None, clock_seq: _Int | None = None) -> UUID: ...
73+
def uuid1(node: int | None = None, clock_seq: int | None = None) -> UUID: ...
7674

7775
if sys.version_info >= (3, 12):
7876
def uuid3(namespace: UUID, name: str | bytes) -> UUID: ...

0 commit comments

Comments
 (0)