Skip to content

Fix initialization of stream decoder #288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions replicate/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,16 @@ class Decoder:
A decoder for server-sent events.
"""

event: Optional["ServerSentEvent.EventType"] = None
data: List[str] = []
last_event_id: Optional[str] = None
retry: Optional[int] = None
event: Optional["ServerSentEvent.EventType"]
data: List[str]
last_event_id: Optional[str]
retry: Optional[int]

def __init__(self) -> None:
self.event = None
self.data = []
self.last_event_id = None
self.retry = None

def decode(self, line: str) -> Optional[ServerSentEvent]:
"""
Expand Down Expand Up @@ -134,6 +140,7 @@ def decode(self, line: str) -> Optional[ServerSentEvent]:

def __iter__(self) -> Iterator[ServerSentEvent]:
decoder = EventSource.Decoder()

for line in self.response.iter_lines():
line = line.rstrip("\n")
sse = decoder.decode(line)
Expand Down
Loading