Skip to content

Commit a133455

Browse files
Copilotbambriz
andcommitted
Replace remaining hardcoded kwargs and options strings with constants
Co-authored-by: bambriz <[email protected]>
1 parent b281cd0 commit a133455

File tree

6 files changed

+44
-44
lines changed

6 files changed

+44
-44
lines changed

sdk/cosmos/azure-cosmos/azure/cosmos/_cosmos_client_connection.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,7 @@ def fetch_fn(options: Mapping[str, Any]) -> Tuple[List[Dict[str, Any]], CaseInse
12351235
if collection_link in self.__container_properties_cache:
12361236
# TODO: This will make deep copy. Check if this has any performance impact
12371237
new_options = dict(options)
1238-
new_options["containerRID"] = self.__container_properties_cache[collection_link]["_rid"]
1238+
new_options[Constants.InternalOptions.CONTAINER_RID] = self.__container_properties_cache[collection_link]["_rid"]
12391239
options = new_options
12401240
return self.__QueryFeed(
12411241
path,
@@ -3186,8 +3186,8 @@ def __GetBodiesFromQueryResult(result: Dict[str, Any]) -> List[Dict[str, Any]]:
31863186
change_feed_state: Optional[ChangeFeedState] = options.get("changeFeedState")
31873187
if change_feed_state is not None:
31883188
feed_options = {}
3189-
if 'excludedLocations' in options:
3190-
feed_options['excludedLocations'] = options['excludedLocations']
3189+
if Constants.InternalOptions.EXCLUDED_LOCATIONS in options:
3190+
feed_options[Constants.InternalOptions.EXCLUDED_LOCATIONS] = options[Constants.InternalOptions.EXCLUDED_LOCATIONS]
31913191
change_feed_state.populate_request_headers(self._routing_map_provider, headers, feed_options)
31923192
request_params.headers = headers
31933193

@@ -3394,9 +3394,9 @@ def _AddPartitionKey(
33943394
# If the collection doesn't have a partition key definition, skip it as it's a legacy collection
33953395
if partitionKeyDefinition:
33963396
# If the user has passed in the partitionKey in options use that else extract it from the document
3397-
if "partitionKey" not in options:
3397+
if Constants.InternalOptions.PARTITION_KEY not in options:
33983398
partitionKeyValue = self._ExtractPartitionKey(partitionKeyDefinition, document)
3399-
new_options["partitionKey"] = partitionKeyValue
3399+
new_options[Constants.InternalOptions.PARTITION_KEY] = partitionKeyValue
34003400
return new_options
34013401

34023402
# Extracts the partition key from the document using the partitionKey definition

sdk/cosmos/azure-cosmos/azure/cosmos/aio/_container.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ def read_all_items(
439439
feed_options[
440440
Constants.InternalOptions.CONTAINER_RID
441441
] = self.__get_client_container_caches()[self.container_link]["_rid"]
442-
kwargs["containerProperties"] = self._get_properties_with_options
442+
kwargs[Constants.Kwargs.CONTAINER_PROPERTIES] = self._get_properties_with_options
443443

444444
items = self.client_connection.ReadItems(
445445
collection_link=self.container_link, feed_options=feed_options, response_hook=response_hook, **kwargs
@@ -484,23 +484,23 @@ async def read_items(
484484

485485

486486
if session_token is not None:
487-
kwargs['session_token'] = session_token
487+
kwargs[Constants.Kwargs.SESSION_TOKEN] = session_token
488488
if initial_headers is not None:
489-
kwargs['initial_headers'] = initial_headers
489+
kwargs[Constants.Kwargs.INITIAL_HEADERS] = initial_headers
490490
if consistency_level is not None:
491-
kwargs['consistencyLevel'] = consistency_level
491+
kwargs[Constants.Kwargs.CONSISTENCY_LEVEL] = consistency_level
492492
if excluded_locations is not None:
493-
kwargs['excludedLocations'] = excluded_locations
493+
kwargs[Constants.Kwargs.EXCLUDED_LOCATIONS] = excluded_locations
494494
if priority is not None:
495-
kwargs['priority'] = priority
495+
kwargs[Constants.Kwargs.PRIORITY] = priority
496496
if throughput_bucket is not None:
497-
kwargs["throughput_bucket"] = throughput_bucket
497+
kwargs[Constants.Kwargs.THROUGHPUT_BUCKET] = throughput_bucket
498498

499499
kwargs['max_concurrency'] = max_concurrency
500-
kwargs["containerProperties"] = self._get_properties_with_options
500+
kwargs[Constants.Kwargs.CONTAINER_PROPERTIES] = self._get_properties_with_options
501501
query_options = _build_options(kwargs)
502502
await self._get_properties_with_options(query_options)
503-
query_options["enableCrossPartitionQuery"] = True
503+
query_options[Constants.InternalOptions.ENABLE_CROSS_PARTITION_QUERY] = True
504504

505505
return await self.client_connection.read_items(
506506
collection_link=self.container_link,
@@ -774,7 +774,7 @@ def query_items(
774774
query = kwargs.pop("query", None)
775775

776776
# Set method to get/cache container properties
777-
kwargs["containerProperties"] = self._get_properties_with_options
777+
kwargs[Constants.Kwargs.CONTAINER_PROPERTIES] = self._get_properties_with_options
778778

779779
utils.verify_exclusive_arguments(["feed_range", "partition_key"], **kwargs)
780780
partition_key = None

sdk/cosmos/azure-cosmos/azure/cosmos/aio/_cosmos_client_connection_async.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2343,7 +2343,7 @@ def QueryItems(
23432343
async def fetch_fn(options: Mapping[str, Any]) -> Tuple[List[Dict[str, Any]], CaseInsensitiveDict]:
23442344
await kwargs["containerProperties"](options)
23452345
new_options = dict(options)
2346-
new_options["containerRID"] = self.__container_properties_cache[database_or_container_link]["_rid"]
2346+
new_options[Constants.InternalOptions.CONTAINER_RID] = self.__container_properties_cache[database_or_container_link]["_rid"]
23472347
return (
23482348
await self.__QueryFeed(
23492349
path,
@@ -2440,7 +2440,7 @@ def _QueryChangeFeed(
24402440
async def fetch_fn(options: Mapping[str, Any]) -> Tuple[List[Dict[str, Any]], CaseInsensitiveDict]:
24412441
if collection_link in self.__container_properties_cache:
24422442
new_options = dict(options)
2443-
new_options["containerRID"] = self.__container_properties_cache[collection_link]["_rid"]
2443+
new_options[Constants.InternalOptions.CONTAINER_RID] = self.__container_properties_cache[collection_link]["_rid"]
24442444
options = new_options
24452445
return (
24462446
await self.__QueryFeed(
@@ -2989,8 +2989,8 @@ def __GetBodiesFromQueryResult(result: Dict[str, Any]) -> List[Dict[str, Any]]:
29892989
change_feed_state: Optional[ChangeFeedState] = options.get("changeFeedState")
29902990
if change_feed_state is not None:
29912991
feed_options = {}
2992-
if 'excludedLocations' in options:
2993-
feed_options['excludedLocations'] = options['excludedLocations']
2992+
if Constants.InternalOptions.EXCLUDED_LOCATIONS in options:
2993+
feed_options[Constants.InternalOptions.EXCLUDED_LOCATIONS] = options[Constants.InternalOptions.EXCLUDED_LOCATIONS]
29942994
await change_feed_state.populate_request_headers_async(self._routing_map_provider, headers,
29952995
feed_options)
29962996
request_params.headers = headers
@@ -3256,9 +3256,9 @@ async def _AddPartitionKey(self, collection_link, document, options):
32563256
# If the collection doesn't have a partition key definition, skip it as it's a legacy collection
32573257
if partitionKeyDefinition:
32583258
# If the user has passed in the partitionKey in options use that else extract it from the document
3259-
if "partitionKey" not in options:
3259+
if Constants.InternalOptions.PARTITION_KEY not in options:
32603260
partitionKeyValue = self._ExtractPartitionKey(partitionKeyDefinition, document)
3261-
new_options["partitionKey"] = partitionKeyValue
3261+
new_options[Constants.InternalOptions.PARTITION_KEY] = partitionKeyValue
32623262

32633263
return new_options
32643264

sdk/cosmos/azure-cosmos/azure/cosmos/container.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -342,22 +342,22 @@ def read_items(
342342
"""
343343

344344
if session_token is not None:
345-
kwargs['session_token'] = session_token
345+
kwargs[Constants.Kwargs.SESSION_TOKEN] = session_token
346346
if initial_headers is not None:
347-
kwargs['initial_headers'] = initial_headers
347+
kwargs[Constants.Kwargs.INITIAL_HEADERS] = initial_headers
348348
if consistency_level is not None:
349-
kwargs['consistencyLevel'] = consistency_level
349+
kwargs[Constants.Kwargs.CONSISTENCY_LEVEL] = consistency_level
350350
if excluded_locations is not None:
351-
kwargs['excludedLocations'] = excluded_locations
351+
kwargs[Constants.Kwargs.EXCLUDED_LOCATIONS] = excluded_locations
352352
if priority is not None:
353-
kwargs['priority'] = priority
353+
kwargs[Constants.Kwargs.PRIORITY] = priority
354354
if throughput_bucket is not None:
355-
kwargs["throughput_bucket"] = throughput_bucket
355+
kwargs[Constants.Kwargs.THROUGHPUT_BUCKET] = throughput_bucket
356356

357357
kwargs['max_concurrency'] = max_concurrency
358358
query_options = build_options(kwargs)
359359
self._get_properties_with_options(query_options)
360-
query_options["enableCrossPartitionQuery"] = True
360+
query_options[Constants.InternalOptions.ENABLE_CROSS_PARTITION_QUERY] = True
361361

362362
item_tuples = [(item_id, self._set_partition_key(pk)) for item_id, pk in items]
363363

@@ -658,13 +658,13 @@ def query_items_change_feed(
658658
change_feed_state_context["startTime"] = kwargs.pop("start_time")
659659

660660
container_properties = self._get_properties_with_options(feed_options)
661-
if "partition_key" in kwargs:
662-
partition_key = kwargs.pop("partition_key")
661+
if Constants.Kwargs.PARTITION_KEY in kwargs:
662+
partition_key = kwargs.pop(Constants.Kwargs.PARTITION_KEY)
663663
change_feed_state_context["partitionKey"] = self._set_partition_key(cast(_PartitionKeyType, partition_key))
664664
change_feed_state_context["partitionKeyFeedRange"] = \
665665
get_epk_range_for_partition_key(container_properties, partition_key)
666-
if "feed_range" in kwargs:
667-
change_feed_state_context["feedRange"] = kwargs.pop('feed_range')
666+
if Constants.Kwargs.FEED_RANGE in kwargs:
667+
change_feed_state_context["feedRange"] = kwargs.pop(Constants.Kwargs.FEED_RANGE)
668668
if "continuation" in feed_options:
669669
change_feed_state_context["continuation"] = feed_options.pop("continuation")
670670

@@ -675,7 +675,7 @@ def query_items_change_feed(
675675

676676
] = container_properties["_rid"]
677677

678-
response_hook = kwargs.pop("response_hook", None)
678+
response_hook = kwargs.pop(Constants.Kwargs.RESPONSE_HOOK, None)
679679
if hasattr(response_hook, "clear"):
680680
response_hook.clear()
681681

@@ -977,17 +977,17 @@ def query_items( # pylint:disable=docstring-missing-param
977977
partition_key_value = self._set_partition_key(kwargs.pop("partition_key"))
978978
partition_key_obj = _build_partition_key_from_properties(container_properties)
979979
if partition_key_obj._is_prefix_partition_key(partition_key_value):
980-
kwargs["prefix_partition_key_object"] = partition_key_obj
981-
kwargs["prefix_partition_key_value"] = cast(_SequentialPartitionKeyType, partition_key_value)
980+
kwargs[Constants.Kwargs.PREFIX_PARTITION_KEY_OBJECT] = partition_key_obj
981+
kwargs[Constants.Kwargs.PREFIX_PARTITION_KEY_VALUE] = cast(_SequentialPartitionKeyType, partition_key_value)
982982
else:
983983
# Add to feed_options, only when feed_range not given and partition_key was not prefixed partition_key
984984
feed_options[Constants.InternalOptions.PARTITION_KEY] = partition_key_value
985985

986986
# Set 'partition_key' for QueryItems method. This can be 'None' if feed range or prefix partition key was set
987-
partition_key = feed_options.get("partitionKey")
987+
partition_key = feed_options.get(Constants.InternalOptions.PARTITION_KEY)
988988

989989
# Set 'response_hook'
990-
response_hook = kwargs.pop("response_hook", None)
990+
response_hook = kwargs.pop(Constants.Kwargs.RESPONSE_HOOK, None)
991991
if response_hook and hasattr(response_hook, "clear"):
992992
response_hook.clear()
993993

sdk/cosmos/azure-cosmos/azure/cosmos/cosmos_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ def list_databases( # pylint:disable=docstring-missing-param
457457
kwargs[Constants.Kwargs.INITIAL_HEADERS] = initial_headers
458458
feed_options = build_options(kwargs)
459459
if max_item_count is not None:
460-
feed_options["maxItemCount"] = max_item_count
460+
feed_options[Constants.InternalOptions.MAX_ITEM_COUNT] = max_item_count
461461
result = self.client_connection.ReadDatabases(options=feed_options, **kwargs)
462462
if response_hook:
463463
response_hook(self.client_connection.last_response_headers)
@@ -510,9 +510,9 @@ def query_databases( # pylint:disable=docstring-missing-param
510510
kwargs[Constants.Kwargs.THROUGHPUT_BUCKET] = throughput_bucket
511511
feed_options = build_options(kwargs)
512512
if enable_cross_partition_query is not None:
513-
feed_options["enableCrossPartitionQuery"] = enable_cross_partition_query
513+
feed_options[Constants.InternalOptions.ENABLE_CROSS_PARTITION_QUERY] = enable_cross_partition_query
514514
if max_item_count is not None:
515-
feed_options["maxItemCount"] = max_item_count
515+
feed_options[Constants.InternalOptions.MAX_ITEM_COUNT] = max_item_count
516516

517517
if query:
518518
result = self.client_connection.QueryDatabases(

sdk/cosmos/azure-cosmos/azure/cosmos/database.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ def list_containers( # pylint:disable=docstring-missing-param
525525
kwargs[Constants.Kwargs.INITIAL_HEADERS] = initial_headers
526526
feed_options = build_options(kwargs)
527527
if max_item_count is not None:
528-
feed_options["maxItemCount"] = max_item_count
528+
feed_options[Constants.InternalOptions.MAX_ITEM_COUNT] = max_item_count
529529
result = self.client_connection.ReadContainers(
530530
database_link=self.database_link, options=feed_options, **kwargs
531531
)
@@ -573,7 +573,7 @@ def query_containers( # pylint:disable=docstring-missing-param
573573
kwargs[Constants.Kwargs.INITIAL_HEADERS] = initial_headers
574574
feed_options = build_options(kwargs)
575575
if max_item_count is not None:
576-
feed_options["maxItemCount"] = max_item_count
576+
feed_options[Constants.InternalOptions.MAX_ITEM_COUNT] = max_item_count
577577
result = self.client_connection.QueryContainers(
578578
database_link=self.database_link,
579579
query=query if parameters is None else {"query": query, "parameters": parameters},
@@ -707,7 +707,7 @@ def list_users(
707707
"""
708708
feed_options = build_options(kwargs)
709709
if max_item_count is not None:
710-
feed_options["maxItemCount"] = max_item_count
710+
feed_options[Constants.InternalOptions.MAX_ITEM_COUNT] = max_item_count
711711

712712
result = self.client_connection.ReadUsers(
713713
database_link=self.database_link, options=feed_options, **kwargs
@@ -739,7 +739,7 @@ def query_users(
739739
"""
740740
feed_options = build_options(kwargs)
741741
if max_item_count is not None:
742-
feed_options["maxItemCount"] = max_item_count
742+
feed_options[Constants.InternalOptions.MAX_ITEM_COUNT] = max_item_count
743743

744744
result = self.client_connection.QueryUsers(
745745
database_link=self.database_link,

0 commit comments

Comments
 (0)