Skip to content

Commit

Permalink
improve types and add clarity around what happens inside presume
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Gaultney committed Sep 29, 2021
1 parent 8a440b4 commit a8ec035
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
8 changes: 4 additions & 4 deletions dev-utils/watch_ddb_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
DYNAMODB_STREAMS = make_dynamodb_stream_images_multicast()


def make_accept_stream_images(item_slicer: Callable[[ItemImages], str]):
def accept_stream_item(images: ItemImages):
def make_accept_stream_images(item_slicer: Callable[[ItemImages], dict]):
def accept_stream_item(images: ItemImages) -> None:
old, new = images
if not old:
print(f"New item: {item_slicer(images)}") # type: ignore
Expand All @@ -34,7 +34,7 @@ def make_key_slicer(table):
except ValueError:
range_key = ""

def extract_primary_key(images: ItemImages):
def extract_primary_key(images: ItemImages) -> dict:
old, new = images
item = new or old
assert item is not None
Expand All @@ -48,7 +48,7 @@ def extract_primary_key(images: ItemImages):


def make_item_slicer(key_slicer, attribute_names):
def item_slicer(images: ItemImages):
def item_slicer(images: ItemImages) -> dict:
old, new = images
if not new:
new = dict()
Expand Down
9 changes: 3 additions & 6 deletions xoto3/dynamodb/write_versioned/specify.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,13 @@ def presume(
)
hkey = hashable_key(item_key)
if hkey not in table_data.items:
item_value = dynamodb_prewrite(item_value, prewrite_transform) if item_value else None
# this prewrite makes sure the value looks like it could have come out of DynamoDB.
return VersionedTransaction(
tables={
**transaction.tables,
table_name: _TableData(
items={
**table_data.items,
hkey: dynamodb_prewrite(item_value, prewrite_transform)
if item_value
else item_value,
},
items={**table_data.items, hkey: item_value},
effects=table_data.effects,
key_attributes=table_data.key_attributes,
),
Expand Down

0 comments on commit a8ec035

Please sign in to comment.