/python-package:code-qualityfrom python-package
Configures Ruff, mypy, and pre-commit for Python code quality. Covers rule sets, type annotations (PEP 695/649), TYPE_CHECKING, and lint/format choices.
Ships in python-package. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
The modern Python code quality stack has consolidated around two tools: Ruff for linting and formatting, mypy (or pyright) for type checking. Ruff replaces Black, isort, flake8, pyupgrade, autoflake, and all flake8 plugins with a single Rust-powered binary that is 10-100x faster. Every major package -- FastAPI, Pydantic, httpx, Polars, Rich, pytest, attrs -- has migrated to Ruff. There is no credible alternative for new projects.
Without this consolidation, teams juggle conflicting configurations across six or more tools, deal with parser incompatibilities, and waste CI minutes. Without type checking in CI, a py.typed marker becomes a lie -- promising type safety to downstream consumers while delivering none.
Start with an explicit select of rules you want. Never use select = ["ALL"] with a long ignore list -- every Ruff update adds new rules that fire unexpectedly.
[tool.ruff.lint]
select = [
"F", # Pyflakes -- undefined names, unused imports
"E", # pycodestyle errors
"W", # pycodestyle warnings
"I", # isort -- import sorting
"N", # pep8-naming -- naming conventions
"UP", # pyupgrade -- modernize syntax
"B", # flake8-bugbear -- common bugs
"SIM", # flake8-simplify -- simplifiable code
"C4", # flake8-comprehensions -- better comprehensions
"RUF", # Ruff-specific rules
"PERF", # Perflint -- performance anti-patterns
]
ignore = ["E501"] # Line too long -- handled by formatter
Also consider adding:
"TCH" -- moves type-only imports behind if TYPE_CHECKING: guards, reducing import time and breaking circular imports. Most valuable for typed libraries where downstream users pay your import cost."C90" -- flags functions exceeding a cyclomatic complexity threshold (default 10). A code review guardrail for functions that are too complex to maintain and test. Pair with [tool.ruff.lint.mccabe] max-complexity = 10.| Tier | Prefixes | Notes |
|---|---|---|
| Must have | F, E, W, I, UP, B | Every top package enables these. Zero noise. |
| Recommended | N, SIM, C4, RUF, PERF | Enabled by Pydantic, Polars, attrs. Catches real issues. |
| Consider | S, D, TCH, PT, C90, PLR | Useful with targeted ignores. TCH valuable for typed libraries. |
| Optional | A, FBT, ARG, ERA, ANN | Opinionated or high false-positive rate. Cherry-pick individual rules. |
Relax rules where they create noise rather than value:
[tool.ruff.lint.per-file-ignores]
"tests/**/*.py" = ["S101", "D", "ANN", "PLR2004"]
"__init__.py" = ["F401"] # Allow unused imports (re-exports)
[tool.ruff]
target-version = "py310" # Match your requires-python lower bound
line-length = 88 # Black default, de facto standard
src = ["src"] # Critical for correct first-party import detection
[tool.ruff.lint.isort]
known-first-party = ["my_package"]
[tool.ruff.format]
docstring-code-format = true
Set src = ["src"] when using src layout. Without it, Ruff cannot distinguish first-party from third-party imports and isort grouping breaks silently.
Use ruff format as a drop-in Black replacement. Same defaults (line length 88, double quotes, magic trailing comma respected), but 30-100x faster.
| Setting | Keep Default | Change Only If |
|---|---|---|
quote-style = "double" | Yes | Team strongly prefers single quotes |
line-length = 88 | Yes | Corporate standard requires different |
skip-magic-trailing-comma = false | Yes | Never change -- preserves developer formatting intent |
docstring-code-format = true | Enable this | No reason not to |
| Aspect | mypy | pyright |
|---|---|---|
| Use when | Need plugins (pydantic, django, sqlalchemy) | Want fastest checks, strictest analysis |
| Strictness | strict = true flag | typeCheckingMode = "strict" |
| Speed | Moderate (use daemon mode) | Consistently fast |
| IDE | External tool | Powers VS Code Pylance |
| Plugin support | Rich ecosystem | Limited |
For library authors: Run both. Different checkers catch different issues. Pydantic, FastAPI, and httpx do this.
[tool.mypy]
python_version = "3.10"
strict = true
warn_return_any = true
warn_unused_configs = true
enable_error_code = ["ignore-without-code", "redundant-cast", "truthy-bool"]
[[tool.mypy.overrides]]
module = "tests.*"
disallow_untyped_defs = false
Always specify error codes in # type: ignore[error-code]. Bare # type: ignore silences all errors on the line, hiding real bugs. Ruff rule PGH003 catches this automatically.
[tool.pyright]
pythonVersion = "3.10"
typeCheckingMode = "standard"
reportUnnecessaryTypeIgnoreComment = true
enableTypeIgnoreComments = false
typeCheckingMode = "standard" is the practical starting point -- strict pyright is significantly noisier than strict mypy, and most exemplar libraries (Pydantic, Flask, SQLAlchemy) do not use strict mode. enableTypeIgnoreComments = false separates suppression concerns: # type: ignore[code] is for mypy only, # pyright: ignore[rule] is for pyright only. This is the pattern typeshed uses and eliminates cross-contamination between the two checkers.
Use the newest syntax your minimum Python version supports. Ruff's UP rules auto-fix old patterns.
| Old Pattern | Modern Pattern | Since |
|---|---|---|
List[str], Dict[str, Any] | list[str], dict[str, Any] | Python 3.9 |
Optional[str], Union[str, int] | str | None, str | int | Python 3.10 |
TypeVar("T") + Generic[T] | class Foo[T]: | Python 3.12 (PEP 695) |
TypeAlias = Union[...] | type Alias = str | int | Python 3.12 (PEP 695) |
from __future__ import annotations | Remove it | Python 3.14 (PEP 649) |
py.typedEvery typed package must include an empty py.typed marker file and the Typing :: Typed classifier. Without it, type checkers ignore your annotations for downstream users. See the project-structure skill for the full explanation, file placement, and PEP 561 details.
Move type-only imports behind TYPE_CHECKING to avoid circular imports and reduce import time:
from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from heavy_module import ExpensiveClass
Ruff's TCH rules detect imports that should be behind this guard.
Pydantic and runtime annotation frameworks: Do not guard imports behind TYPE_CHECKING if the type is used in Pydantic models, dataclasses with runtime validation, or any framework that evaluates annotations at runtime (serializers, dependency injection containers). Pydantic needs the actual class at runtime for validation -- guarding it behind TYPE_CHECKING causes NameError. When using TCH rules, configure Ruff to recognize your runtime annotation framework: [tool.ruff.lint.flake8-type-checking] runtime-evaluated-base-classes = ["pydantic.BaseModel"].
Collapse the entire pre-commit config to two Ruff hooks plus basic file hygiene. Do not add mypy, pytest, or security scanners -- they are too slow for pre-commit and belong in CI.
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-toml
- id: check-added-large-files
args: ["--maxkb=500"]
- id: check-merge-conflict
- id: debug-statements
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.7
hooks:
- id: ruff
args: [--fix]
- id: ruff-format
Run ruff (linter with --fix) before ruff-format so auto-fixes are properly formatted.
Complete pyproject.toml quality tooling section:
# -- Ruff ---------------------------------------------------------
[tool.ruff]
target-version = "py310"
line-length = 88
src = ["src"]
[tool.ruff.lint]
select = ["F", "E", "W", "I", "N", "UP", "B", "SIM", "C4", "RUF", "PERF", "TCH", "C90"]
ignore = ["E501"]
[tool.ruff.lint.per-file-ignores]
"tests/**/*.py" = ["S101", "PLR2004"]
"__init__.py" = ["F401"]
[tool.ruff.lint.isort]
known-first-party = ["my_package"]
[tool.ruff.lint.mccabe]
max-complexity = 10
[tool.ruff.format]
docstring-code-format = true
# -- mypy ----------------------------------------------------------
[tool.mypy]
python_version = "3.10"
strict = true
warn_return_any = true
warn_unused_configs = true
enable_error_code = ["ignore-without-code", "redundant-cast", "truthy-bool"]
[[tool.mypy.overrides]]
module = "tests.*"
disallow_untyped_defs = false
# -- pyright (for libraries running both checkers) -----------------
[tool.pyright]
pythonVersion = "3.10"
typeCheckingMode = "standard"
reportUnnecessaryTypeIgnoreComment = true
enableTypeIgnoreComments = false
# -- Dependency group ----------------------------------------------
[dependency-groups]
lint = ["ruff>=0.9", "mypy>=1.14", "pyright>=1.1"]
When reviewing code for quality tooling and type safety:
tool.ruff.lint.select uses explicit opt-in, not select = ["ALL"] with a long ignore listsrc = ["src"] is set in [tool.ruff] for src-layout projectsE501 is in the ignore list when using ruff format (formatter handles line length)strict = true) with enable_error_code = ["ignore-without-code"]# type: ignore comments -- all have specific error codestypeCheckingMode = "standard", enableTypeIgnoreComments = false)py.typed marker file exists in the package root and is included in the wheellist[str], str | None)ruff hook runs before ruff-format in pre-commit orderingper-file-ignores relaxes rules for tests and __init__.py re-exportsmax-complexity = 10) if C90 is enabledTYPE_CHECKING guards do not hide types used by runtime validation frameworks (Pydantic, attrs, dataclasses)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub oborchers/fractional-cto --plugin python-package13 skills in this plugin
/api-designThis skill should be used when the user is designing a library's public API surface, defining __all__, organizing imports, creating an exception hierarchy, implementing async/sync dual APIs, adding plugin architecture (pluggy, entry points, protocols), applying progressive disclosure, choosing return types, naming methods, or reviewing backward compatibility. Covers __all__, underscore-prefixed modules, exception trees, httpx _BaseClient pattern, pluggy, entry points, Protocols, dependency injection, configuration patterns./ci-cdThis skill should be used when the user is setting up GitHub Actions, configuring CI/CD pipelines, creating test matrices, enabling trusted publishing with OIDC, automating PyPI releases, adding Dependabot or Renovate, or configuring Sigstore attestations. Covers workflow architecture, lint/type-check/test/build/publish jobs, caching, concurrency, reusable workflows, SLSA provenance./cli-architectureThis skill should be used when the user is adding a CLI to a Python package, choosing between Click, Typer, and argparse, structuring cli.py or a cli/ directory, creating a __main__.py for python -m support, defining console script entry points, handling exit codes, or organizing subcommands. Covers framework selection, CLI module layout, __main__.py delegation pattern, exit code conventions, and subcommand organization./developer-experienceThis skill should be used when the user is writing a CONTRIBUTING.md, setting up developer onboarding, creating a Makefile or justfile, adding issue templates, adding PR templates, writing a README, creating a CODE_OF_CONDUCT.md, setting up CODEOWNERS, adding .editorconfig, configuring devcontainers, labeling good first issues, or building project community and governance. Covers one-command dev setup, task automation, contributor funnel, and community health files./documentationThis skill should be used when the user is setting up MkDocs Material, configuring mkdocstrings, writing docstrings, generating API reference pages, structuring documentation with the Diataxis framework, deploying docs to GitHub Pages or ReadTheDocs, or writing a README. Covers mkdocs.yml configuration, Griffe, Google-style docstrings, versioned docs with mike, code example testing, nav structure./packaging-distributionThis skill should be used when the user is building wheels, creating sdists, packaging compiled extensions, configuring cibuildwheel, setting up maturin for Rust extensions, using scikit-build-core, optimizing package size, working with platform tags, namespace packages, or choosing between pure Python and compiled distributions. Covers wheel format, abi3 stable ABI, manylinux/musllinux tags, dual-package strategy, environment markers, PyPI metadata, and TestPyPI.Other plugins' skills for the same job