Skip to content

Commit

Permalink
typing: refactor to follow typeshed (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 authored Sep 10, 2024
1 parent 926d2c2 commit 3ff08f6
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions python/uuid_utils/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import builtins
import sys
from enum import Enum

from _typeshed import Unused
from typing_extensions import TypeAlias

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

__version__: str
Expand Down Expand Up @@ -74,44 +73,44 @@ class UUID:
def __init__(
self,
hex: str | None = None,
bytes: _Bytes | None = None,
bytes_le: _Bytes | None = None,
bytes: builtins.bytes | None = None,
bytes_le: builtins.bytes | None = None,
fields: _FieldsType | None = None,
int: _Int | None = None,
version: _Int | None = None,
int: builtins.int | None = None,
version: builtins.int | None = None,
*,
is_safe: SafeUUID = ...,
) -> None: ...
@property
def is_safe(self) -> SafeUUID: ...
@property
def bytes(self) -> _Bytes: ...
def bytes(self) -> builtins.bytes: ...
@property
def bytes_le(self) -> _Bytes: ...
def bytes_le(self) -> builtins.bytes: ...
@property
def clock_seq(self) -> _Int: ...
def clock_seq(self) -> builtins.int: ...
@property
def clock_seq_hi_variant(self) -> _Int: ...
def clock_seq_hi_variant(self) -> builtins.int: ...
@property
def clock_seq_low(self) -> _Int: ...
def clock_seq_low(self) -> builtins.int: ...
@property
def fields(self) -> _FieldsType: ...
@property
def hex(self) -> str: ...
@property
def int(self) -> _Int: ...
def int(self) -> builtins.int: ...
@property
def node(self) -> _Int: ...
def node(self) -> builtins.int: ...
@property
def time(self) -> _Int: ...
def time(self) -> builtins.int: ...
@property
def time_hi_version(self) -> _Int: ...
def time_hi_version(self) -> builtins.int: ...
@property
def time_low(self) -> _Int: ...
def time_low(self) -> builtins.int: ...
@property
def time_mid(self) -> _Int: ...
def time_mid(self) -> builtins.int: ...
@property
def timestamp(self) -> _Int:
def timestamp(self) -> builtins.int:
"""Get UUID timestamp milliseconds since epoch.
Only works for UUID versions 1, 6 and 7, otherwise raises ValueError."""
...
Expand All @@ -121,8 +120,8 @@ class UUID:
@property
def variant(self) -> str: ...
@property
def version(self) -> _Int | None: ...
def __int__(self) -> _Int: ...
def version(self) -> builtins.int | None: ...
def __int__(self) -> builtins.int: ...
def __eq__(self, other: object) -> bool: ...
def __lt__(self, other: UUID) -> bool: ...
def __le__(self, other: UUID) -> bool: ...
Expand All @@ -135,7 +134,7 @@ if sys.version_info >= (3, 9):
else:
def getnode(*, getters: Unused = None) -> int: ... # undocumented

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

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

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

def uuid8(bytes: _Bytes) -> UUID:
def uuid8(bytes: bytes) -> UUID:
"""Generate a custom UUID comprised almost entirely of user-supplied bytes."""
...

Expand Down

0 comments on commit 3ff08f6

Please sign in to comment.