Skip to content

Commit c144dbb

Browse files
committed
chore: accept Mapping as well as SupportsDuplicateItems
Although our types.SupportsDuplicateItems type is wider than Dict and Mapping, it's not a familar type to users, so explicitly accepting Mapping in the from_http() functions should make it more clear to users that a dict-like object is required for the headers argument. Signed-off-by: Hal Blackburn <hwtb2@cam.ac.uk>
1 parent 130cdfa commit c144dbb

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

cloudevents/conversion.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ def from_json(
9191

9292
def from_http(
9393
event_type: typing.Type[AnyCloudEvent],
94-
headers: types.SupportsDuplicateItems[str, str],
94+
headers: typing.Union[
95+
typing.Mapping[str, str], types.SupportsDuplicateItems[str, str]
96+
],
9597
data: typing.Optional[typing.Union[str, bytes]],
9698
data_unmarshaller: typing.Optional[types.UnmarshallerType] = None,
9799
) -> AnyCloudEvent:

cloudevents/http/conversion.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ def from_json(
3737

3838

3939
def from_http(
40-
headers: types.SupportsDuplicateItems[str, str],
40+
headers: typing.Union[
41+
typing.Mapping[str, str], types.SupportsDuplicateItems[str, str]
42+
],
4143
data: typing.Optional[typing.Union[str, bytes]],
4244
data_unmarshaller: typing.Optional[types.UnmarshallerType] = None,
4345
) -> CloudEvent:

cloudevents/pydantic/v1/conversion.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121

2222

2323
def from_http(
24-
headers: types.SupportsDuplicateItems[str, str],
24+
headers: typing.Union[
25+
typing.Mapping[str, str], types.SupportsDuplicateItems[str, str]
26+
],
2527
data: typing.Optional[typing.AnyStr],
2628
data_unmarshaller: typing.Optional[types.UnmarshallerType] = None,
2729
) -> CloudEvent:

cloudevents/pydantic/v2/conversion.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222

2323

2424
def from_http(
25-
headers: types.SupportsDuplicateItems[str, str],
25+
headers: typing.Union[
26+
typing.Mapping[str, str], types.SupportsDuplicateItems[str, str]
27+
],
2628
data: typing.Optional[typing.AnyStr],
2729
data_unmarshaller: typing.Optional[types.UnmarshallerType] = None,
2830
) -> CloudEvent:

0 commit comments

Comments
 (0)