Skip to content

Fix pylint errors #39397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,20 @@ def validate_kwargs(
The values of keyword arguments must match the expect type and conditions. If the conditions do not match,
errors will be raised with the error messages and possible ways to correct the errors.

:param kwargs: Keyword arguments to verify for query_items_change_feed API
:keyword mode: Must be one of the values in the Enum, 'ChangeFeedMode'.
:param dict[str, Any] kwargs: Keyword arguments to verify for query_items_change_feed API
* keyword mode: Must be one of the values in the Enum, 'ChangeFeedMode'.
If the value is 'ALL_VERSIONS_AND_DELETES', the following keywords must be in the right condition:
- 'partition_key_range_id': Cannot be used at any time
- 'is_start_from_beginning': Must be 'False'
- 'start_time': Must be "Now"
:paramtype mode: Optional[Literal["LatestVersion", "AllVersionsAndDeletes"]]
:keyword partition_key_range_id: Deprecated Warning.
:paramtype partition_key_range_id: str
:keyword is_start_from_beginning: Deprecated Warning. Cannot be used with 'start_time'.
:paramtype is_start_from_beginning: bool
:keyword start_time: Must be in supported types.
:paramtype start_time: Union[~datetime.datetime, Literal["Now", "Beginning"]]
:type kwargs: dict[str, Any]
* paramtype mode: Optional[Literal["LatestVersion", "AllVersionsAndDeletes"]]
* keyword partition_key_range_id: Deprecated Warning.
* paramtype partition_key_range_id: str
* keyword is_start_from_beginning: Deprecated Warning. Cannot be used with 'start_time'.
* paramtype is_start_from_beginning: bool
* keyword start_time: Must be in supported types.
* paramtype start_time: Union[~datetime.datetime, Literal["Now", "Beginning"]]
* type kwargs: dict[str, Any]
"""
# Filter items with value None
kwargs = {key: value for key, value in kwargs.items() if value is not None}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1029,14 +1029,14 @@ def ReadItems(
self,
collection_link: str,
feed_options: Optional[Mapping[str, Any]] = None,
response_hook: Optional[Callable[[Mapping[str, Any], Mapping[str, Any]], None]] = None,
response_hook: Optional[Callable[[CaseInsensitiveDict, Dict[str, Any]], None]] = None,
**kwargs: Any
) -> ItemPaged[Dict[str, Any]]:
"""Reads all documents in a collection.
:param str collection_link: The link to the document collection.
:param dict feed_options: The additional options for the operation.
:param response_hook: A callable invoked with the response metadata.
:type response_hook: Callable[[Dict[str, str], Dict[str, Any]]
:type response_hook: Callable[[CaseInsensitiveDict, Dict[str, Any]]
:return: Query Iterable of Documents.
:rtype: query_iterable.QueryIterable
"""
Expand All @@ -1051,7 +1051,7 @@ def QueryItems(
query: Optional[Union[str, Dict[str, Any]]],
options: Optional[Mapping[str, Any]] = None,
partition_key: Optional[PartitionKeyType] = None,
response_hook: Optional[Callable[[Mapping[str, Any], Mapping[str, Any]], None]] = None,
response_hook: Optional[Callable[[CaseInsensitiveDict, Dict[str, Any]], None]] = None,
**kwargs: Any
) -> ItemPaged[Dict[str, Any]]:
"""Queries documents in a collection.
Expand All @@ -1063,7 +1063,7 @@ def QueryItems(
:param partition_key: Partition key for the query(default value None)
:type: partition_key: Union[str, int, float, bool, List[Union[str, int, float, bool]]]
:param response_hook: A callable invoked with the response metadata.
:type response_hook: Callable[[Dict[str, str], Dict[str, Any]]
:type response_hook: Callable[[CaseInsensitiveDict, Dict[str, Any]]

:return:
Query Iterable of Documents.
Expand Down Expand Up @@ -2974,7 +2974,7 @@ def __QueryFeed( # pylint: disable=too-many-locals, too-many-statements
query: Optional[Union[str, Dict[str, Any]]],
options: Optional[Mapping[str, Any]] = None,
partition_key_range_id: Optional[str] = None,
response_hook: Optional[Callable[[Mapping[str, Any], Mapping[str, Any]], None]] = None,
response_hook: Optional[Callable[[CaseInsensitiveDict, Dict[str, Any]], None]] = None,
is_query_plan: bool = False,
**kwargs: Any
) -> Tuple[List[Dict[str, Any]], CaseInsensitiveDict]:
Expand All @@ -2990,7 +2990,8 @@ def __QueryFeed( # pylint: disable=too-many-locals, too-many-statements
The request options for the request.
:param str partition_key_range_id:
Specifies partition key range id.
:param function response_hook:
:param response_hook: A callable invoked with the response metadata.
:type response_hook: Callable[[CaseInsensitiveDict, Dict[str, Any]]
:param bool is_query_plan:
Specifies if the call is to fetch query plan
:returns: A list of the queried resources.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def on_response(
if http_response.status_code >= 400:
logger.info("Response error message: %r", _format_error(http_response.text()))
except Exception as err: # pylint: disable=broad-except
logger.warning("Failed to log request: %s", repr(err))
logger.warning("Failed to log request: %s", repr(err)) # pylint: disable=do-not-log-exceptions

# pylint: disable=unused-argument
def _default_should_log(
Expand Down
43 changes: 29 additions & 14 deletions sdk/cosmos/azure-cosmos/azure/cosmos/aio/_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
"""Create, read, update and delete items in the Azure Cosmos DB SQL API service.
"""
from datetime import datetime
from typing import Any, Dict, Mapping, Optional, Sequence, Type, Union, List, Tuple, cast, overload, AsyncIterable
from typing import (Any, Dict, Mapping, Optional, Sequence, Type, Union, List, Tuple, cast, overload, AsyncIterable,
Callable)
from typing_extensions import Literal

from azure.core import MatchConditions
from azure.core.async_paging import AsyncItemPaged, AsyncList
from azure.core.tracing.decorator import distributed_trace
from azure.core.tracing.decorator_async import distributed_trace_async # type: ignore
from azure.core.utils import CaseInsensitiveDict
from azure.cosmos._change_feed.change_feed_utils import validate_kwargs

from ._cosmos_client_connection_async import CosmosClientConnection
Expand Down Expand Up @@ -58,6 +60,7 @@
# pylint: disable=protected-access, too-many-lines
# pylint: disable=missing-client-constructor-parameter-credential,missing-client-constructor-parameter-kwargs
# pylint: disable=too-many-public-methods
# pylint: disable=docstring-keyword-should-match-keyword-only

PartitionKeyType = Union[str, int, float, bool, Sequence[Union[str, int, float, bool, None]], Type[NonePartitionKeyValue]] # pylint: disable=line-too-long

Expand Down Expand Up @@ -336,6 +339,8 @@ def read_all_items(
max_item_count: Optional[int] = None,
session_token: Optional[str] = None,
initial_headers: Optional[Dict[str, str]] = None,
response_hook: Optional[Callable[[CaseInsensitiveDict,
Union[Dict[str, Any], AsyncItemPaged[Dict[str, Any]]]], None]] = None,
max_integrated_cache_staleness_in_ms: Optional[int] = None,
priority: Optional[Literal["High", "Low"]] = None,
**kwargs: Any
Expand All @@ -346,7 +351,8 @@ def read_all_items(
:keyword str session_token: Token for use with Session consistency.
:keyword dict[str, str] initial_headers: Initial headers to be sent as part of the request.
:keyword response_hook: A callable invoked with the response metadata.
:paramtype response_hook: Callable[[Dict[str, str], AsyncItemPaged[Dict[str, Any]]], None]
:paramtype response_hook:
Callable[[CaseInsensitiveDict, Union[Dict[str, Any], AsyncItemPaged[Dict[str, Any]]]], None]
:keyword int max_integrated_cache_staleness_in_ms: The max cache staleness for the integrated cache in
milliseconds. For accounts configured to use the integrated cache, using Session or Eventual consistency,
responses are guaranteed to be no staler than this value.
Expand All @@ -356,7 +362,6 @@ def read_all_items(
:returns: An AsyncItemPaged of items (dicts).
:rtype: AsyncItemPaged[Dict[str, Any]]
"""
response_hook = kwargs.pop('response_hook', None)
if session_token is not None:
kwargs['session_token'] = session_token
if initial_headers is not None:
Expand All @@ -369,7 +374,7 @@ def read_all_items(
if max_integrated_cache_staleness_in_ms:
validate_cache_staleness_value(max_integrated_cache_staleness_in_ms)
feed_options["maxIntegratedCacheStaleness"] = max_integrated_cache_staleness_in_ms
if hasattr(response_hook, "clear"):
if response_hook and hasattr(response_hook, "clear"):
response_hook.clear()
if self.container_link in self.__get_client_container_caches():
feed_options["containerRID"] = self.__get_client_container_caches()[self.container_link]["_rid"]
Expand Down Expand Up @@ -397,6 +402,8 @@ def query_items(
max_integrated_cache_staleness_in_ms: Optional[int] = None,
priority: Optional[Literal["High", "Low"]] = None,
continuation_token_limit: Optional[int] = None,
response_hook: Optional[Callable[[CaseInsensitiveDict,
Union[Dict[str, Any], AsyncItemPaged[Dict[str, Any]]]], None]] = None,
**kwargs: Any
) -> AsyncItemPaged[Dict[str, Any]]:
"""Return all results matching the given `query`.
Expand Down Expand Up @@ -424,7 +431,8 @@ def query_items(
:keyword str session_token: Token for use with Session consistency.
:keyword dict[str, str] initial_headers: Initial headers to be sent as part of the request.
:keyword response_hook: A callable invoked with the response metadata.
:paramtype response_hook: Callable[[Dict[str, str], AsyncItemPaged[Dict[str, Any]]], None]
:paramtype response_hook:
Callable[[CaseInsensitiveDict, Union[Dict[str, Any], AsyncItemPaged[Dict[str, Any]]]], None]
:keyword int continuation_token_limit: The size limit in kb of the response continuation token in the query
response. Valid values are positive integers.
A value of 0 is the same as not passing a value (default no limit).
Expand Down Expand Up @@ -455,7 +463,6 @@ def query_items(
:caption: Parameterized query to get all products that have been discontinued:
:name: query_items_param
"""
response_hook = kwargs.pop('response_hook', None)
if session_token is not None:
kwargs['session_token'] = session_token
if initial_headers is not None:
Expand Down Expand Up @@ -483,7 +490,7 @@ def query_items(
feed_options["correlatedActivityId"] = correlated_activity_id
if continuation_token_limit is not None:
feed_options["responseContinuationTokenLimitInKb"] = continuation_token_limit
if hasattr(response_hook, "clear"):
if response_hook and hasattr(response_hook, "clear"):
response_hook.clear()
if self.container_link in self.__get_client_container_caches():
feed_options["containerRID"] = self.__get_client_container_caches()[self.container_link]["_rid"]
Expand All @@ -509,6 +516,7 @@ def query_items_change_feed(
partition_key: PartitionKeyType,
priority: Optional[Literal["High", "Low"]] = None,
mode: Optional[Literal["LatestVersion", "AllVersionsAndDeletes"]] = None,
response_hook: Optional[Callable[[CaseInsensitiveDict, AsyncItemPaged[Dict[str, Any]]], None]] = None,
**kwargs: Any
) -> AsyncItemPaged[Dict[str, Any]]:
"""Get a sorted list of items that were changed, in the order in which they were modified.
Expand Down Expand Up @@ -547,6 +555,7 @@ def query_items_change_feed(
start_time: Optional[Union[datetime, Literal["Now", "Beginning"]]] = None,
priority: Optional[Literal["High", "Low"]] = None,
mode: Optional[Literal["LatestVersion", "AllVersionsAndDeletes"]] = None,
response_hook: Optional[Callable[[CaseInsensitiveDict, AsyncItemPaged[Dict[str, Any]]], None]] = None,
**kwargs: Any
) -> AsyncItemPaged[Dict[str, Any]]:
"""Get a sorted list of items that were changed, in the order in which they were modified.
Expand All @@ -569,7 +578,7 @@ def query_items_change_feed(
or 'continuation' token.
:paramtype mode: Literal["LatestVersion", "AllVersionsAndDeletes"]
:keyword response_hook: A callable invoked with the response metadata.
:paramtype response_hook: Callable[[Mapping[str, Any], Mapping[str, Any]], None]
:paramtype response_hook: Callable[[CaseInsensitiveDict, AsyncItemPaged[Dict[str, Any]]], None]
:returns: An AsyncItemPaged of items (dicts).
:rtype: AsyncItemPaged[Dict[str, Any]]
"""
Expand All @@ -582,6 +591,7 @@ def query_items_change_feed(
continuation: str,
max_item_count: Optional[int] = None,
priority: Optional[Literal["High", "Low"]] = None,
response_hook: Optional[Callable[[CaseInsensitiveDict, AsyncItemPaged[Dict[str, Any]]], None]] = None,
**kwargs: Any
) -> AsyncItemPaged[Dict[str, Any]]:
"""Get a sorted list of items that were changed, in the order in which they were modified.
Expand All @@ -594,7 +604,7 @@ def query_items_change_feed(
before high priority requests start getting throttled. Feature must first be enabled at the account level.
:paramtype priority: Literal["High", "Low"]
:keyword response_hook: A callable invoked with the response metadata.
:paramtype response_hook: Callable[[Mapping[str, Any], Mapping[str, Any]], None]
:paramtype response_hook: Callable[[CaseInsensitiveDict, AsyncItemPaged[Dict[str, Any]]], None]
:returns: An AsyncItemPaged of items (dicts).
:rtype: AsyncItemPaged[Dict[str, Any]]
"""
Expand All @@ -609,6 +619,7 @@ def query_items_change_feed(
start_time: Optional[Union[datetime, Literal["Now", "Beginning"]]] = None,
priority: Optional[Literal["High", "Low"]] = None,
mode: Optional[Literal["LatestVersion", "AllVersionsAndDeletes"]] = None,
response_hook: Optional[Callable[[CaseInsensitiveDict, AsyncItemPaged[Dict[str, Any]]], None]] = None,
**kwargs: Any
) -> AsyncItemPaged[Dict[str, Any]]:
"""Get a sorted list of items that were changed in the entire container,
Expand All @@ -631,7 +642,7 @@ def query_items_change_feed(
or 'continuation' token.
:paramtype mode: Literal["LatestVersion", "AllVersionsAndDeletes"]
:keyword response_hook: A callable invoked with the response metadata.
:paramtype response_hook: Callable[[Mapping[str, Any], Mapping[str, Any]], None]
:paramtype response_hook: Callable[[CaseInsensitiveDict, AsyncItemPaged[Dict[str, Any]]], None]
:returns: An AsyncItemPaged of items (dicts).
:rtype: AsyncItemPaged[Dict[str, Any]]
"""
Expand Down Expand Up @@ -992,7 +1003,12 @@ async def delete_item(
await self.client_connection.DeleteItem(document_link=document_link, options=request_options, **kwargs)

@distributed_trace_async
async def get_throughput(self, **kwargs: Any) -> ThroughputProperties:
async def get_throughput(
self,
*,
response_hook: Optional[Callable[[CaseInsensitiveDict, List[Dict[str, Any]]], None]] = None,
**kwargs: Any
) -> ThroughputProperties:
"""Get the ThroughputProperties object for this container.

If no ThroughputProperties already exists for the container, an exception is raised.
Expand All @@ -1004,7 +1020,6 @@ async def get_throughput(self, **kwargs: Any) -> ThroughputProperties:
:returns: ThroughputProperties for the container.
:rtype: ~azure.cosmos.offer.ThroughputProperties
"""
response_hook = kwargs.pop('response_hook', None)
throughput_properties: List[Dict[str, Any]]
properties = await self._get_properties()
link = properties["_self"]
Expand Down Expand Up @@ -1063,6 +1078,7 @@ def list_conflicts(
self,
*,
max_item_count: Optional[int] = None,
response_hook: Optional[Callable[[CaseInsensitiveDict, AsyncItemPaged[Dict[str, Any]]], None]] = None,
**kwargs: Any
) -> AsyncItemPaged[Dict[str, Any]]:
"""List all the conflicts in the container.
Expand All @@ -1074,7 +1090,6 @@ def list_conflicts(
:rtype: AsyncItemPaged[Dict[str, Any]]
"""
feed_options = _build_options(kwargs)
response_hook = kwargs.pop('response_hook', None)
if max_item_count is not None:
feed_options["maxItemCount"] = max_item_count
if self.container_link in self.__get_client_container_caches():
Expand All @@ -1095,6 +1110,7 @@ def query_conflicts(
parameters: Optional[List[Dict[str, object]]] = None,
partition_key: Optional[PartitionKeyType] = None,
max_item_count: Optional[int] = None,
response_hook: Optional[Callable[[CaseInsensitiveDict, AsyncItemPaged[Dict[str, Any]]], None]] = None,
**kwargs: Any
) -> AsyncItemPaged[Dict[str, Any]]:
"""Return all conflicts matching a given `query`.
Expand All @@ -1112,7 +1128,6 @@ def query_conflicts(
:rtype: AsyncItemPaged[Dict[str, Any]]
"""
feed_options = _build_options(kwargs)
response_hook = kwargs.pop('response_hook', None)
if max_item_count is not None:
feed_options["maxItemCount"] = max_item_count
if partition_key is not None:
Expand Down
Loading
Loading