Skip to content

Commit 18f7042

Browse files
committed
chore: fix static check errors
1 parent a33ba33 commit 18f7042

File tree

3 files changed

+21
-19
lines changed

3 files changed

+21
-19
lines changed

aws_advanced_python_wrapper/aurora_connection_tracker_plugin.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
if TYPE_CHECKING:
2828
from aws_advanced_python_wrapper.driver_dialect import DriverDialect
2929
from aws_advanced_python_wrapper.plugin_service import PluginService
30+
from aws_advanced_python_wrapper.hostinfo import HostInfo
3031
from aws_advanced_python_wrapper.pep249 import Connection
3132

3233
from aws_advanced_python_wrapper.utils.rds_url_type import RdsUrlType
@@ -35,7 +36,6 @@
3536
from _weakrefset import WeakSet
3637

3738
from aws_advanced_python_wrapper.errors import FailoverError
38-
from aws_advanced_python_wrapper.hostinfo import HostInfo, HostRole
3939
from aws_advanced_python_wrapper.pep249_methods import DbApiMethod
4040
from aws_advanced_python_wrapper.plugin import Plugin, PluginFactory
4141
from aws_advanced_python_wrapper.utils.log import Logger
@@ -83,10 +83,10 @@ def _prune_connections(cls):
8383
to_remove.append(conn)
8484
except Exception:
8585
pass
86-
86+
8787
for conn in to_remove:
8888
conn_set.discard(conn)
89-
89+
9090
# Remove empty connection sets
9191
if not conn_set:
9292
del cls._opened_connections[host]
@@ -105,8 +105,8 @@ def populate_opened_connection_set(self, host_info: HostInfo, conn: Connection):
105105
self._track_connection(host_info.as_alias(), conn)
106106
return
107107

108-
instance_endpoint: Optional[str] = next((alias for alias in aliases if self._rds_utils.is_rds_instance(self._rds_utils.remove_port(alias))),
109-
None)
108+
instance_endpoint: Optional[str] = next(
109+
(alias for alias in aliases if self._rds_utils.is_rds_instance(self._rds_utils.remove_port(alias))), None)
110110
if not instance_endpoint:
111111
logger.debug("OpenedConnectionTracker.UnableToPopulateOpenedConnectionSet")
112112
return
@@ -143,12 +143,15 @@ def invalidate_all_connections(self, host_info: Optional[HostInfo] = None, host:
143143
self._log_connection_set(instance_endpoint, connection_set)
144144
self._invalidate_connections(connection_set)
145145

146-
def remove_connection_tracking(self, host_info: HostInfo, connection: Connection):
146+
def remove_connection_tracking(self, host_info: HostInfo, connection: Connection | None):
147+
if not connection:
148+
return
149+
147150
if self._rds_utils.is_rds_instance(host_info.host):
148151
host = host_info.as_alias()
149152
else:
150153
host = next((alias for alias in host_info.as_aliases()
151-
if self._rds_utils.is_rds_instance(self._rds_utils.remove_port(alias))), None)
154+
if self._rds_utils.is_rds_instance(self._rds_utils.remove_port(alias))), "")
152155

153156
if not host:
154157
return
@@ -168,7 +171,7 @@ def _task(connection_set: WeakSet):
168171
while connection_set is not None:
169172
try:
170173
conn_reference = connection_set.pop()
171-
except KeyError as e:
174+
except KeyError:
172175
# connection_set is empty
173176
# use KeyError instead of len() to determine whether connection_set is empty to prevent data race
174177
break
@@ -182,7 +185,6 @@ def _task(connection_set: WeakSet):
182185
# Swallow this exception, current connection should be useless anyway
183186
pass
184187

185-
186188
def _invalidate_connections(self, connection_set: WeakSet):
187189
invalidate_connection_thread: Thread = Thread(daemon=True, target=self._task,
188190
args=[connection_set]) # type: ignore
@@ -286,7 +288,8 @@ def execute(self, target: object, method_name: str, execute_func: Callable, *arg
286288

287289
except Exception as e:
288290
if isinstance(e, FailoverError):
289-
AuroraConnectionTrackerPlugin._host_list_refresh_end_time_nano = perf_counter_ns() + AuroraConnectionTrackerPlugin._TOPOLOGY_CHANGES_EXPECTED_TIME_NANO
291+
AuroraConnectionTrackerPlugin._host_list_refresh_end_time_nano = (
292+
perf_counter_ns() + AuroraConnectionTrackerPlugin._TOPOLOGY_CHANGES_EXPECTED_TIME_NANO)
290293
# Calling this method may effectively close/abort a current connection
291294
self._check_writer_changed(True)
292295
raise

aws_advanced_python_wrapper/fastest_response_strategy_plugin.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import time
1818
from copy import copy
1919
from dataclasses import dataclass
20-
from datetime import datetime
2120
from threading import Event, Lock, Thread
2221
from time import sleep
2322
from typing import (TYPE_CHECKING, Callable, ClassVar, Dict, List, Optional,

tests/unit/test_aurora_connection_tracker.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def mock_cursor(mocker):
4040
return mocker.MagicMock()
4141

4242

43-
@pytest.fixturey
43+
@pytest.fixture
4444
def mock_plugin_service(mocker):
4545
return mocker.MagicMock()
4646

@@ -116,12 +116,12 @@ def test_prune_connections_logs_none_connection(mocker, caplog):
116116
mock_conn_set.__iter__ = mocker.MagicMock(return_value=iter([None]))
117117
mock_conn_set.__len__ = mocker.MagicMock(return_value=1)
118118
mock_conn_set.discard = mocker.MagicMock()
119-
119+
120120
OpenedConnectionTracker._opened_connections = {"test-host": mock_conn_set}
121-
121+
122122
with caplog.at_level("DEBUG"):
123123
tracker._prune_connections()
124-
124+
125125
mock_conn_set.discard.assert_called_with(None)
126126

127127

@@ -131,16 +131,16 @@ def test_prune_connections_logs_closed_connection(mocker, caplog):
131131
mock_conn = mocker.MagicMock()
132132
mock_conn.__module__ = "psycopg"
133133
mock_conn.is_closed.return_value = True
134-
134+
135135
mock_conn_set = mocker.MagicMock(spec=WeakSet)
136136
mock_conn_set.__iter__ = mocker.MagicMock(return_value=iter([mock_conn]))
137137
mock_conn_set.__len__ = mocker.MagicMock(return_value=1)
138138
mock_conn_set.discard = mocker.MagicMock()
139-
139+
140140
tracker = OpenedConnectionTracker()
141141
OpenedConnectionTracker._opened_connections = {"test-host": mock_conn_set}
142-
142+
143143
with caplog.at_level("DEBUG"):
144144
tracker._prune_connections()
145-
145+
146146
mock_conn_set.discard.assert_called_with(mock_conn)

0 commit comments

Comments
 (0)