python-code-quality

Reviews Python code using ruff linting, mypy type checking, and Pythonic refactoring patterns.

1|2|Updated Nov 25, 2017
One-click install
npx skills add https://github.com/asarchami/dotfiles --skill python-code-quality-asarchami
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-code-quality
Source: https://github.com/asarchami/dotfiles/tree/main/dot_config/opencode/skills/python/code-quality
Command: npx skills add https://github.com/asarchami/dotfiles --skill python-code-quality-asarchami

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Python codebases often accumulate lint violations, missing type annotations, and anti-patterns like mutable default arguments or bare except clauses. This Skill provides a structured checklist and configuration guidance to bring Python code up to modern quality standards using ruff and mypy. ## Core Features & Use Cases - Static Analysis Configuration: Provides minimal, ready-to-use ruff and mypy configurations for pyproject.toml, including strict type-checking options. - Type Hint Patterns: Covers common annotation patterns including generics, optionals, callables, and TypeVars for public APIs. - Anti-Pattern Detection: Identifies and fixes common issues such as mutable default arguments, bare except clauses, and non-Pythonic iteration. - Use Case: When reviewing a pull request, ask the AI to check the changed Python files against the quality checklist to catch lint errors, missing type hints, and unsafe exception handling before merging. ## Quick Start Review my Python source files for code quality issues and fix any ruff or mypy violations you find.

Frequently Asked Questions about python-code-quality

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I configure ruff and mypy in pyproject.toml?

Add a [tool.ruff] section with line-length, target-version, and lint rules like E, W, F, I, B, C4, and UP. For mypy, add a [tool.mypy] section with python_version, disallow_untyped_defs, and warn_return_any for strict checking.

How do I fix mutable default argument errors in Python?

Replace mutable defaults like list or dict with None as the default value, then initialize inside the function body. For example, use def process(items: list | None = None) followed by items = items or [].

What is the difference between ruff and mypy for Python linting?

Ruff handles linting and formatting, catching style violations, unused imports, and code smells. Mypy performs static type checking, verifying that type annotations are correct and catching type mismatches before runtime.

Does mypy strict mode require type hints on all functions?

With disallow_untyped_defs enabled, mypy requires type annotations on all function signatures. Public APIs should be fully annotated, and packages should include a py.typed marker so downstream users benefit from the type information.

Why should I avoid bare except clauses in Python?

Bare except clauses catch all exceptions including KeyboardInterrupt and SystemExit, hiding real bugs. Catch specific exceptions like ValueError instead, and log the error so failures remain visible and debuggable.