Skip to content

Commit 5862b4a

Browse files
committed
Use slots option in dataclasses
Signed-off-by: Sreekanth <prsreekanth920@gmail.com>
1 parent d9c84c3 commit 5862b4a

8 files changed

Lines changed: 28 additions & 97 deletions

File tree

packages/pynumaflow/pynumaflow/accumulator/_dtypes.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class WindowOperation(IntEnum):
2222
APPEND = (2,)
2323

2424

25-
@dataclass(init=False)
25+
@dataclass(init=False, slots=True)
2626
class Datum:
2727
"""
2828
Class to define the important information for the event.
@@ -48,8 +48,6 @@ class Datum:
4848
```
4949
"""
5050

51-
__slots__ = ("_keys", "_value", "_event_time", "_watermark", "_headers", "_id")
52-
5351
_keys: list[str]
5452
_value: bytes
5553
_event_time: datetime
@@ -132,12 +130,10 @@ def id(self) -> str:
132130
return self._id
133131

134132

135-
@dataclass(init=False)
133+
@dataclass(init=False, slots=True)
136134
class IntervalWindow:
137135
"""Defines the start and end of the interval window for the event."""
138136

139-
__slots__ = ("_start", "_end")
140-
141137
_start: datetime
142138
_end: datetime
143139

@@ -164,15 +160,13 @@ def end(self) -> datetime:
164160
return self._end
165161

166162

167-
@dataclass(init=False)
163+
@dataclass(init=False, slots=True)
168164
class KeyedWindow:
169165
"""
170166
Defines the window for a accumulator operation which includes the
171167
interval window along with the slot.
172168
"""
173169

174-
__slots__ = ("_window", "_slot", "_keys")
175-
176170
_window: IntervalWindow
177171
_slot: str
178172
_keys: list[str]
@@ -359,7 +353,7 @@ def payload(self) -> Datum:
359353
return self._payload
360354

361355

362-
@dataclass(init=False)
356+
@dataclass(init=False, slots=True)
363357
class Message:
364358
"""
365359
Basic datatype for data passing to the next vertex/vertices.
@@ -374,8 +368,6 @@ class Message:
374368
id: message id (optional)
375369
"""
376370

377-
__slots__ = ("_value", "_keys", "_tags", "_watermark", "_event_time", "_headers", "_id")
378-
379371
_value: bytes
380372
_keys: list[str]
381373
_tags: list[str]

packages/pynumaflow/pynumaflow/batchmapper/_dtypes.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
Bs = TypeVar("Bs", bound="BatchResponses")
1313

1414

15-
@dataclass(init=False)
15+
@dataclass(init=False, slots=True)
1616
class Message:
1717
"""
1818
Basic datatype for data passing to the next vertex/vertices.
@@ -23,8 +23,6 @@ class Message:
2323
tags: list of tags for conditional forwarding (optional)
2424
"""
2525

26-
__slots__ = ("_value", "_keys", "_tags")
27-
2826
_value: bytes
2927
_keys: list[str]
3028
_tags: list[str]
@@ -55,7 +53,7 @@ def tags(self) -> list[str]:
5553
return self._tags
5654

5755

58-
@dataclass(init=False)
56+
@dataclass(init=False, slots=True)
5957
class Datum:
6058
"""
6159
Class to define the important information for the event.
@@ -69,8 +67,6 @@ class Datum:
6967
id: the unique ID for this request
7068
"""
7169

72-
__slots__ = ("_keys", "_value", "_event_time", "_watermark", "_headers", "_id")
73-
7470
_keys: list[str]
7571
_value: bytes
7672
_event_time: datetime

packages/pynumaflow/pynumaflow/mapper/_dtypes.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
Ms = TypeVar("Ms", bound="Messages")
1414

1515

16-
@dataclass(init=False)
16+
@dataclass(init=False, slots=True)
1717
class Message:
1818
"""
1919
Basic datatype for data passing to the next vertex/vertices.
@@ -25,8 +25,6 @@ class Message:
2525
user_metadata: metadata for the message (optional)
2626
"""
2727

28-
__slots__ = ("_value", "_keys", "_tags", "_user_metadata")
29-
3028
_value: bytes
3129
_keys: list[str]
3230
_tags: list[str]
@@ -112,7 +110,7 @@ def items(self) -> Sequence[M]:
112110
return self._messages
113111

114112

115-
@dataclass(init=False)
113+
@dataclass(init=False, slots=True)
116114
class Datum:
117115
"""
118116
Class to define the important information for the event.
@@ -139,16 +137,6 @@ class Datum:
139137
```
140138
"""
141139

142-
__slots__ = (
143-
"_keys",
144-
"_value",
145-
"_event_time",
146-
"_watermark",
147-
"_headers",
148-
"_user_metadata",
149-
"_system_metadata",
150-
)
151-
152140
_keys: list[str]
153141
_value: bytes
154142
_event_time: datetime

packages/pynumaflow/pynumaflow/mapstreamer/_dtypes.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
Ms = TypeVar("Ms", bound="Messages")
1313

1414

15-
@dataclass(init=False)
15+
@dataclass(init=False, slots=True)
1616
class Message:
1717
"""
1818
Basic datatype for data passing to the next vertex/vertices.
@@ -23,8 +23,6 @@ class Message:
2323
tags: list of tags for conditional forwarding (optional)
2424
"""
2525

26-
__slots__ = ("_value", "_keys", "_tags")
27-
2826
_value: bytes
2927
_keys: list[str]
3028
_tags: list[str]
@@ -98,7 +96,7 @@ def items(self) -> list[Message]:
9896
return self._messages
9997

