Skip to content

Commit d31caba

Browse files
rnpridgeonRyan P
authored andcommitted
Minor cleanup to AvroSerializer/AvroDeserializer
1 parent f97a9c2 commit d31caba

File tree

3 files changed

+15
-22
lines changed

3 files changed

+15
-22
lines changed

confluent_kafka/schema_registry/avro.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ class AvroSerializer(Serializer):
7575
7676
AvroSerializer configuration properties:
7777
+-----------------------+----------+--------------------------------------------------+
78-
| Property Name | type | Description |
78+
| Property Name | Type | Description |
7979
+=======================+==========+==================================================+
8080
| | | Registers schemas automatically if not |
8181
| auto.register.schemas | bool | previously associated with a particular subject. |
8282
| | | Defaults to True. |
8383
+-----------------------|----------+--------------------------------------------------+
84-
| | | Callable(str, SerialalizationContext) -> str |
84+
| | | Callable(SerializationContext, str) -> str |
8585
| | | |
86-
| subject.name.strategy | callable | Instructs the AvroSerializer on how to Construct |
86+
| subject.name.strategy | callable | Instructs the AvroSerializer on how to construct |
8787
| | | Schema Registry subject names. |
8888
| | | Defaults to topic_subject_name_strategy. |
8989
+-----------------------+----------+--------------------------------------------------+
@@ -138,7 +138,7 @@ class AvroSerializer(Serializer):
138138
""" # noqa: E501
139139
__slots__ = ['_hash', '_auto_register', '_known_subjects', '_parsed_schema',
140140
'_registry', '_schema', '_schema_id', '_schema_name',
141-
'_subject_name_func', 'to_dict']
141+
'_subject_name_func', '_to_dict']
142142

143143
# default configuration
144144
_default_conf = {'auto.register.schemas': True,
@@ -153,9 +153,9 @@ def __init__(self, schema_registry_client, schema_str,
153153

154154
if to_dict is not None and not callable(to_dict):
155155
raise ValueError("to_dict must be callable with the signature"
156-
" to_dict(Serialization Context, object)->dict")
156+
" to_dict(SerializationContext, object)->dict")
157157

158-
self.to_dict = to_dict
158+
self._to_dict = to_dict
159159

160160
# handle configuration
161161
conf_copy = self._default_conf.copy()
@@ -197,7 +197,7 @@ def __call__(self, ctx, obj):
197197
ctx (SerializationContext): Metadata pertaining to the serialization
198198
operation.
199199
200-
obj (object): object instance to serializes.
200+
obj (object): object instance to serialize.
201201
202202
Note:
203203
None objects are represented as Kafka Null.
@@ -228,8 +228,8 @@ def __call__(self, ctx, obj):
228228
self._schema_id = registered_schema.schema_id
229229
self._known_subjects.add(subject)
230230

231-
if self.to_dict is not None:
232-
value = self.to_dict(ctx, obj)
231+
if self._to_dict is not None:
232+
value = self._to_dict(ctx, obj)
233233
else:
234234
value = obj
235235

@@ -271,7 +271,7 @@ class AvroDeserializer(Deserializer):
271271
https://avro.apache.org/docs/1.8.2/spec.html#Schema+Resolution
272272
273273
"""
274-
__slots__ = ['_reader_schema', '_registry', 'from_dict', '_writer_schemas']
274+
__slots__ = ['_reader_schema', '_registry', '_from_dict', '_writer_schemas']
275275

276276
def __init__(self, schema_registry_client, schema_str, from_dict=None):
277277
self._registry = schema_registry_client
@@ -282,12 +282,11 @@ def __init__(self, schema_registry_client, schema_str, from_dict=None):
282282
if from_dict is not None and not callable(from_dict):
283283
raise ValueError("from_dict must be callable with the signature"
284284
" from_dict(SerializationContext, dict) -> object")
285-
self.from_dict = from_dict
285+
self._from_dict = from_dict
286286

287287
def __call__(self, ctx, value):
288288
"""
289-
Decodes a Confluent Schema Registry formatted Avro bytes
290-
to an object.
289+
Decodes a Confluent Schema Registry formatted Avro bytes to an object.
291290
292291
Arguments:
293292
ctx (SerializationContext): Metadata pertaining to the serialization
@@ -331,7 +330,7 @@ def __call__(self, ctx, value):
331330
writer_schema,
332331
self._reader_schema)
333332

334-
if self.from_dict is not None:
335-
return self.from_dict(ctx, obj_dict)
333+
if self._from_dict is not None:
334+
return self._from_dict(ctx, obj_dict)
336335

337336
return obj_dict

examples/avro_consumer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def main(args):
115115

116116

117117
if __name__ == '__main__':
118-
parser = argparse.ArgumentParser(description="Producer Example client with "
118+
parser = argparse.ArgumentParser(description="Consumer Example client with "
119119
"serialization capabilities")
120120
parser.add_argument('-b', dest="bootstrap_servers", required=True,
121121
help="Bootstrap broker(s) (host[:port])")

tests/integration/schema_registry/test_avro_serializers.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ def test_avro_record_serialization(kafka_cluster, load_avsc, avsc, data, record_
6767
avsc (str) avsc: Avro schema file
6868
data (object): data to be serialized
6969
70-
Raises:
71-
AssertionError on test failure
72-
7370
"""
7471
topic = kafka_cluster.create_topic("serialization-avro")
7572
sr = kafka_cluster.schema_registry()
@@ -114,9 +111,6 @@ def test_delivery_report_serialization(kafka_cluster, load_avsc, avsc, data, rec
114111
avsc (str) avsc: Avro schema file
115112
data (object): data to be serialized
116113
117-
Raises:
118-
AssertionError on test failure
119-
120114
"""
121115
topic = kafka_cluster.create_topic("serialization-avro-dr")
122116
sr = kafka_cluster.schema_registry()

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