Repository navigation
Description
Follow up of #391
#679 Introduced Ruff with a good amount of rules to check, but that list can be improved so more things get checked/validated. Adding a list sorted by how impactful would be the changes:
-
RUF(Ruff-specific) — 10 violations. The highest-value item on the list: RUF012 flags mutable class defaults indbt/adapters/clickhouse/column.py:13andimpl.py:68— class-level dicts shared across all instances, a real shared-state bug class. Also cleans up 6 stale# noqacomments (auto-fixable) and 2 unused unpacked variables in tests. -
DTZ(flake8-datetimez) — 3 violations. Flags naivedatetimecalls, e.g.datetime.now()withouttzintest_clickhouse_table_ttl.py:63. Timestamps compared against ClickHouse server time can silently diverge when the CI machine's timezone differs — the classic cause of flaky TTL tests. Tiny fix, real failure mode. -
PGH(pygrep-hooks) — 6 violations. All blanket# noqacomments without rule codes (in__init__.py,dbclient.py). A bare# noqasuppresses every future rule on that line, so bugs introduced there later go unseen. Cheap fix, prevents future blind spots. -
RET(flake8-return) — 8 violations. One substantive catch: RET503 atimpl.py:119, a function that returns a value on some paths but implicitly returnsNoneon others — a potential missing-case bug. The remaining 7 are stylistic. -
C90(mccabe complexity) — 2 violations at the default threshold of 10. Restores the guardrail our old flake8 config had. At the previousmax-complexity = 18it passes with zero changes today — it purely prevents future complexity growth. -
SIM(flake8-simplify) — 11 violations. Readability: mostly SIM118 (key in dict.keys()→key in dict) inimpl.pyand tests. No bugs, but genuinely cleaner code. -
PT(flake8-pytest-style) — 13 violations. Test-suite conventions: parametrize argument types (PT007) andyieldfixtures with no teardown (PT022). Worthwhile given how test-heavy this repo is, but purely conventional. -
C4(comprehensions) — 14 violations. Unnecessary generators passed toset()and similar. Micro-performance and style only; auto-fixable with--unsafe-fixes. -
UP(pyupgrade) — 137 violations. Ranked low not because it's bad but because it's pure modernization (Optional[str]→str | None, etc.) with the largest diff. All auto-fixable. -
PERF— 3 violations. Least impact: try/except inside loops. Would likely need a# noqamore than a fix.
items 1–5 (29 violations, mostly small or auto-fixable) buy all the actual bug-catching; 6–10 are style and modernization we can adopt incrementally.
Ones I'd skip:
Sbandit, 669 hits — almost all false positives from SQL string-building, which is inherent to an adapter.PLpylint, 139 — mostly magic-number and argument-count pedantry.TRY39 — opinionated exception style that conflicts with the adapter's error-wrapping pattern.ARG69 — unused arguments that are actually required by dbt's adapter interface signatures.
Activity
humayun-1 commentedon Nov 16, 2026
Hi @koletzilla , I'd like to pick this up, starting with items 1-5 (RUF, DTZ, PGH, RET, C90) and leaving SIM, PT, C4, UP and PERF for follow-up PRs as you suggested.
Most of the fixes are mechanical: specific codes on the bare
noqas,ClassVaron the class-level lookup tables, explicit returns, and tz-aware datetimes in tests.get_clickhouse_cluster_namewould get an explicitreturn None, since several macros checkis none. With the existing E/F rules on as well it comes to 24 findings rather than 29, since most of the RUF100 hits go away.A few questions before I open the PR:
max-complexity = 18(the old flake8 value) OK? At the default 10,_check_lightweight_deletesands3source_clausewould need a refactor or anoqa.tests/, or picking specific RUF rules instead of the whole set?ClassVaronCONSTRAINT_SUPPORTdoesn't match howBaseAdapterdeclares it in dbt-adapters. mypy here doesn't follow imports so it passes, but I can use anoqawith a note instead if you prefer.It's working locally (lint clean, unit tests and the touched integration tests passing on 26.3 and 26.10), so I can open it as soon as you're happy with the choices.
koletzilla commentedon Nov 16, 2026
Hi @humayun-1, I'm not convinced by the approach you mentioned. Let's wait for other users responses on it.