Skip to content

Commit efca352

Browse files
fix kafka unmarshaller args typing and defaults (#240)
* fix kafka unmarshaller args typing and defaults Signed-off-by: Christoph Hösler <christoph.hoesler@inovex.de> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Signed-off-by: Christoph Hösler <christoph.hoesler@inovex.de> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent c6c7e8c commit efca352

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

cloudevents/kafka/conversion.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@
2121
from cloudevents.kafka.exceptions import KeyMapperError
2222
from cloudevents.sdk import types
2323

24-
DEFAULT_MARSHALLER: types.MarshallerType = json.dumps
25-
DEFAULT_UNMARSHALLER: types.MarshallerType = json.loads
26-
DEFAULT_EMBEDDED_DATA_MARSHALLER: types.MarshallerType = lambda x: x
24+
JSON_MARSHALLER: types.MarshallerType = json.dumps
25+
JSON_UNMARSHALLER: types.UnmarshallerType = json.loads
26+
IDENTITY_MARSHALLER = IDENTITY_UNMARSHALLER = lambda x: x
27+
28+
DEFAULT_MARSHALLER: types.MarshallerType = JSON_MARSHALLER
29+
DEFAULT_UNMARSHALLER: types.UnmarshallerType = JSON_UNMARSHALLER
30+
DEFAULT_EMBEDDED_DATA_MARSHALLER: types.MarshallerType = IDENTITY_MARSHALLER
31+
DEFAULT_EMBEDDED_DATA_UNMARSHALLER: types.UnmarshallerType = IDENTITY_UNMARSHALLER
2732

2833

2934
class KafkaMessage(typing.NamedTuple):
@@ -109,7 +114,7 @@ def to_binary(
109114
def from_binary(
110115
message: KafkaMessage,
111116
event_type: typing.Optional[typing.Type[AnyCloudEvent]] = None,
112-
data_unmarshaller: typing.Optional[types.MarshallerType] = None,
117+
data_unmarshaller: typing.Optional[types.UnmarshallerType] = None,
113118
) -> AnyCloudEvent:
114119
"""
115120
Returns a CloudEvent from a KafkaMessage in binary format.
@@ -208,7 +213,7 @@ def to_structured(
208213
def from_structured(
209214
message: KafkaMessage,
210215
event_type: typing.Optional[typing.Type[AnyCloudEvent]] = None,
211-
data_unmarshaller: typing.Optional[types.MarshallerType] = None,
216+
data_unmarshaller: typing.Optional[types.UnmarshallerType] = None,
212217
envelope_unmarshaller: typing.Optional[types.UnmarshallerType] = None,
213218
) -> AnyCloudEvent:
214219
"""
@@ -222,7 +227,7 @@ def from_structured(
222227
:returns: CloudEvent
223228
"""
224229

225-
data_unmarshaller = data_unmarshaller or DEFAULT_EMBEDDED_DATA_MARSHALLER
230+
data_unmarshaller = data_unmarshaller or DEFAULT_EMBEDDED_DATA_UNMARSHALLER
226231
envelope_unmarshaller = envelope_unmarshaller or DEFAULT_UNMARSHALLER
227232
try:
228233
structure = envelope_unmarshaller(message.value)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy