Skip to content

Commit 0fd67d8

Browse files
move init of counter to __init__
1 parent f04e751 commit 0fd67d8

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

tests/utils.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,22 @@
44

55

66
class SequenceGenerator:
7-
_instance = None
8-
_lock = Lock()
7+
_instance: SequenceGenerator | None = None
8+
_lock: Lock = Lock()
9+
_counter: int
910

10-
def __init__(self):
11-
self._counter = 1
11+
def __init__(self) -> None:
12+
if not hasattr(self, "_counter"):
13+
self._counter = 1
1214

13-
def __new__(cls):
15+
def __new__(cls) -> SequenceGenerator:
1416
if cls._instance is None:
1517
with cls._lock:
1618
if cls._instance is None:
1719
cls._instance = super().__new__(cls)
18-
cls._instance._counter = 1
1920
return cls._instance
2021

21-
def next(self):
22+
def next(self) -> int:
2223
with self._lock:
2324
current = self._counter
2425
self._counter += 1

0 commit comments

Comments
 (0)