Skip to content

Commit 7f3fcc1

Browse files
authored
[EH] EH Pylint-Next Cleanup (#35347)
* remove unused import * removed typing import from TYPE_CHECKING * add return type and returns to docstrings * remove unnecessary parens * add timeout to flush methods in producer * disable inconsistent return rule * add timeout kwarg to public api * add update_token to create_token * update mgmt_request operation kwargs * add typed kwargs for send* * typed kwargs for create_batch * update receive batch kwargs * kwargs for mgmt exec op * typed kwargs for receieve * add typed kwargs for sync consumer client * consumer from conn str kwargs * producer conn str kwargs * kwargs for send client in transports * receive client kwargs * typed kwargs for create_connection * fix error in event processor * make locales optional * fix type in field name * make max_batch_size position * pass in timeout kwarg * address PR comments * missing comma * fix uamqp transport * add final new line * fix missing comma * initial mypy fixes * match up conn manager with amqp.create_connection * intial mypy fixes for transports * futher mypy match up conn manager and transport * fix eventprocessor mypy errors * further fixes to align typing * more mypy fixes * address comments * add forward ref types for uamqp and azure amqp * enable uamqp tests for ci run * disable uAMQP tests
1 parent 75139d2 commit 7f3fcc1

25 files changed

+1198
-429
lines changed

sdk/eventhub/azure-eventhub/azure/eventhub/_client_base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ def _backoff(
401401
)
402402
raise last_exception
403403

404-
def _management_request(
404+
def _management_request(# pylint:disable=inconsistent-return-statements
405405
self, mgmt_msg: Union[uamqp_Message, Message], op_type: bytes
406406
) -> Any:
407407
# pylint:disable=assignment-from-none
@@ -414,7 +414,7 @@ def _management_request(
414414
)
415415
try:
416416
conn = self._conn_manager.get_connection( # pylint:disable=assignment-from-none
417-
host=self._address.hostname, auth=mgmt_auth
417+
endpoint=self._address.hostname, auth=mgmt_auth
418418
)
419419
mgmt_client.open(connection=conn)
420420
while not mgmt_client.client_ready():
@@ -556,7 +556,7 @@ def _open(self) -> bool:
556556
auth = self._client._create_auth()
557557
self._create_handler(auth)
558558
conn = self._client._conn_manager.get_connection( # pylint: disable=protected-access
559-
host=self._client._address.hostname, auth=auth
559+
endpoint=self._client._address.hostname, auth=auth
560560
)
561561
self._handler.open(connection=conn)
562562
while not self._handler.client_ready():
@@ -584,7 +584,7 @@ def _handle_exception(self, exception, *, is_consumer=False):
584584
exception, self, is_consumer=is_consumer
585585
)
586586

587-
def _do_retryable_operation(self, operation, timeout=None, **kwargs):
587+
def _do_retryable_operation(self, operation, timeout=None, **kwargs): # pylint:disable=inconsistent-return-statements
588588
# pylint:disable=protected-access
589589
timeout_time = (time.time() + timeout) if timeout else None
590590
retried_times = 0

sdk/eventhub/azure-eventhub/azure/eventhub/_connection_manager.py

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# --------------------------------------------------------------------------------------------
55

66
from __future__ import annotations
7-
from typing import TYPE_CHECKING, Optional, Union, Any
7+
from typing import TYPE_CHECKING, Dict, Optional, Union, Any
88
from threading import Lock
99
from enum import Enum
1010

@@ -30,9 +30,8 @@ class ConnectionManager(Protocol):
3030
def get_connection(
3131
self,
3232
*,
33-
host: Optional[str] = None,
33+
endpoint: str,
3434
auth: Optional[Union[JWTTokenAuth, uamqp_JWTTokenAuth]] = None,
35-
endpoint: Optional[str] = None,
3635
) -> Union[Connection, uamqp_Connection]:
3736
pass
3837

@@ -49,37 +48,52 @@ class _ConnectionMode(Enum):
4948

5049

5150
class _SharedConnectionManager: # pylint:disable=too-many-instance-attributes
52-
def __init__(self, **kwargs: Any):
51+
def __init__( #pylint:disable=unused-argument
52+
self,
53+
*,
54+
container_id: Optional[str] = None,
55+
custom_endpoint_address: Optional[str] = None,
56+
debug: bool = False,
57+
error_policy: Optional[Any] = None,
58+
properties: Optional[Dict[str, Any]] = None,
59+
encoding: str = "UTF-8",
60+
transport_type: TransportType = TransportType.Amqp,
61+
http_proxy: Optional[str] = None,
62+
max_frame_size: int,
63+
channel_max: int,
64+
idle_timeout: float,
65+
remote_idle_timeout_empty_frame_send_ratio: float,
66+
amqp_transport: AmqpTransport,
67+
**kwargs: Any
68+
):
5369
self._lock = Lock()
5470
self._conn: Union[Connection, uamqp_Connection] = None
5571

56-
self._container_id = kwargs.get("container_id")
57-
self._custom_endpoint_address = kwargs.get("custom_endpoint_address")
58-
self._debug = kwargs.get("debug")
59-
self._error_policy = kwargs.get("error_policy")
60-
self._properties = kwargs.get("properties")
61-
self._encoding = kwargs.get("encoding") or "UTF-8"
62-
self._transport_type = kwargs.get("transport_type") or TransportType.Amqp
63-
self._http_proxy = kwargs.get("http_proxy")
64-
self._max_frame_size = kwargs.get("max_frame_size")
65-
self._channel_max = kwargs.get("channel_max")
66-
self._idle_timeout = kwargs.get("idle_timeout")
67-
self._remote_idle_timeout_empty_frame_send_ratio = kwargs.get("remote_idle_timeout_empty_frame_send_ratio")
68-
self._amqp_transport: AmqpTransport = kwargs.pop("amqp_transport")
72+
self._container_id = container_id
73+
self._custom_endpoint_address = custom_endpoint_address
74+
self._debug = debug
75+
self._error_policy = error_policy
76+
self._properties = properties
77+
self._encoding = encoding
78+
self._transport_type = transport_type
79+
self._http_proxy = http_proxy
80+
self._max_frame_size = max_frame_size
81+
self._channel_max = channel_max
82+
self._idle_timeout = idle_timeout
83+
self._remote_idle_timeout_empty_frame_send_ratio = remote_idle_timeout_empty_frame_send_ratio
84+
self._amqp_transport: AmqpTransport = amqp_transport
6985

7086
def get_connection(
7187
self,
7288
*,
73-
host: Optional[str] = None,
89+
endpoint: str,
7490
auth: Optional[Union[JWTTokenAuth, uamqp_JWTTokenAuth]] = None,
75-
endpoint: Optional[str] = None,
7691
) -> Union[Connection, uamqp_Connection]:
7792
with self._lock:
7893
if self._conn is None:
7994
self._conn = self._amqp_transport.create_connection(
80-
host=host,
81-
auth=auth,
8295
endpoint=endpoint,
96+
auth=auth,
8397
custom_endpoint_address=self._custom_endpoint_address,
8498
container_id=self._container_id,
8599
max_frame_size=self._max_frame_size,
@@ -113,9 +127,8 @@ def __init__(self, **kwargs):
113127
def get_connection( # pylint:disable=unused-argument
114128
self,
115129
*,
116-
host: Optional[str] = None,
130+
endpoint: str,
117131
auth: Optional[Union[JWTTokenAuth, uamqp_JWTTokenAuth]] = None,
118-
endpoint: Optional[str] = None,
119132
) -> None:
120133
return None
121134

sdk/eventhub/azure-eventhub/azure/eventhub/_consumer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def _create_handler(self, auth: Union[uamqp_JWTTokenAuth, JWTTokenAuth]) -> None
159159
auth=auth,
160160
network_trace=self._client._config.network_tracing, # pylint:disable=protected-access
161161
link_credit=self._prefetch,
162-
link_properties=self._link_properties,
162+
link_properties=self._link_properties, # type: ignore
163163
timeout=self._timeout,
164164
idle_timeout=self._idle_timeout,
165165
retry_policy=self._retry_policy,
@@ -203,7 +203,7 @@ def _open(self) -> bool:
203203
auth = self._client._create_auth()
204204
self._create_handler(auth)
205205
conn = self._client._conn_manager.get_connection( # pylint: disable=protected-access
206-
host=self._client._address.hostname, auth=auth
206+
endpoint=self._client._address.hostname, auth=auth
207207
)
208208
self._handler = cast("ReceiveClient", self._handler)
209209
self._handler.open(connection=conn)

0 commit comments

Comments
 (0)