10098

101-
@dataclass(init=False)
99+
@dataclass(init=False, slots=True)
102100
class Datum:
103101
"""
104102
Class to define the important information for the event.
@@ -125,8 +123,6 @@ class Datum:
125123
```
126124
"""
127125

128-
__slots__ = ("_keys", "_value", "_event_time", "_watermark", "_headers")
129-
130126
_keys: list[str]
131127
_value: bytes
132128
_event_time: datetime

packages/pynumaflow/pynumaflow/reducer/_dtypes.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class WindowOperation(IntEnum):
2929
APPEND = (4,)
3030

3131

32-
@dataclass(init=False)
32+
@dataclass(init=False, slots=True)
3333
class Message:
3434
"""
3535
Basic datatype for data passing to the next vertex/vertices.
@@ -40,8 +40,6 @@ class Message:
4040
tags: []string tags for conditional forwarding (optional)
4141
"""
4242

43-
__slots__ = ("_value", "_keys", "_tags")
44-
4543
_value: bytes
4644
_keys: list[str]
4745
_tags: list[str]
@@ -115,7 +113,7 @@ def items(self) -> list[Message]:
115113
return self._messages
116114

117115

118-
@dataclass(init=False)
116+
@dataclass(init=False, slots=True)
119117
class Datum:
120118
"""
121119
Class to define the important information for the event.
@@ -142,8 +140,6 @@ class Datum:
142140
```
143141
"""
144142

145-
__slots__ = ("_keys", "_value", "_event_time", "_watermark", "_headers")
146-
147143
_keys: list[str]
148144
_value: bytes
149145
_event_time: datetime
@@ -194,12 +190,10 @@ def headers(self) -> dict[str, str]:
194190
return self._headers.copy()
195191

196192

197-
@dataclass(init=False)
193+
@dataclass(init=False, slots=True)
198194
class IntervalWindow:
199195
"""Defines the start and end of the interval window for the event."""
200196

201-
__slots__ = ("_start", "_end")
202-
203197
_start: datetime
204198
_end: datetime
205199

@@ -218,15 +212,13 @@ def end(self):
218212
return self._end
219213

220214

221-
@dataclass(init=False)
215+
@dataclass(init=False, slots=True)
222216
class ReduceWindow:
223217
"""
224218
Defines the window for a reduce operation which includes the
225219
interval window along with the slot.
226220
"""
227221

228-
__slots__ = ("_window", "_slot")
229-
230222
_window: IntervalWindow
231223
_slot: str
232224

@@ -255,12 +247,10 @@ def window(self):
255247
return self._window
256248

257249

258-
@dataclass(init=False)
250+
@dataclass(init=False, slots=True)
259251
class Metadata:
260252
"""Defines the metadata for the event."""
261253

262-
__slots__ = ("_interval_window",)
263-
264254
_interval_window: IntervalWindow
265255

266256
def __init__(self, interval_window: IntervalWindow):

packages/pynumaflow/pynumaflow/reducestreamer/_dtypes.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class WindowOperation(IntEnum):
2222
APPEND = (4,)
2323

2424

25-
@dataclass(init=False)
25+
@dataclass(init=False, slots=True)
2626
class Datum:
2727
"""
2828
Class to define the important information for the event.
@@ -49,8 +49,6 @@ class Datum:
4949
```
5050
"""
5151

52-
__slots__ = ("_keys", "_value", "_event_time", "_watermark", "_headers")
53-
5452
_keys: list[str]
5553
_value: bytes
5654
_event_time: datetime
@@ -101,12 +99,10 @@ def headers(self) -> dict[str, str]:
10199
return self._headers
102100

103101

104-
@dataclass(init=False)
102+
@dataclass(init=False, slots=True)
105103
class IntervalWindow:
106104
"""Defines the start and end of the interval window for the event."""
107105

108-
__slots__ = ("_start", "_end")
109-
110106
_start: datetime
111107
_end: datetime
112108

@@ -125,15 +121,13 @@ def end(self):
125121
return self._end
126122

127123

128-
@dataclass(init=False)
124+
@dataclass(init=False, slots=True)
129125
class ReduceWindow:
130126
"""
131127
Defines the window for a reduce operation which includes the
132128
interval window along with the slot.
133129
"""
134130

135-
__slots__ = ("_window", "_slot")
136-
137131
_window: IntervalWindow
138132
_slot: str
139133

@@ -162,12 +156,10 @@ def window(self):
162156
return self._window
163157

164158

165-
@dataclass(init=False)
159+
@dataclass(init=False, slots=True)
166160
class Metadata:
167161
"""Defines the metadata for the event."""
168162

169-
__slots__ = ("_interval_window",)
170-
171163
_interval_window: IntervalWindow
172164

173165
def __init__(self, interval_window: IntervalWindow):
@@ -254,7 +246,7 @@ def payload(self) -> Datum:
254246
return self._payload
255247

256248

257-
@dataclass(init=False)
249+
@dataclass(init=False, slots=True)
258250
class Message:
259251
"""
260252
Basic datatype for data passing to the next vertex/vertices.
@@ -265,8 +257,6 @@ class Message:
265257
tags: []string tags for conditional forwarding (optional)
266258
"""
267259

268-
__slots__ = ("_value", "_keys", "_tags")
269-
270260
_value: bytes
271261
_keys: list[str]
272262
_tags: list[str]

0 commit comments

Comments
 (0)