1818 import mypy_boto3_dynamodb
1919 DynamoDBTable = mypy_boto3_dynamodb .service_resource .Table
2020except ImportError :
21- DynamoDBTable = Any # type: ignore
21+ DynamoDBTable = Any # type: ignore
2222
2323DynamoDBKeyPrimitiveTypes = (str , bytes , bytearray , int , Decimal )
2424"""DynamoDB primary key primitive choices."""
4949"""DynamoDB value type choices."""
5050
5151DynamoDBValue = Union [
52- bytes , bytearray , str , int , Decimal ,bool ,
52+ bytes , bytearray , str , int , Decimal , bool ,
5353 Set [int ], Set [Decimal ], Set [str ], Set [bytes ], Set [bytearray ],
5454 Sequence [Any ], Mapping [str , Any ], None ,
5555]
6060
6161logger = logging .getLogger (__name__ )
6262
63+
6364def _boto3_session_from_config (config : Dict [str , Any ]) -> Optional [boto3 .Session ]:
6465 if "aws_access_key_id" in config and "aws_secret_access_key" in config :
6566 return boto3 .Session (
@@ -71,6 +72,7 @@ def _boto3_session_from_config(config: Dict[str, Any]) -> Optional[boto3.Session
7172 else :
7273 return None
7374
75+
7476def get_key_names (table : DynamoDBTable ) -> DynamoDBKeyName :
7577 """Gets the key names of the DynamoDB table.
7678
@@ -121,6 +123,7 @@ def create_tuple_keys(key: DynamoDBKeySimplified) -> DynamoDBKeyAny:
121123 else :
122124 return cast (DynamoDBKeySimple , (key ,))
123125
126+
124127def _log_keys_from_params (key_params : Dict [str , DynamoDBKeyPrimitive ]) -> str :
125128 log_keys = list (key_params .values ())
126129 res = log_keys [0 ] if len (log_keys ) == 1 else log_keys
@@ -194,7 +197,8 @@ class DynamoDBItemAccessor(dict):
194197 initial_data (Dict): The initial item data.
195198 """
196199
197- def __init__ (self ,
200+ def __init__ (
201+ self ,
198202 parent : "DynamoDBMapping" ,
199203 item_keys : DynamoDBKeySimplified ,
200204 initial_data : DynamoDBItemType ,
@@ -268,7 +272,8 @@ class DynamoDBMapping(MutableMapping):
268272 the values are one of the `permitted DynamoDB value types`_. The ``DynamoDBItemType`` type
269273 reflects the possible item types.
270274
271- .. _permitted DynamoDB value types: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/customizations/dynamodb.html
275+ .. _permitted DynamoDB value types: \
276+ https://boto3.amazonaws.com/v1/documentation/api/latest/reference/customizations/dynamodb.html
272277
273278 Args:
274279 table_name: The name of the DynamoDB table.
@@ -278,7 +283,7 @@ class DynamoDBMapping(MutableMapping):
278283 """
279284
280285 def __init__ (
281- self , table_name : str , boto3_session : Optional [boto3 .session .Session ]= None , ** kwargs
286+ self , table_name : str , boto3_session : Optional [boto3 .session .Session ] = None , ** kwargs
282287 ) -> None :
283288 session = (
284289 boto3_session or
@@ -294,7 +299,7 @@ def _create_key_param(self, keys: DynamoDBKeySimplified) -> Dict[str, DynamoDBKe
294299 tuple_keys = create_tuple_keys (keys )
295300 if len (tuple_keys ) != len (self .key_names ):
296301 raise ValueError (f"You must provide a value for each of { self .key_names } keys." )
297- param = { name : value for name , value in zip (self .key_names , tuple_keys ) }
302+ param = {name : value for name , value in zip (self .key_names , tuple_keys )}
298303 return param
299304
300305 def scan (self , ** kwargs ) -> Iterator [DynamoDBItemType ]:
@@ -356,7 +361,7 @@ def get_item(self, keys: DynamoDBKeySimplified, **kwargs) -> DynamoDBItemAccesso
356361 key_params = self ._create_key_param (keys )
357362 logger .debug ("Performing a get_item operation on %s table" , self .table .name )
358363 response = self .table .get_item (Key = key_params , ** kwargs )
359- if not "Item" in response :
364+ if "Item" not in response :
360365 raise KeyError (_log_keys_from_params (key_params ))
361366 data = response ["Item" ]
362367 return DynamoDBItemAccessor (parent = self , item_keys = keys , initial_data = data )
@@ -404,12 +409,13 @@ def del_item(self, keys: DynamoDBKeySimplified, check_existing=True, **kwargs) -
404409 :meth:`~DynamoDBTable.delete_item` operation.
405410 """
406411 key_params = self ._create_key_param (keys )
407- if check_existing and not keys in self .keys ():
412+ if check_existing and keys not in self .keys ():
408413 raise KeyError (_log_keys_from_params (key_params ))
409414 logger .debug ("Performing a delete_item operation on %s table" , self .table .name )
410415 self .table .delete_item (Key = key_params , ** kwargs )
411416
412- def modify_item (self ,
417+ def modify_item (
418+ self ,
413419 keys : DynamoDBKeySimplified ,
414420 modifications : DynamoDBItemType ,
415421 ** kwargs
0 commit comments