Skip to content

Commit aa0f563

Browse files
authored
[EventHubs] Fix pylint and mypy (Azure#21939)
* fix pylint * fix credential mypy * one more place * more lint
1 parent 7e7fb30 commit aa0f563

File tree

7 files changed

+20
-18
lines changed

7 files changed

+20
-18
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242

4343
_LOGGER = logging.getLogger(__name__)
4444
_Address = collections.namedtuple("Address", "hostname path")
45-
_AccessToken = collections.namedtuple("AccessToken", "token expires_on")
4645

4746

4847
def _parse_conn_str(conn_str, **kwargs):
@@ -127,8 +126,8 @@ def _parse_conn_str(conn_str, **kwargs):
127126

128127

129128
def _generate_sas_token(uri, policy, key, expiry=None):
130-
# type: (str, str, str, Optional[timedelta]) -> _AccessToken
131-
"""Create a shared access signiture token as a string literal.
129+
# type: (str, str, str, Optional[timedelta]) -> AccessToken
130+
"""Create a shared access signature token as a string literal.
132131
:returns: SAS token as string literal.
133132
:rtype: str
134133
"""
@@ -141,7 +140,7 @@ def _generate_sas_token(uri, policy, key, expiry=None):
141140
encoded_key = key.encode("utf-8")
142141

143142
token = utils.create_sas_token(encoded_policy, encoded_key, encoded_uri, expiry)
144-
return _AccessToken(token=token, expires_on=abs_expiry)
143+
return AccessToken(token=token, expires_on=abs_expiry)
145144

146145

147146
def _build_uri(address, entity):
@@ -169,11 +168,12 @@ def __init__(self, policy, key):
169168
self.token_type = b"servicebus.windows.net:sastoken"
170169

171170
def get_token(self, *scopes, **kwargs): # pylint:disable=unused-argument
172-
# type: (str, Any) -> _AccessToken
171+
# type: (str, Any) -> AccessToken
173172
if not scopes:
174173
raise ValueError("No token scope provided.")
175174
return _generate_sas_token(scopes[0], self.policy, self.key)
176175

176+
177177
class EventhubAzureNamedKeyTokenCredential(object):
178178
"""The named key credential used for authentication.
179179
@@ -187,7 +187,7 @@ def __init__(self, azure_named_key_credential):
187187
self.token_type = b"servicebus.windows.net:sastoken"
188188

189189
def get_token(self, *scopes, **kwargs): # pylint:disable=unused-argument
190-
# type: (str, Any) -> _AccessToken
190+
# type: (str, Any) -> AccessToken
191191
if not scopes:
192192
raise ValueError("No token scope provided.")
193193
name, key = self._credential.named_key
@@ -217,6 +217,7 @@ def get_token(self, *scopes, **kwargs): # pylint:disable=unused-argument
217217
"""
218218
return AccessToken(self.token, self.expiry)
219219

220+
220221
class EventhubAzureSasTokenCredential(object):
221222
"""The shared access token credential used for authentication
222223
when AzureSasCredential is provided.
@@ -350,6 +351,7 @@ def _backoff(
350351

351352
def _management_request(self, mgmt_msg, op_type):
352353
# type: (Message, bytes) -> Any
354+
# pylint:disable=assignment-from-none
353355
retried_times = 0
354356
last_exception = None
355357
while retried_times <= self._config.max_retries:
@@ -360,7 +362,7 @@ def _management_request(self, mgmt_msg, op_type):
360362
try:
361363
conn = self._conn_manager.get_connection(
362364
self._address.hostname, mgmt_auth
363-
) # pylint:disable=assignment-from-none
365+
)
364366
mgmt_client.open(connection=conn)
365367
mgmt_msg.application_properties["security_token"] = mgmt_auth.token
366368
response = mgmt_client.mgmt_request(

sdk/eventhub/azure-eventhub/azure/eventhub/_common.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def __init__(self, body=None):
108108
# Internal usage only for transforming AmqpAnnotatedMessage to outgoing EventData
109109
self._raw_amqp_message = AmqpAnnotatedMessage( # type: ignore
110110
data_body=body, annotations={}, application_properties={}
111-
)
111+
)
112112
self.message = (self._raw_amqp_message._message) # pylint:disable=protected-access
113113
self._raw_amqp_message.header = AmqpMessageHeader()
114114
self._raw_amqp_message.properties = AmqpMessageProperties()
@@ -171,6 +171,7 @@ def __str__(self):
171171
@classmethod
172172
def _from_message(cls, message, raw_amqp_message=None):
173173
# type: (Message, Optional[AmqpAnnotatedMessage]) -> EventData
174+
# pylint:disable=protected-access
174175
"""Internal use only.
175176
176177
Creates an EventData object from a raw uamqp message and, if provided, AmqpAnnotatedMessage.

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
# --------------------------------------------------------------------------------------------
55

66
from typing import TYPE_CHECKING
7-
from threading import Lock
8-
from enum import Enum
97

10-
from uamqp import Connection, TransportType, c_uamqp
8+
from uamqp import Connection
119

1210
if TYPE_CHECKING:
1311
from uamqp.authentication import JWTTokenAuth

sdk/eventhub/azure-eventhub/azure/eventhub/_utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,10 @@ def trace_message(event, parent_span=None):
172172

173173

174174
def get_event_links(events):
175+
# pylint:disable=isinstance-second-argument-not-valid-type
175176
trace_events = (
176177
events if isinstance(events, Iterable) else (events,)
177-
) # pylint:disable=isinstance-second-argument-not-valid-type
178+
)
178179
links = []
179180
try:
180181
for event in trace_events: # type: ignore
@@ -296,6 +297,7 @@ def transform_outbound_single_message(message, message_type):
296297

297298
def decode_with_recurse(data, encoding="UTF-8"):
298299
# type: (Any, str) -> Any
300+
# pylint:disable=isinstance-second-argument-not-valid-type
299301
"""
300302
If data is of a compatible type, iterates through nested structure and decodes all binary
301303
strings with provided encoding.
@@ -311,7 +313,7 @@ def decode_with_recurse(data, encoding="UTF-8"):
311313
return data.decode(encoding)
312314
if isinstance(data, Mapping):
313315
decoded_mapping = {}
314-
for k,v in data.items():
316+
for k, v in data.items():
315317
decoded_key = decode_with_recurse(k, encoding)
316318
decoded_val = decode_with_recurse(v, encoding)
317319
decoded_mapping[decoded_key] = decoded_val

sdk/eventhub/azure-eventhub/azure/eventhub/aio/_async_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#--------------------------------------------------------------------------
66

77
import sys
8-
import asyncio
8+
99

1010
def get_dict_with_loop_if_needed(loop):
1111
if sys.version_info >= (3, 10):

sdk/eventhub/azure-eventhub/azure/eventhub/aio/_client_base_async.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def __init__(self, policy: str, key: str):
5757
self.key = key
5858
self.token_type = b"servicebus.windows.net:sastoken"
5959

60-
async def get_token(self, *scopes, **kwargs): # pylint:disable=unused-argument
60+
async def get_token(self, *scopes, **kwargs) -> AccessToken: # pylint:disable=unused-argument
6161
if not scopes:
6262
raise ValueError("No token scope provided.")
6363
return _generate_sas_token(scopes[0], self.policy, self.key)
@@ -84,6 +84,7 @@ async def get_token(self, *scopes: str, **kwargs: Any) -> AccessToken: # pylint
8484
"""
8585
return AccessToken(self.token, self.expiry)
8686

87+
8788
class EventhubAzureNamedKeyTokenCredentialAsync(object):
8889
"""The named key credential used for authentication.
8990
@@ -96,7 +97,7 @@ def __init__(self, azure_named_key_credential):
9697
self._credential = azure_named_key_credential
9798
self.token_type = b"servicebus.windows.net:sastoken"
9899

99-
async def get_token(self, *scopes, **kwargs): # pylint:disable=unused-argument
100+
async def get_token(self, *scopes, **kwargs) -> AccessToken: # pylint:disable=unused-argument
100101
if not scopes:
101102
raise ValueError("No token scope provided.")
102103
name, key = self._credential.named_key

sdk/eventhub/azure-eventhub/azure/eventhub/aio/_connection_manager_async.py

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

66
from typing import TYPE_CHECKING
7-
from asyncio import Lock
87

9-
from uamqp import TransportType, c_uamqp
108
from uamqp.async_ops import ConnectionAsync
119

1210
if TYPE_CHECKING:

0 commit comments

Comments
 (0)