agentleFS
Baba01hacker666Baba01hacker666/dummyskills/skills/python/py-code-quality/SKILL.md

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.

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
  1. Distinctive:

    Use this skill when:

    line 14
  2. Very specific:

    Do not use for running tests.

    line 20
  3. Very specific:

    Do not use to fix syntax errors.

    line 21
  4. Very specific:

    If target_file is missing: ask for target file.

    line 27
  5. Distinctive:

    Never introduce backwards-incompatible API breaks without user confirmation.

    line 28
  6. Distinctive:

    Follow these numbered actions:

    line 31
  7. Very specific:

    Check for bare except:, range(len()), and manual file close without with.

    line 33
  8. Very specific:

    Use @dataclass(frozen=True) for immutable value objects.

    line 35
  9. Very specific:

    Run pytest to confirm 100% behavior preservation.

    line 41
  10. Very specific:

    If managing files or sockets: always use with open(...) as f:.

    line 44
  11. Very specific:

    Never use mutable default arguments like def func(items=[]).

    line 45
  12. Distinctive:

    Stop and ask the user when:

    line 73

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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 @dataclass or Pydantic models.
  • Ensuring resource management uses with context managers.
  • Replacing index-based loops (for i in range(len(arr))) with enumerate() or zip().

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

  1. If target_file is missing: ask for target file.
  2. Never introduce backwards-incompatible API breaks without user confirmation.

6. Procedure

Follow these numbered actions:

  1. Action 1: Audit for Anti-Patterns
    • Check for bare except:, range(len()), and manual file close without with.
  2. Action 2: Convert Raw Dicts to Dataclasses
    • Use @dataclass(frozen=True) for immutable value objects.
  3. Action 3: Use Context Managers
    • Wrap file I/O, database sessions, and locks in with blocks.
  4. Action 4: Define Domain Exceptions
    • Inherit from a custom base exception (class DomainError(Exception): pass).
  5. Action 5: Verify Tests
    • Run pytest to confirm 100% behavior preservation.

7. Decision Rules

  • If managing files or sockets: always use with open(...) as f:.
  • Never use mutable default arguments like def func(items=[]); use items: 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 pytest suite passes.

10. Common Failures and Recovery

Failure SymptomCauseRecovery Action
Mutable default bugdef 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`.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.