Skip to content

Commit e647df7

Browse files
Cycle 11: apply ruff --fix; contextlib.suppress in do_ping cleanup
Ruff newly running on this package (since run-tests.sh now lints everything) surfaced import ordering and a single SIM105 on the do_ping cursor.close() cleanup. Applied autofixes + manual rewrite to contextlib.suppress. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 60b7ed1 commit e647df7

4 files changed

Lines changed: 13 additions & 17 deletions

File tree

src/sqlalchemydqlite/base.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
"""Base dqlite dialect for SQLAlchemy."""
22

3+
import contextlib
34
import datetime
45
import warnings
56
from typing import Any
67

7-
import dqliteclient.exceptions as _client_exc
8-
import dqlitedbapi.exceptions as _dbapi_exc
98
from sqlalchemy import types as sqltypes
109
from sqlalchemy.dialects.sqlite.base import SQLiteDialect
1110
from sqlalchemy.engine import URL
1211
from sqlalchemy.engine.interfaces import DBAPIConnection, IsolationLevel
1312
from sqlalchemy.exc import ArgumentError
1413

14+
import dqliteclient.exceptions as _client_exc
15+
import dqlitedbapi.exceptions as _dbapi_exc
16+
1517

1618
class _DqliteDateTime(sqltypes.DateTime):
1719
"""Passthrough DateTime — ``dqlitedbapi`` already returns ``datetime.datetime``
@@ -35,9 +37,7 @@ class _DqliteDate(sqltypes.Date):
3537
def bind_processor(self, dialect: Any) -> None:
3638
return None
3739

38-
def result_processor(
39-
self, dialect: Any, coltype: Any
40-
) -> Any:
40+
def result_processor(self, dialect: Any, coltype: Any) -> Any:
4141
def process(value: Any) -> Any:
4242
if isinstance(value, datetime.datetime):
4343
return value.date()
@@ -143,8 +143,7 @@ def set_isolation_level(self, dbapi_connection: DBAPIConnection, level: str | No
143143
"Use explicit commit() / rollback() on the connection."
144144
)
145145
warnings.warn(
146-
f"dqlite only supports SERIALIZABLE isolation. "
147-
f"Requested level {level!r} is ignored.",
146+
f"dqlite only supports SERIALIZABLE isolation. Requested level {level!r} is ignored.",
148147
stacklevel=2,
149148
)
150149

@@ -219,10 +218,8 @@ def do_ping(self, dbapi_connection: Any) -> bool:
219218
):
220219
return False
221220
finally:
222-
try:
223-
cursor.close()
224-
except Exception:
225-
pass # cursor close shouldn't crash the ping result
221+
with contextlib.suppress(Exception):
222+
cursor.close() # cursor close shouldn't crash the ping result
226223

227224
def _get_server_version_info(self, connection: Any) -> tuple[int, ...]:
228225
"""Return the server version as a tuple.

tests/integration/test_time_and_reflection.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ def test_reflect_round_trip(self, engine_url: str) -> None:
116116

117117
fks = insp.get_foreign_keys("books")
118118
assert any(
119-
fk["referred_table"] == "authors"
120-
and fk["constrained_columns"] == ["author_id"]
119+
fk["referred_table"] == "authors" and fk["constrained_columns"] == ["author_id"]
121120
for fk in fks
122121
)
123122
finally:

tests/test_dialect.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,8 @@ def test_ping_returns_false_on_connection_error(self) -> None:
313313

314314
dialect = DqliteDialect()
315315
mock_conn = MagicMock()
316-
mock_conn.cursor.return_value.execute.side_effect = (
317-
dqlitedbapi.exceptions.OperationalError("bye")
316+
mock_conn.cursor.return_value.execute.side_effect = dqlitedbapi.exceptions.OperationalError(
317+
"bye"
318318
)
319319
assert dialect.do_ping(mock_conn) is False
320320

tests/test_dialect_dialect_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111

1212
from unittest.mock import MagicMock
1313

14-
import dqliteclient.exceptions
15-
import dqlitedbapi.exceptions
1614
import pytest
1715
from sqlalchemy.engine import make_url
1816
from sqlalchemy.exc import ArgumentError
1917

18+
import dqliteclient.exceptions
19+
import dqlitedbapi.exceptions
2020
from sqlalchemydqlite.base import DqliteDialect
2121

2222

0 commit comments

Comments
 (0)