code-quality-python
Skill345 starsChanged 35 days agoApache-2.0View on GitHub
Use when writing or reviewing Python in this repo's tooling (sink-connector/python — db_compare, ch_sink_tools, mysql_resync and friends), or when asked for "worldclass"/"idiomatic" Python. Covers type hints, error handling, the Ruff/Black/mypy toolchain, and a deep review checklist for the defect classes that matter in operational CLI tools.
In this repository17 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- clickhouse-sink-reviewSkill
- code-quality-architectureSkill
- code-quality-bashSkill
- code-quality-goSkill
- code-quality-jvmSkill
- code-quality-sqlSkill
- code-reuse-firstSkill
- code-reuse-reviewSkill
- design-note-debtSkill
- destructive-operation-safetySkill
- mandatory-code-change-validationSkill
- pr-self-reviewSkill
- repro-harness-negative-proofSkill
- sink-connector-mysql-source-of-truthSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 28
Type hints on every public function signature: Run mypy (or the project's configured type checker) in CI.
- Very specific: line 74
Run this over every changed .py file during pr-self-review's per-language pass.
- Very specific: line 101
Prefer pytest with fixtures over ad hoc setup/teardown.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Worldclass Python
Overview
Idiomatic, typed Python for this project's tooling under
sink-connector/python — comparison/verification tools (db_compare),
the ch_sink_tools package, and operational scripts such as
mysql_resync.py. These tools are run by operators against production
data, so correctness and loud failure matter more than cleverness.
When to Use
- Writing or reviewing any
.pyfile undersink-connector/python - A user asks for "worldclass / idiomatic" Python
- Reviewing a CLI tool, comparison script, or data-repair utility for correctness and failure handling
Core Rules
- Type hints on every public function signature. Run mypy (or the project's configured type checker) in CI; untyped internals are tolerable, untyped public APIs are not.
dataclasses(orattrs) for structured data, not loose dicts passed around and mutated in place.- Explicit over implicit — no bare
except:; catch the specific exception type you can actually handle, and let everything else propagate loudly. - Context managers for resources — DB connections, file handles,
anything with a lifecycle —
withblocks, not manual open/close pairs. - f-strings for formatting; no
%-formatting or.format()in new code. pathlib.Pathover string path manipulation.- Argument parsing via
argparse/click, with--dry-runas a first-class, well-tested mode for anything that mutates data — this matters especially for destructive/repair tooling (seedestructive-operation-safety). - Logging, not
print(), for anything beyond a CLI's final summary output; structured, leveled, and loud on failure (never swallow an exception and continue silently — see Invariant I9, Loud Failure).
# BAD
try:
result = compare_tables(a, b)
except:
print("something went wrong")
# GOOD
try:
result = compare_tables(a, b)
except TableComparisonError:
logger.exception("comparison failed for %s vs %s", a, b)
raiseRuff Rule Sets
A reasonable baseline Ruff configuration for this kind of operational
tooling selects at least: E/F (pyflakes/pycodestyle core), B
(bugbear — catches common real bugs like mutable default arguments), UP
(pyupgrade — keep syntax current), SIM (simplify), and C90
(complexity). Run ruff format for formatting and ruff check --fix for
the rest; wire both into CI rather than relying on local habit.
Deep Review Checklist (Python)
Run this over every changed .py file during pr-self-review's
per-language pass.
- Mutable default arguments (
def f(x, items=[])) — the classic shared-state bug; default toNoneand assign inside the function. - Bare or overly broad
exceptclauses that hide the real error or swallow aKeyboardInterrupt/SystemExit. - Resource leaks — file handles, DB connections, or cursors opened
without a
withblock, especially on an error path. - Off-by-one and boundary handling in anything doing comparison batching, pagination, or chunked reads of a replicated table.
- Silent coercion — comparing or hashing values across types without
checking that
NULL/Noneis handled the same way the source database handles it; a comparison tool that treatsNULLand empty string as equal can hide a real divergence. - Dry-run vs apply divergence — for any tool with both modes
(
mysql_resync.pyand similar), does the dry-run path actually execute the same logic as the apply path up to the point of mutation, or is it a separate, driftable code path that can silently stop matching reality? - Unbounded work — a scan or comparison over an entire table with no batching/limit, especially relevant given Invariant I14 (Bounded Bookkeeping) for anything touching replicated or target-table data.
- Hardcoded version-dependent assumptions — a check that assumes one MySQL/ClickHouse version's behavior without verifying it still holds on others the tool is expected to support.
Testing
Prefer pytest with fixtures over ad hoc setup/teardown. Every bug fix in
this tooling should add a test that fails without the fix — a test that
only re-asserts current behavior proves nothing. For comparison/repair
tools, test both the dry-run and apply code paths explicitly, not just one.
Anti-Patterns
Bare except: · mutable default arguments · print() for anything beyond
final CLI output · swallowing exceptions in repair/comparison tooling ·
untyped public function signatures · a dry-run mode that is a separate,
unverified code path from the real one.
Sources
PEP 8 / PEP 484 (typing) · Ruff and mypy documentation · general Python anti-pattern references (mutable defaults, broad excepts).
Cross-References
pr-self-review, code-quality-architecture, destructive-operation-safety,
sink-connector-mysql-source-of-truth.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

