Skip to content

Commit

Permalink
[EH] next-pylint (Azure#38896)
Browse files Browse the repository at this point in the history
* eh pylint

* remove

* fix

* update
  • Loading branch information
l0lawrence authored Dec 17, 2024
1 parent f98d6ad commit 8f4fff6
Show file tree
Hide file tree
Showing 36 changed files with 91 additions and 181 deletions.
5 changes: 2 additions & 3 deletions sdk/eventhub/azure-eventhub/azure/eventhub/_client_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ def _backoff(
)
if backoff <= self._config.backoff_max and (
timeout_time is None or time.time() + backoff <= timeout_time
): # pylint:disable=no-else-return
):
time.sleep(backoff)
_LOGGER.info(
"%r has an exception (%r). Retrying...",
Expand All @@ -411,7 +411,6 @@ def _backoff(
def _management_request( # pylint:disable=inconsistent-return-statements
self, mgmt_msg: Union[uamqp_Message, Message], op_type: bytes
) -> Any:
# pylint:disable=assignment-from-none
retried_times = 0
last_exception = None
while retried_times <= self._config.max_retries:
Expand All @@ -420,7 +419,7 @@ def _management_request( # pylint:disable=inconsistent-return-statements
self._address, mgmt_auth=mgmt_auth, config=self._config
)
try:
conn = self._conn_manager.get_connection( # pylint:disable=assignment-from-none
conn = self._conn_manager.get_connection(
endpoint=self._address.hostname, auth=mgmt_auth
)
mgmt_client.open(connection=conn)
Expand Down
6 changes: 1 addition & 5 deletions sdk/eventhub/azure-eventhub/azure/eventhub/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@

if TYPE_CHECKING:
try:
from uamqp import ( # pylint: disable=unused-import
from uamqp import (
Message, # not importing as uamqp_Message, b/c type is exposed to user
BatchMessage,
)
Expand Down Expand Up @@ -143,7 +143,6 @@ def __init__(
self.correlation_id = None

def __repr__(self) -> str:
# pylint: disable=bare-except
try:
body_str = self.body_as_str()
except Exception as e: # pylint: disable=broad-except
Expand Down Expand Up @@ -230,7 +229,6 @@ def _from_message(
message: Union["Message", pyamqp_Message],
raw_amqp_message: Optional[AmqpAnnotatedMessage] = None,
) -> EventData:
# pylint:disable=protected-access
"""Internal use only.
Creates an EventData object from a raw uamqp message and, if provided, AmqpAnnotatedMessage.
Expand All @@ -242,13 +240,11 @@ def _from_message(
:rtype: ~azure.eventhub.EventData
"""
event_data = cls(body="")
# pylint: disable=protected-access
event_data._message = message
event_data._raw_amqp_message = raw_amqp_message if raw_amqp_message else AmqpAnnotatedMessage(message=message)
return event_data

def _decode_non_data_body_as_str(self, encoding: str = "UTF-8") -> str:
# pylint: disable=protected-access
body = self.raw_amqp_message.body
if self.body_type == AmqpMessageBodyType.VALUE:
if not body:
Expand Down
5 changes: 2 additions & 3 deletions sdk/eventhub/azure-eventhub/azure/eventhub/_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def __init__(self, client: "EventHubConsumerClient", source: str, **kwargs: Any)
if owner_level is not None:
link_properties[EPOCH_SYMBOL] = int(owner_level)
link_property_timeout_ms = (
self._client._config.receive_timeout or self._timeout # pylint:disable=protected-access
self._client._config.receive_timeout or self._timeout
) * self._amqp_transport.TIMEOUT_FACTOR
link_properties[TIMEOUT_SYMBOL] = int(link_property_timeout_ms)
self._link_properties: Union[Dict[uamqp_AMQPType, uamqp_AMQPType], Dict[types.AMQPTypes, types.AMQPTypes]] = (
Expand Down Expand Up @@ -158,7 +158,6 @@ def _open_with_retry(self) -> None:
self._do_retryable_operation(self._open, operation_need_param=False)

def _message_received(self, message: Union[uamqp_Message, Message]) -> None:
# pylint:disable=protected-access
self._message_buffer.append(message)

def _next_message_in_buffer(self):
Expand Down Expand Up @@ -245,7 +244,7 @@ def receive(self, batch=False, max_batch_size=300, max_wait_time=None):
if batch:
events_for_callback = []
for _ in range(min(max_batch_size, len(self._message_buffer))):
events_for_callback.append(self._next_message_in_buffer()) # pylint: disable=protected-access
events_for_callback.append(self._next_message_in_buffer())
self._on_event_received(events_for_callback)
else:
self._on_event_received(self._next_message_in_buffer() if self._message_buffer else None)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
)

if TYPE_CHECKING:
# pylint: disable=ungrouped-imports
from .._common import EventData
from .._consumer import EventHubConsumer
from ..aio._consumer_async import EventHubConsumer as EventHubConsumerAsync
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,9 @@ def __init__(
prefetch: Optional[int] = None,
track_last_enqueued_event_properties: bool = False,
) -> None:
# pylint: disable=line-too-long
self._consumer_group = consumer_group
self._eventhub_client = eventhub_client
self._namespace = eventhub_client._address.hostname # pylint: disable=protected-access
self._namespace = eventhub_client._address.hostname
self._eventhub_name = eventhub_client.eventhub_name
self._event_handler = on_event
self._batch = batch
Expand Down Expand Up @@ -240,7 +239,7 @@ def _on_event_received(

with receive_context_manager(
self._eventhub_client, links=links, start_time=self._last_received_time
): # pylint:disable=protected-access
):
self._last_received_time = time.time_ns()

with process_context_manager(self._eventhub_client, links=links, is_batch=is_batch):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(
self.cached_parition_ids: List[str] = []
self.owned_partitions: Iterable[Dict[str, Any]] = []
self.eventhub_client = eventhub_client
self.fully_qualified_namespace = eventhub_client._address.hostname # pylint: disable=protected-access
self.fully_qualified_namespace = eventhub_client._address.hostname
self.eventhub_name = eventhub_client.eventhub_name
self.consumer_group = consumer_group
self.owner_id = owner_id
Expand Down
2 changes: 1 addition & 1 deletion sdk/eventhub/azure-eventhub/azure/eventhub/_producer.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def send(
links = [link] if link else []

self._unsent_events = [wrapper_event_data._message] # pylint: disable=protected-access
with send_context_manager(self._client, links=links): # pylint: disable=protected-access
with send_context_manager(self._client, links=links):
self._send_event_data_with_retry(timeout=timeout)

def close(self) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def _buffered_send_event(
timeout: Optional[float] = None,
partition_id: Optional[str] = None,
partition_key: Optional[str] = None,
**kwargs: Any, # pylint: disable=unused-argument
**kwargs: Any,
) -> None:
set_event_partition_key(event, partition_key, self._amqp_transport)
timeout_time = time.time() + timeout if timeout else None
Expand Down Expand Up @@ -565,7 +565,7 @@ def send_event(
timeout: Optional[float] = None,
partition_id: Optional[str] = None,
partition_key: Optional[str] = None,
**kwargs: Any, # pylint: disable=unused-argument
**kwargs: Any,
) -> None:
"""
Sends an event data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
)


def get_local_timeout(now: float, idle_timeout: Optional[float], last_frame_received_time: float) -> bool:
def get_local_timeout(now: float, idle_timeout: float, last_frame_received_time: float) -> bool:
"""Check whether the local timeout has been reached since a new incoming frame was received.
:param float now: The current time to check against.
Expand Down Expand Up @@ -90,7 +90,7 @@ class Connection: # pylint:disable=too-many-instance-attributes
and 1 for transport type AmqpOverWebsocket.
"""

def __init__( # pylint:disable=too-many-locals,too-many-statements
def __init__( # pylint:disable=too-many-locals
self,
endpoint: str,
*,
Expand Down
2 changes: 0 additions & 2 deletions sdk/eventhub/azure-eventhub/azure/eventhub/_pyamqp/_decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
# pylint: disable=redefined-builtin, import-error

import struct
import uuid
import logging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,9 @@ def encode_map(
count = len(cast(Sized, value)) * 2
encoded_size = 0
encoded_values = bytearray()
items: Iterable[Any]
if isinstance(value, dict):
items: Iterable[Any] = value.items()
items = value.items()
elif isinstance(value, Iterable):
items = value

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------

# pylint: disable=too-many-lines
from enum import Enum
from typing import (
Callable,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ------------------------------------------------------------------------- # pylint: disable=file-needs-copyright-header
# ------------------------------------------------------------------------- # pylint: disable=file-needs-copyright-header,useless-suppression
# This is a fork of the transport.py which was originally written by Barry Pederson and
# maintained by the Celery project: https://github.com/celery/py-amqp.
#
Expand Down Expand Up @@ -32,7 +32,6 @@
# THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------


import errno
import re
import socket
Expand Down Expand Up @@ -747,7 +746,7 @@ def connect(self):
self.close()
raise

def _read(self, n, initial=False, buffer=None, _errnos=None): # pylint: disable=unused-argument
def _read(self, n, initial=False, buffer=None, _errnos=None):
"""Read exactly n bytes from the peer.
:param int n: The number of bytes to read.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ async def update_token(self) -> None:
if self._token and token_type:
await self._put_token(self._token, token_type, self._auth.audience, utc_from_timestamp(self._expires_on))

async def handle_token(self) -> bool: # pylint: disable=inconsistent-return-statements
async def handle_token(self) -> bool:
if not await self._cbs_link_ready():
return False
await self._update_status()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# ------------------------------------------------------------------------- # pylint: disable=client-suffix-needed
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
# TODO: Check types of kwargs (issue exists for this)
# pylint: disable=too-many-lines
import asyncio
import logging
import time
Expand Down Expand Up @@ -69,7 +68,7 @@ class AMQPClientAsync(AMQPClientSync):
:paramtype channel_max: int
:keyword idle_timeout: Timeout in seconds after which the Connection will close
if there is no further activity.
:paramtype idle_timeout: Optional[float]
:paramtype idle_timeout: int
:keyword auth_timeout: Timeout in seconds for CBS authentication. Otherwise this value will be ignored.
Default value is 60s.
:paramtype auth_timeout: int
Expand Down Expand Up @@ -426,7 +425,7 @@ class SendClientAsync(SendClientSync, AMQPClientAsync):
:paramtype channel_max: int
:keyword idle_timeout: Timeout in seconds after which the Connection will close
if there is no further activity.
:paramtype idle_timeout: Optional[float]
:paramtype idle_timeout: int
:keyword auth_timeout: Timeout in seconds for CBS authentication. Otherwise this value will be ignored.
Default value is 60s.
:paramtype auth_timeout: int
Expand Down Expand Up @@ -499,7 +498,6 @@ async def _client_ready_async(self):
:return: Whether or not the client is ready to start sending messages.
:rtype: bool
"""
# pylint: disable=protected-access
if not self._link:
self._link = self._session.create_sender_link(
target_address=self.target,
Expand Down Expand Up @@ -635,7 +633,7 @@ class ReceiveClientAsync(ReceiveClientSync, AMQPClientAsync):
:paramtype channel_max: int
:keyword idle_timeout: Timeout in seconds after which the Connection will close
if there is no further activity.
:paramtype idle_timeout: Optional[float]
:paramtype idle_timeout: int
:keyword auth_timeout: Timeout in seconds for CBS authentication. Otherwise this value will be ignored.
Default value is 60s.
:paramtype auth_timeout: int
Expand Down Expand Up @@ -708,7 +706,6 @@ async def _client_ready_async(self):
:return: Whether the client is ready to start receiving messages.
:rtype: bool
"""
# pylint: disable=protected-access
if not self._link:
self._link = self._session.create_receiver_link(
source_address=self.source,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class Connection: # pylint:disable=too-many-instance-attributes
and 1 for transport type AmqpOverWebsocket.
"""

def __init__( # pylint:disable=too-many-locals,too-many-statements
def __init__( # pylint:disable=too-many-locals
self,
endpoint: str,
*,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async def execute(self, message, operation=None, operation_type=None, timeout: f

if self._mgmt_error:
self._responses.pop(operation_id)
raise self._mgmt_error # pylint: disable=raising-bad-type
raise self._mgmt_error

response = self._responses.pop(operation_id)
return response
Expand All @@ -105,7 +105,7 @@ async def open(self):

async def ready(self):
try:
raise self._mgmt_error # pylint: disable=raising-bad-type
raise self._mgmt_error
except TypeError:
pass

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def start(self):
return b""


class SASLTransportMixinAsync: # pylint: disable=no-member
class SASLTransportMixinAsync:
async def _negotiate(self):
await self.write(SASL_HEADER_FRAME)
_, returned_header = await self.receive_frame()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ------------------------------------------------------------------------- # pylint: disable=file-needs-copyright-header
# ------------------------------------------------------------------------- # pylint: disable=file-needs-copyright-header,useless-suppression
# This is a fork of the transport.py which was originally written by Barry Pederson and
# maintained by the Celery project: https://github.com/celery/py-amqp.
#
Expand Down Expand Up @@ -217,7 +217,7 @@ def __init__(
socket_settings=None,
raise_on_initial_eintr=True,
use_tls: bool = True,
**kwargs, # pylint: disable=unused-argument
**kwargs,
):
self.connected = False
self.sock = None
Expand Down
10 changes: 4 additions & 6 deletions sdk/eventhub/azure-eventhub/azure/eventhub/_pyamqp/client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ------------------------------------------------------------------------- # pylint: disable=client-suffix-needed
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
Expand Down Expand Up @@ -88,7 +88,7 @@ class AMQPClient(object): # pylint: disable=too-many-instance-attributes
:paramtype channel_max: int
:keyword idle_timeout: Timeout in seconds after which the Connection will close
if there is no further activity.
:paramtype idle_timeout: Optional[float]
:paramtype idle_timeout: int
:keyword auth_timeout: Timeout in seconds for CBS authentication. Otherwise this value will be ignored.
Default value is 60s.
:paramtype auth_timeout: int
Expand Down Expand Up @@ -510,7 +510,7 @@ class SendClient(AMQPClient):
:paramtype channel_max: int
:keyword idle_timeout: Timeout in seconds after which the Connection will close
if there is no further activity.
:paramtype idle_timeout: Optional[float]
:paramtype idle_timeout: int
:keyword auth_timeout: Timeout in seconds for CBS authentication. Otherwise this value will be ignored.
Default value is 60s.
:paramtype auth_timeout: int
Expand Down Expand Up @@ -590,7 +590,6 @@ def _client_ready(self):
:return: Whether the client is ready to start receiving messages.
:rtype: bool
"""
# pylint: disable=protected-access
if not self._link:
self._link = self._session.create_sender_link(
target_address=self.target,
Expand Down Expand Up @@ -736,7 +735,7 @@ class ReceiveClient(AMQPClient): # pylint:disable=too-many-instance-attributes
:paramtype channel_max: int
:keyword idle_timeout: Timeout in seconds after which the Connection will close
if there is no further activity.
:paramtype idle_timeout: Optional[float]
:paramtype idle_timeout: int
:keyword auth_timeout: Timeout in seconds for CBS authentication. Otherwise this value will be ignored.
Default value is 60s.
:paramtype auth_timeout: int
Expand Down Expand Up @@ -826,7 +825,6 @@ def _client_ready(self):
:return: True if the client is ready to start receiving messages.
:rtype: bool
"""
# pylint: disable=protected-access
if not self._link:
self._link = self._session.create_receiver_link(
source_address=self.source,
Expand Down
Loading

0 comments on commit 8f4fff6

Please sign in to comment.