Skip to content

Commit 9875e22

Browse files
Apply suggestions from code review
Co-authored-by: Heitor Lessa <[email protected]>
1 parent c5394f5 commit 9875e22

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

aws_lambda_powertools/utilities/data_classes/common.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import base64
22
import json
3-
from typing import Any, Dict, Iterator, Mapping, Optional
3+
from collections.abc import Mapping
4+
from typing import Any, Dict, Iterator, Optional
45

56

67
class DictWrapper(Mapping):

aws_lambda_powertools/utilities/data_classes/dynamo_db_stream_event.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,10 @@ def approximate_creation_date_time(self) -> Optional[int]:
182182
item = self.get("ApproximateCreationDateTime")
183183
return None if item is None else int(item)
184184

185-
# This override breaks the Mapping protocol of DictWrapper, it's left here for backwards compatibility with
186-
# a 'type: ignore' comment. This is currently the only subclass of DictWrapper that breaks this protocol.
185+
# NOTE: This override breaks the Mapping protocol of DictWrapper, it's left here for backwards compatibility with
186+
# a 'type: ignore' comment. See #1516 for discussion
187187
@property
188-
def keys(self) -> Optional[Dict[str, AttributeValue]]: # type: ignore
188+
def keys(self) -> Optional[Dict[str, AttributeValue]]: # type: ignore[override]
189189
"""The primary key attribute(s) for the DynamoDB item that was modified."""
190190
return _attribute_value_dict(self._data, "Keys")
191191

tests/functional/test_data_classes.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,17 @@ def message(self) -> str:
102102
assert DataClassSample(data1).raw_event is data1
103103

104104

105-
def test_dict_wrapper_imlements_mapping():
105+
def test_dict_wrapper_implements_mapping():
106106
class DataClassSample(DictWrapper):
107107
pass
108108

109109
data = {"message": "foo1"}
110-
dcs = DataClassSample(data)
111-
assert len(dcs) == len(data)
112-
assert list(dcs) == list(data)
113-
assert dcs.keys() == data.keys()
114-
assert list(dcs.values()) == list(data.values())
115-
assert dcs.items() == data.items()
110+
event_source = DataClassSample(data)
111+
assert len(event_source) == len(data)
112+
assert list(event_source) == list(data)
113+
assert event_source.keys() == data.keys()
114+
assert list(event_source.values()) == list(data.values())
115+
assert event_source.items() == data.items()
116116

117117

118118
def test_cloud_watch_dashboard_event():
@@ -633,19 +633,19 @@ def test_dynamo_attribute_value_type_error():
633633

634634
def test_stream_record_keys_with_valid_keys():
635635
attribute_value = {"Foo": "Bar"}
636-
sr = StreamRecord({"Keys": {"Key1": attribute_value}})
637-
assert sr.keys == {"Key1": AttributeValue(attribute_value)}
636+
record = StreamRecord({"Keys": {"Key1": attribute_value}})
637+
assert record.keys == {"Key1": AttributeValue(attribute_value)}
638638

639639

640640
def test_stream_record_keys_with_no_keys():
641-
sr = StreamRecord({})
642-
assert sr.keys is None
641+
record = StreamRecord({})
642+
assert record.keys is None
643643

644644

645645
def test_stream_record_keys_overrides_dict_wrapper_keys():
646646
data = {"Keys": {"key1": {"attr1": "value1"}}}
647-
sr = StreamRecord(data)
648-
assert sr.keys != data.keys()
647+
record = StreamRecord(data)
648+
assert record.keys != data.keys()
649649

650650

651651
def test_event_bridge_event():

0 commit comments

Comments
 (0)