Skip to content

Commit 51d64fd

Browse files
committed
convert events.InformationalResponseReceived into a dataclass
1 parent 0216433 commit 51d64fd

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

src/h2/events.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ class _PushedRequestSent(_HeadersSent):
235235
"""
236236

237237

238-
238+
@dataclass(**kw_only)
239239
class InformationalResponseReceived(Event):
240240
"""
241241
The InformationalResponseReceived event is fired when an informational
@@ -259,20 +259,20 @@ class InformationalResponseReceived(Event):
259259
Added ``priority_updated`` property.
260260
"""
261261

262-
def __init__(self) -> None:
263-
#: The Stream ID for the stream this informational response was made
264-
#: on.
265-
self.stream_id: int | None = None
262+
stream_id: int
263+
"""The Stream ID for the stream this informational response was made on."""
266264

267-
#: The headers for this informational response.
268-
self.headers: list[Header] | None = None
265+
headers: list[Header] = _LAZY_INIT
266+
"""The headers for this informational response."""
269267

270-
#: If this response also had associated priority information, the
271-
#: associated :class:`PriorityUpdated <h2.events.PriorityUpdated>`
272-
#: event will be available here.
273-
#:
274-
#: .. versionadded:: 2.4.0
275-
self.priority_updated: PriorityUpdated | None = None
268+
priority_updated: PriorityUpdated | None = None
269+
"""
270+
If this response also had associated priority information, the
271+
associated :class:`PriorityUpdated <h2.events.PriorityUpdated>`
272+
event will be available here.
273+
274+
.. versionadded:: 2.4.0
275+
"""
276276

277277
def __repr__(self) -> str:
278278
return f"<InformationalResponseReceived stream_id:{self.stream_id}, headers:{self.headers}>"

src/h2/stream.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -424,9 +424,7 @@ def recv_informational_response(self, previous_state: StreamState) -> list[Event
424424
msg = "Informational response after final response"
425425
raise ProtocolError(msg)
426426

427-
event = InformationalResponseReceived()
428-
event.stream_id = self.stream_id
429-
return [event]
427+
return [InformationalResponseReceived(stream_id=self.stream_id)]
430428

431429
def recv_alt_svc(self, previous_state: StreamState) -> list[Event]:
432430
"""

tests/test_events.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,10 @@ def test_informationalresponsereceived_repr(self) -> None:
159159
"""
160160
InformationalResponseReceived has a useful debug representation.
161161
"""
162-
e = h2.events.InformationalResponseReceived()
163-
e.stream_id = 62
164-
e.headers = self.example_informational_headers
162+
e = h2.events.InformationalResponseReceived(
163+
stream_id=62,
164+
headers=self.example_informational_headers,
165+
)
165166

166167
assert repr(e) == (
167168
"<InformationalResponseReceived stream_id:62, headers:["

0 commit comments

Comments
 (0)