Skip to content

Commit 860c96f

Browse files
committed
Improve docstrings
1 parent ee74c55 commit 860c96f

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

src/sonyflake_turbo/_sonyflake.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,9 @@ PyDoc_STRVAR(sonyflake_doc,
326326
"SonyFlake ID generator implementation that combines multiple ID generators into one to improve throughput.\n"
327327
"Upon counter overflow, it switches to the next machine ID and sleeps only when all machine ids are exhausted for time"
328328
"frame of 10ms. This produces always-increasing id sequence.\n"
329+
"\n"
330+
"Important:\n"
331+
" Implementation uses thread locks and blocking sleeps.\n"
329332
);
330333

331334
static PyType_Slot sonyflake_type_slots[] = {
@@ -423,6 +426,8 @@ PyDoc_STRVAR(machine_id_lcg_doc,
423426
"MachineIDLCG(seed, /)\n--\n\n"
424427
"LCG with params a=32309, c=13799, m=65536.\n"
425428
"Provides a thread-safe way to generate pseudo-random sequence of machine ids to be used as args to SonyFlake.\n"
429+
"\n"
430+
"You generally want to use this class as a singleton, i.e. create one instance and reuse it.\n"
426431
);
427432

428433

src/sonyflake_turbo/_sonyflake.pyi

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,39 @@ SONYFLAKE_MACHINE_ID_OFFSET: int
1414
SONYFLAKE_TIME_OFFSET: int
1515

1616
class SonyFlake:
17-
def __init__(self, *machine_id: int, start_time: Optional[int] = None): ...
18-
def __iter__(self) -> Self: ...
19-
def __next__(self) -> int: ...
17+
def __init__(self, *machine_id: int, start_time: Optional[int] = None):
18+
"""Initialize SonyFlake ID generator.
19+
20+
Args:
21+
machine_id: Unique ID(s) of a SonyFlake instance.
22+
A number in range [0, 0xFFFF]. Must be provided at least one,
23+
at most 65536, and have no duplicates.
24+
start_time: Time since which the SonyFlake time is defined as the
25+
elapsed time. A UNIX timestamp in UTC time zone, if unset
26+
defaults to 1409529600 (2014-09-01 00:00:00 UTC). Must be in
27+
the past.
28+
29+
Raises:
30+
ValueError: Invalid values of ``machine_id`` or ``start_time``.
31+
TypeError: ``machine_id`` or ``start_time`` are not integers.
32+
"""
33+
34+
def __iter__(self) -> Self:
35+
"""Returns ``self``."""
36+
37+
def __next__(self) -> int:
38+
"""Produce a SonyFlake ID."""
2039

2140
class MachineIDLCG:
22-
def __init__(self, x: int, /) -> None: ...
23-
def __iter__(self) -> Self: ...
24-
def __next__(self) -> int: ...
41+
def __new__(cls, seed: int, /) -> Self:
42+
"""Make a LCG.
43+
44+
Args:
45+
seed: Starting seed.
46+
"""
47+
48+
def __iter__(self) -> Self:
49+
"""Returns ``self``."""
50+
51+
def __next__(self) -> int:
52+
"""Produce a Machine ID for :class:`SonyFlake`."""

0 commit comments

Comments
 (0)