Skip to content

Commit 15356f9

Browse files
committed
chore: improve inline comments and move code
1 parent 8423025 commit 15356f9

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

openedx_events/event_bus/avro/deserializer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def _deserialized_avro_record_dict_to_object(data: dict, data_type, deserializer
5353
if arg_data_type[0] in SIMPLE_PYTHON_TYPE_TO_AVRO_MAPPING:
5454
return data
5555

56-
# Complex list items that need recursive deserialization
56+
# Complex nested types like List[List[...]], List[Dict[...]], etc.
5757
item_type = arg_data_type[0]
5858
return [_deserialized_avro_record_dict_to_object(sub_data, item_type, deserializers) for sub_data in data]
5959
elif data_type_origin is dict:
@@ -73,10 +73,10 @@ def _deserialized_avro_record_dict_to_object(data: dict, data_type, deserializer
7373
if key_type is not str:
7474
raise TypeError("Avro maps only support string keys. The key type must be 'str'.")
7575

76-
# For complex nested types like Dict[str, Dict[...]], Dict[str, List[...]], etc.
76+
# Complex nested types like Dict[str, Dict[...]], Dict[str, List[...]], etc.
7777
return {
78-
k: _deserialized_avro_record_dict_to_object(v, value_type, deserializers)
79-
for k, v in data.items()
78+
key: _deserialized_avro_record_dict_to_object(value, value_type, deserializers)
79+
for key, value in data.items()
8080
}
8181
elif hasattr(data_type, "__attrs_attrs__"):
8282
transformed = {}

openedx_events/event_bus/avro/tests/test_avro.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ def process_type(type_spec: Any) -> Any:
127127
defined types.
128128
129129
Args:
130-
type_spec (Any): A type specification which might be a string,
131-
dict, or list
130+
type_spec (Any): A type specification which might be a str, dict, or list
132131
133132
Returns:
134133
Any: An appropriate test value for the specified type
@@ -171,7 +170,7 @@ def process_type(type_spec: Any) -> Any:
171170
# Array type (list)
172171
elif type_name == "array":
173172
items = type_spec.get("items")
174-
# We crate a list with a single element
173+
# We create a list with a single element
175174
return [process_type(items)]
176175

177176
# Map type (dictionary/object)
@@ -267,6 +266,10 @@ def generate_test_event_data_for_data_type(data_type: Any) -> dict: # pragma: n
267266

268267
item_type = args[0]
269268

269+
# Handle List of simple types, e.g. List[str]
270+
if item_type in defaults_per_type:
271+
return [defaults_per_type[item_type]]
272+
270273
# Handle List of Dicts, e.g. List[Dict[str, str]]
271274
if get_origin(item_type) is dict:
272275
dict_key_type, dict_value_type = get_args(item_type)
@@ -285,10 +288,6 @@ def generate_test_event_data_for_data_type(data_type: Any) -> dict: # pragma: n
285288

286289
return [sample_dict]
287290

288-
# Handle List of simple types, e.g. List[str]
289-
if item_type in defaults_per_type:
290-
return [defaults_per_type[item_type]]
291-
292291
# Handle List of attrs classes, e.g. List[EventData]
293292
item_data = generate_test_event_data_for_data_type(item_type)
294293
return [item_data]

0 commit comments

Comments
 (0)