Skip to content

Commit 13361d9

Browse files
committed
add proper constructor for events.WindowUpdated
1 parent 1feb271 commit 13361d9

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

src/h2/connection.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1806,9 +1806,7 @@ def _receive_window_update_frame(self, frame: WindowUpdateFrame) -> tuple[list[F
18061806
)
18071807

18081808
# FIXME: Should we split this into one event per active stream?
1809-
window_updated_event = WindowUpdated()
1810-
window_updated_event.stream_id = 0
1811-
window_updated_event.delta = frame.window_increment
1809+
window_updated_event = WindowUpdated(stream_id=0, delta=frame.window_increment)
18121810
stream_events = [window_updated_event]
18131811
frames = []
18141812

src/h2/events.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -301,13 +301,20 @@ class WindowUpdated(Event):
301301
the connection), and the delta in the window size.
302302
"""
303303

304-
def __init__(self) -> None:
305-
#: The Stream ID of the stream whose flow control window was changed.
306-
#: May be ``0`` if the connection window was changed.
307-
self.stream_id: int | None = None
304+
stream_id: int
305+
"""
306+
The Stream ID of the stream whose flow control window was changed.
307+
May be ``0`` if the connection window was changed.
308+
"""
309+
310+
delta: int | None
311+
"""
312+
The window delta.
313+
"""
308314

309-
#: The window delta.
310-
self.delta: int | None = None
315+
def __init__(self, *, stream_id: int, delta: int | None = None) -> None:
316+
self.stream_id = stream_id
317+
self.delta = delta
311318

312319
def __repr__(self) -> str:
313320
return f"<WindowUpdated stream_id:{self.stream_id}, delta:{self.delta}>"

src/h2/stream.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,7 @@ def window_updated(self, previous_state: StreamState) -> list[Event]:
232232
"""
233233
Fires when a window update frame is received.
234234
"""
235-
event = WindowUpdated()
236-
event.stream_id = self.stream_id
237-
return [event]
235+
return [WindowUpdated(stream_id=0)]
238236

239237
def stream_half_closed(self, previous_state: StreamState) -> list[Event]:
240238
"""

tests/test_events.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,7 @@ def test_windowupdated_repr(self) -> None:
186186
"""
187187
WindowUpdated has a useful debug representation.
188188
"""
189-
e = h2.events.WindowUpdated()
190-
e.stream_id = 0
191-
e.delta = 2**16
189+
e = h2.events.WindowUpdated(stream_id=0, delta=2**16)
192190

193191
assert repr(e) == "<WindowUpdated stream_id:0, delta:65536>"
194192

0 commit comments

Comments
 (0)