Skip to content

Commit 19de891

Browse files
authored
Fix pylint errors (Azure#39397)
* Fix pylint errors * Fix the errors for unit tests * Addressing comments * Addressed comments * Removing `match_condition` from non-applicable APIs * Removing unused imports * Revert "Removing unused imports" This reverts commit 17e7517. * Revert "Removing `match_condition` from non-applicable APIs" This reverts commit 6993928. * fix import style error * Removed unnecessary pylint disables * Address comments * Addressed comments
1 parent a5f87d7 commit 19de891

File tree

12 files changed

+219
-146
lines changed

12 files changed

+219
-146
lines changed

sdk/cosmos/azure-cosmos/azure/cosmos/_change_feed/change_feed_utils.py

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -75,74 +75,71 @@ def add_args_to_kwargs(
7575
kwargs[key] = value
7676

7777
def validate_kwargs(
78-
kwargs: Dict[str, Any]
78+
keyword_arguments: Dict[str, Any]
7979
) -> None:
80-
"""Validate keyword arguments(kwargs).
81-
The values of keyword arguments must match the expect type and conditions. If the conditions do not match,
82-
errors will be raised with the error messages and possible ways to correct the errors.
83-
84-
:param kwargs: Keyword arguments to verify for query_items_change_feed API
85-
:keyword mode: Must be one of the values in the Enum, 'ChangeFeedMode'.
86-
If the value is 'ALL_VERSIONS_AND_DELETES', the following keywords must be in the right condition:
87-
- 'partition_key_range_id': Cannot be used at any time
88-
- 'is_start_from_beginning': Must be 'False'
89-
- 'start_time': Must be "Now"
90-
:paramtype mode: Optional[Literal["LatestVersion", "AllVersionsAndDeletes"]]
91-
:keyword partition_key_range_id: Deprecated Warning.
92-
:paramtype partition_key_range_id: str
93-
:keyword is_start_from_beginning: Deprecated Warning. Cannot be used with 'start_time'.
94-
:paramtype is_start_from_beginning: bool
95-
:keyword start_time: Must be in supported types.
96-
:paramtype start_time: Union[~datetime.datetime, Literal["Now", "Beginning"]]
97-
:type kwargs: dict[str, Any]
80+
"""Validate keyword arguments for change_feed API.
81+
The values of keyword arguments must match the expected type and conditions. If the conditions do not match,
82+
errors will be raised with the proper error messages and possible ways to correct the errors.
83+
84+
:param dict[str, Any] keyword_arguments: Keyword arguments to verify for query_items_change_feed API
85+
- Literal["LatestVersion", "AllVersionsAndDeletes"] mode: Must be one of the values in the Enum,
86+
'ChangeFeedMode'. If the value is 'ALL_VERSIONS_AND_DELETES', the following keywords must be in the right
87+
conditions:
88+
- 'partition_key_range_id': Cannot be used at any time
89+
- 'is_start_from_beginning': Must be 'False'
90+
- 'start_time': Must be "Now"
91+
- str partition_key_range_id: Deprecated Warning.
92+
- bool is_start_from_beginning: Deprecated Warning. Cannot be used with 'start_time'.
93+
- Union[~datetime.datetime, Literal["Now", "Beginning"]] start_time: Must be in supported types.
9894
"""
9995
# Filter items with value None
100-
kwargs = {key: value for key, value in kwargs.items() if value is not None}
96+
keyword_arguments = {key: value for key, value in keyword_arguments.items() if value is not None}
10197

10298
# Validate the keyword arguments
103-
if "mode" in kwargs:
104-
mode = kwargs["mode"]
99+
if "mode" in keyword_arguments:
100+
mode = keyword_arguments["mode"]
105101
if mode not in CHANGE_FEED_MODES:
106102
raise ValueError(
107-
f"Invalid mode was used: '{kwargs['mode']}'."
103+
f"Invalid mode was used: '{keyword_arguments['mode']}'."
108104
f" Supported modes are {CHANGE_FEED_MODES}.")
109105

110106
if mode == 'AllVersionsAndDeletes':
111-
if "partition_key_range_id" in kwargs:
107+
if "partition_key_range_id" in keyword_arguments:
112108
raise ValueError(
113109
"'AllVersionsAndDeletes' mode is not supported if 'partition_key_range_id'"
114110
" was used. Please use 'feed_range' instead.")
115-
if "is_start_from_beginning" in kwargs and kwargs["is_start_from_beginning"] is not False:
111+
if ("is_start_from_beginning" in keyword_arguments
112+
and keyword_arguments["is_start_from_beginning"] is not False):
116113
raise ValueError(
117114
"'AllVersionsAndDeletes' mode is only supported if 'is_start_from_beginning'"
118115
" is 'False'. Please use 'is_start_from_beginning=False' or 'continuation' instead.")
119-
if "start_time" in kwargs and kwargs["start_time"] != "Now":
116+
if "start_time" in keyword_arguments and keyword_arguments["start_time"] != "Now":
120117
raise ValueError(
121118
"'AllVersionsAndDeletes' mode is only supported if 'start_time' is 'Now'."
122119
" Please use 'start_time=\"Now\"' or 'continuation' instead.")
123120

124-
if "partition_key_range_id" in kwargs:
121+
if "partition_key_range_id" in keyword_arguments:
125122
warnings.warn(
126123
"'partition_key_range_id' is deprecated. Please pass in 'feed_range' instead.",
127124
DeprecationWarning
128125
)
129126

130-
if "is_start_from_beginning" in kwargs:
127+
if "is_start_from_beginning" in keyword_arguments:
131128
warnings.warn(
132129
"'is_start_from_beginning' is deprecated. Please pass in 'start_time' instead.",
133130
DeprecationWarning
134131
)
135132

136-
if not isinstance(kwargs["is_start_from_beginning"], bool):
133+
if not isinstance(keyword_arguments["is_start_from_beginning"], bool):
137134
raise TypeError(
138135
f"'is_start_from_beginning' must be 'bool' type,"
139-
f" but given '{type(kwargs['is_start_from_beginning']).__name__}'.")
136+
f" but given '{type(keyword_arguments['is_start_from_beginning']).__name__}'.")
140137

141-
if kwargs["is_start_from_beginning"] is True and "start_time" in kwargs:
138+
if keyword_arguments["is_start_from_beginning"] is True and "start_time" in keyword_arguments:
142139
raise ValueError("'is_start_from_beginning' and 'start_time' are exclusive, please only set one of them.")
143140

144-
if "start_time" in kwargs:
145-
if not isinstance(kwargs['start_time'], datetime):
146-
if kwargs['start_time'].lower() not in ["now", "beginning"]:
141+
if "start_time" in keyword_arguments:
142+
if not isinstance(keyword_arguments['start_time'], datetime):
143+
if keyword_arguments['start_time'].lower() not in ["now", "beginning"]:
147144
raise ValueError(
148-
f"'start_time' must be either 'Now' or 'Beginning', but given '{kwargs['start_time']}'.")
145+
f"'start_time' must be either 'Now' or 'Beginning', but given '{keyword_arguments['start_time']}'.")

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,14 +1031,14 @@ def ReadItems(
10311031
self,
10321032
collection_link: str,
10331033
feed_options: Optional[Mapping[str, Any]] = None,
1034-
response_hook: Optional[Callable[[Mapping[str, Any], Mapping[str, Any]], None]] = None,
1034+
response_hook: Optional[Callable[[Mapping[str, Any], Dict[str, Any]], None]] = None,
10351035
**kwargs: Any
10361036
) -> ItemPaged[Dict[str, Any]]:
10371037
"""Reads all documents in a collection.
10381038
:param str collection_link: The link to the document collection.
10391039
:param dict feed_options: The additional options for the operation.
10401040
:param response_hook: A callable invoked with the response metadata.
1041-
:type response_hook: Callable[[Dict[str, str], Dict[str, Any]]
1041+
:type response_hook: Callable[[Mapping[str, Any], Dict[str, Any]]
10421042
:return: Query Iterable of Documents.
10431043
:rtype: query_iterable.QueryIterable
10441044
"""
@@ -1053,7 +1053,7 @@ def QueryItems(
10531053
query: Optional[Union[str, Dict[str, Any]]],
10541054
options: Optional[Mapping[str, Any]] = None,
10551055
partition_key: Optional[PartitionKeyType] = None,
1056-
response_hook: Optional[Callable[[Mapping[str, Any], Mapping[str, Any]], None]] = None,
1056+
response_hook: Optional[Callable[[Mapping[str, Any], Dict[str, Any]], None]] = None,
10571057
**kwargs: Any
10581058
) -> ItemPaged[Dict[str, Any]]:
10591059
"""Queries documents in a collection.
@@ -1065,7 +1065,7 @@ def QueryItems(
10651065
:param partition_key: Partition key for the query(default value None)
10661066
:type: partition_key: Union[str, int, float, bool, List[Union[str, int, float, bool]]]
10671067
:param response_hook: A callable invoked with the response metadata.
1068-
:type response_hook: Callable[[Dict[str, str], Dict[str, Any]]
1068+
:type response_hook: Callable[[Mapping[str, Any], Dict[str, Any]], None]
10691069
10701070
:return:
10711071
Query Iterable of Documents.
@@ -3005,7 +3005,7 @@ def __QueryFeed( # pylint: disable=too-many-locals, too-many-statements
30053005
query: Optional[Union[str, Dict[str, Any]]],
30063006
options: Optional[Mapping[str, Any]] = None,
30073007
partition_key_range_id: Optional[str] = None,
3008-
response_hook: Optional[Callable[[Mapping[str, Any], Mapping[str, Any]], None]] = None,
3008+
response_hook: Optional[Callable[[Mapping[str, Any], Dict[str, Any]], None]] = None,
30093009
is_query_plan: bool = False,
30103010
**kwargs: Any
30113011
) -> Tuple[List[Dict[str, Any]], CaseInsensitiveDict]:
@@ -3021,7 +3021,8 @@ def __QueryFeed( # pylint: disable=too-many-locals, too-many-statements
30213021
The request options for the request.
30223022
:param str partition_key_range_id:
30233023
Specifies partition key range id.
3024-
:param function response_hook:
3024+
:param response_hook: A callable invoked with the response metadata.
3025+
:type response_hook: Callable[[Mapping[str, Any], Dict[str, Any]], None]
30253026
:param bool is_query_plan:
30263027
Specifies if the call is to fetch query plan
30273028
:returns: A list of the queried resources.

0 commit comments

Comments
 (0)