py-code-quality
Skill0 starsChanged 2 months agoMITView on GitHub
Guides agents in applying Pythonic idioms: dataclasses, context managers, generator expressions, and explicit exception hierarchies.
In this repository49 other files it gives its agents.
- bug-reproducerSkill
- claim-checkerSkill
- command-failure-diagnoserSkill
- config-risk-reviewerSkill
- csv-validatorSkill
- deployment-checklist-makerSkill
- diff-reviewerSkill
- factual-summarizerSkill
- field-extractorSkill
- api-contract-testerSkill
- database-migration-helperSkill
- security-vulnerability-fixerSkill
- git-commit-stagerSkill
- git-conflict-resolverSkill
- github-actions-debuggerSkill
- github-issue-triagerSkill
- github-pr-creatorSkill
- github-pr-reviewerSkill
- go-code-qualitySkill
- go-lint-and-vetSkill
- go-testingSkill
- json-schema-converterSkill
- lint-and-typecheckSkill
- meaning-preserving-editorSkill
- meeting-notes-to-actionsSkill
- minimal-bug-fixSkill
- option-comparatorSkill
- py-lint-and-typecheckSkill
- py-testingSkill
- readme-writerSkill
- regression-test-writerSkill
- release-notes-drafterSkill
- repo-inspectorSkill
- research-briefSkill
- reversible-cleanup-plannerSkill
- rust-clippy-checkSkill
- rust-code-qualitySkill
- rust-testingSkill
- small-refactorSkill
- status-updateSkill
- step-by-step-tutorialSkill
- step-decomposerSkill
- tabular-analyzerSkill
- task-briefSkill
- test-runner-debuggerSkill
- ts-code-qualitySkill
- ts-lint-and-typecheckSkill
- ts-testingSkill
- skill-templateSkill
The file
We split this skill into the rules it gives an agent
12 rules. About 0 are common, 4 are distinctive, and 8 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
8
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 14
Use this skill when:
- Very specific: line 20
Do not use for running tests.
- Very specific: line 21
Do not use to fix syntax errors.
- Very specific: line 27
If target_file is missing: ask for target file.
- Distinctive: line 28
Never introduce backwards-incompatible API breaks without user confirmation.
- Distinctive: line 31
Follow these numbered actions:
- Very specific: line 33
Check for bare except:, range(len()), and manual file close without with.
- Very specific: line 35
Use @dataclass(frozen=True) for immutable value objects.
- Very specific: line 41
Run pytest to confirm 100% behavior preservation.
- Very specific: line 44
If managing files or sockets: always use with open(...) as f:.
- Very specific: line 45
Never use mutable default arguments like def func(items=[]).
- Distinctive: line 73
Stop and ask the user when:
≈ “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
Python Code Quality & Idioms
Refactors Python code into clean, idiomatic ("Pythonic") architecture. Enforces context managers (with), dataclasses, explicit exceptions, and generator pipelines.
1. Purpose
Eliminate non-idiomatic patterns in Python (e.g. C-style index loops, raw dictionary passing, catching bare Exception).
2. When to Use
Use this skill when:
- Replacing raw dictionaries with
@dataclassorPydanticmodels. - Ensuring resource management uses
withcontext managers. - Replacing index-based loops (
for i in range(len(arr))) withenumerate()orzip().
3. When Not to Use
- Do not use for running tests; use
py-testing. - Do not use to fix syntax errors; use
py-lint-and-typecheck.
4. Required Inputs
target_file: Path to the Python file to inspect or refactor.
5. Missing-Input Behavior
- If
target_fileis missing: ask for target file. - Never introduce backwards-incompatible API breaks without user confirmation.
6. Procedure
Follow these numbered actions:
- Action 1: Audit for Anti-Patterns
- Check for bare
except:,range(len()), and manual file close withoutwith.
- Check for bare
- Action 2: Convert Raw Dicts to Dataclasses
- Use
@dataclass(frozen=True)for immutable value objects.
- Use
- Action 3: Use Context Managers
- Wrap file I/O, database sessions, and locks in
withblocks.
- Wrap file I/O, database sessions, and locks in
- Action 4: Define Domain Exceptions
- Inherit from a custom base exception (
class DomainError(Exception): pass).
- Inherit from a custom base exception (
- Action 5: Verify Tests
- Run
pytestto confirm 100% behavior preservation.
- Run
7. Decision Rules
- If managing files or sockets: always use
with open(...) as f:. - Never use mutable default arguments like
def func(items=[]); useitems: list | None = None.
8. Output Format
Emit the report using this template:
### Python Code Quality Report: [File]
- **File Modified**: `[path]`
- **Patterns Applied**: [e.g. Dataclass, Context Manager]
- **Test Status**: PASS
#### Refactoring Details
- [Pattern 1 applied with explanation]
- [Pattern 2 applied with explanation]9. Verification Checklist
- No bare
except:statements. - Mutable default arguments eliminated.
- Context managers used for I/O.
- Existing
pytestsuite passes.
10. Common Failures and Recovery
| Failure Symptom | Cause | Recovery Action |
| Mutable default bug | def add(item, lst=[]) | Change default to None and initialize inside function. |
11. Stop or Escalation Conditions
Stop and ask the user when:
- Changing dictionary structures breaks external JSON consumers.
12. Examples
Example 1: Successful Execution
Input:
File: src/export.py
Anti-pattern: f = open("data.csv"); f.write(...); f.close()Output:
### Python Code Quality Report: src/export.py
- **File Modified**: `src/export.py`
- **Patterns Applied**: Context Manager
- **Test Status**: PASS
#### Refactoring Details
- Replaced manual `open()` / `close()` with `with open("data.csv", "w", encoding="utf-8") as f:`.
- Guarantees file handle cleanup even if an exception is raised.Example 2: Ambiguous or Missing Input
Input:
Clean Python.Output:
### Python Code Quality Report: Halted - No Target File
- **Status**: Halted
Please specify the Python file to inspect.Example 3: Expected Final Output
Output:
### Python Code Quality Report: src/models.py
- **File Modified**: `src/models.py`
- **Patterns Applied**: Immutable Dataclass
- **Test Status**: PASS
#### Refactoring Details
- Converted untyped user tuple into `@dataclass(frozen=True) class User`.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.

