Skip to content

Commit b3e83dc

Browse files
committed
ci: add bugbear to linting and fix all violations
1 parent a3d0ba9 commit b3e83dc

File tree

12 files changed

+19
-21
lines changed

12 files changed

+19
-21
lines changed

ably/http/http.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ async def make_request(self, method, path, version=None, headers=None, body=None
188188

189189
hosts = self.get_rest_hosts()
190190
for retry_count, host in enumerate(hosts):
191-
def should_stop_retrying():
191+
def should_stop_retrying(retry_count=retry_count):
192192
time_passed = time.time() - requested_at
193193
# if it's the last try or cumulative timeout is done, we stop retrying
194194
return retry_count == len(hosts) - 1 or time_passed > http_max_retry_duration

ably/realtime/connectionmanager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ async def ping(self) -> float:
125125
try:
126126
response = await self.__ping_future
127127
except asyncio.CancelledError:
128-
raise AblyException("Ping request cancelled due to request timeout", 504, 50003)
128+
raise AblyException("Ping request cancelled due to request timeout", 504, 50003) from None
129129
return response
130130

131131
self.__ping_future = asyncio.Future()
@@ -139,7 +139,7 @@ async def ping(self) -> float:
139139
try:
140140
await asyncio.wait_for(self.__ping_future, self.__timeout_in_secs)
141141
except asyncio.TimeoutError:
142-
raise AblyException("Timeout waiting for ping response", 504, 50003)
142+
raise AblyException("Timeout waiting for ping response", 504, 50003) from None
143143

144144
ping_end_time = datetime.now().timestamp()
145145
response_time_ms = (ping_end_time - ping_start_time) * 1000

ably/rest/auth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ async def request_token(self, token_params: dict | None = None,
186186
try:
187187
token_request = await auth_callback(token_params)
188188
except Exception as e:
189-
raise AblyException("auth_callback raised an exception", 401, 40170, cause=e)
189+
raise AblyException("auth_callback raised an exception", 401, 40170, cause=e) from e
190190
elif auth_url:
191191
log.debug("using token auth with authUrl")
192192

@@ -210,7 +210,7 @@ async def request_token(self, token_params: dict | None = None,
210210
except TypeError as e:
211211
msg = "Expected token request callback to call back with a token string, token request object, or \
212212
token details object"
213-
raise AblyAuthException(msg, 401, 40170, cause=e)
213+
raise AblyAuthException(msg, 401, 40170, cause=e) from e
214214
elif isinstance(token_request, str):
215215
if len(token_request) == 0:
216216
raise AblyAuthException("Token string is empty", 401, 4017)

ably/rest/rest.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ def __init__(self, key: Optional[str] = None, token: Optional[str] = None,
6161
else:
6262
options = Options(**kwargs)
6363

64-
try:
65-
self._is_realtime
66-
except AttributeError:
64+
if not hasattr(self, '_is_realtime'):
6765
self._is_realtime = False
6866

6967
self.__http = Http(self, options)

ably/transport/websockettransport.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ async def ws_connect(self, ws_url, headers):
9696
exception = AblyException(f'Error opening websocket connection: {e}', 400, 40000)
9797
log.exception(f'WebSocketTransport.ws_connect(): Error opening websocket connection: {exception}')
9898
self._emit('failed', exception)
99-
raise exception
99+
raise exception from e
100100

101101
async def _handle_websocket_connection(self, ws_url, websocket):
102102
log.info(f'ws_connect(): connection established to {ws_url}')

ably/types/authoptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def set_key(self, key):
3636
except ValueError:
3737
raise AblyException("key of not len 2 parameters: {}"
3838
.format(key.split(':')),
39-
401, 40101)
39+
401, 40101) from None
4040

4141
def replace(self, auth_options):
4242
if type(auth_options) is dict:

ably/types/mixins.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def decode(data, encoding='', cipher=None, context=None):
101101

102102
except Exception as e:
103103
log.error(f'VCDiff decode failed: {e}')
104-
raise AblyException('VCDiff decode failure', 40018, 40018)
104+
raise AblyException('VCDiff decode failure', 40018, 40018) from e
105105

106106
elif encoding.startswith(f'{CipherData.ENCODING_ID}+'):
107107
if not cipher:

ably/util/exceptions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def raise_for_response(response):
4343
response.text)
4444
raise AblyException(message=response.text,
4545
status_code=response.status_code,
46-
code=response.status_code * 100)
46+
code=response.status_code * 100) from None
4747

4848
if decoded_response and 'error' in decoded_response:
4949
error = decoded_response['error']
@@ -56,7 +56,7 @@ def raise_for_response(response):
5656
except KeyError:
5757
msg = "Unexpected exception decoding server response: %s"
5858
msg = msg % response.text
59-
raise AblyException(message=msg, status_code=500, code=50000)
59+
raise AblyException(message=msg, status_code=500, code=50000) from None
6060

6161
raise AblyException(message="",
6262
status_code=response.status_code,
@@ -91,7 +91,7 @@ async def wrapper(*args, **kwargs):
9191
return await func(*args, **kwargs)
9292
except Exception as e:
9393
log.exception(e)
94-
raise AblyException.from_exception(e)
94+
raise AblyException.from_exception(e) from e
9595

9696
return wrapper
9797

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ extend-exclude = [
8787
]
8888

8989
[tool.ruff.lint]
90-
# Enable Pyflakes (F), pycodestyle (E, W), pep8-naming (N), isort (I), and pyupgrade (UP)
91-
select = ["E", "W", "F", "N", "I", "UP"]
90+
# Enable Pyflakes (F), pycodestyle (E, W), pep8-naming (N), isort (I), pyupgrade (UP) and bugbear (B)
91+
select = ["E", "W", "F", "N", "I", "UP", "B"]
9292
ignore = [
9393
"N818", # exception name should end in 'Error'
9494
]

test/ably/rest/restchannelpublish_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ async def test_interoperability(self):
402402
response = await channel.publish(data=expected_value)
403403
assert response.status_code == 201
404404

405-
async def check_data():
405+
async def check_data(encoding=encoding, msg_data=msg_data):
406406
async with httpx.AsyncClient(http2=True) as client:
407407
r = await client.get(url, auth=auth)
408408
item = r.json()[0]
@@ -418,7 +418,7 @@ async def check_data():
418418
response = await channel.publish(messages=[Message(data=msg_data, encoding=encoding)])
419419
assert response.status_code == 201
420420

421-
async def check_history():
421+
async def check_history(expected_value=expected_value, expected_type=expected_type):
422422
history = await channel.history()
423423
message = history.items[0]
424424
return message.data == expected_value and isinstance(message.data, type_mapping[expected_type])

0 commit comments

Comments
 (0)