Skip to content

Commit f0de54c

Browse files
committed
Make stream event dataclasses not keyword-only
Since all attributes have different types, it is not too error prone to allow using positional arguments, and this makes the dataclass automatically provides a `__match__` dunder method that allows for less verbose match syntax. We also update examples to use the match syntax to extra the event information more easily. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 03a1932 commit f0de54c

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

RELEASE_NOTES.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
match msg:
2020
case StreamStarted():
2121
print("Stream started")
22-
case StreamStopped() as event:
23-
print(f"Stream stopped, reason {event.exception}, retry in {event.retry_time}")
22+
case StreamStopped(delay, error):
23+
print(f"Stream stopped, reason {error}, retry in {delay}")
2424
case int() as output:
2525
print(f"Received message: {output}")
2626
```

src/frequenz/client/base/streaming.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
"""The output type of the stream."""
2727

2828

29-
@dataclass(frozen=True, kw_only=True)
29+
@dataclass(frozen=True)
3030
class StreamStarted:
3131
"""Event indicating that the stream has started."""
3232

3333

34-
@dataclass(frozen=True, kw_only=True)
34+
@dataclass(frozen=True)
3535
class StreamStopped:
3636
"""Event indicating that the stream has stopped."""
3737

@@ -81,8 +81,8 @@ def async_range() -> AsyncIterable[int]:
8181
match msg:
8282
case StreamStarted():
8383
print("Stream started")
84-
case StreamStopped() as event:
85-
print(f"Stream stopped, reason {event.exception}, retry in {event.retry_time}")
84+
case StreamStopped(delay, error):
85+
print(f"Stream stopped, reason {error}, retry in {delay}")
8686
case int() as output:
8787
print(f"Received message: {output}")
8888
```

0 commit comments

Comments
 (0)