python-code-quality
Enforce Python code quality and typing standards.
Install
mkdir -p .claude/skills/python-code-quality && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/16306" && unzip -o skill.zip -d .claude/skills/python-code-quality && rm skill.zipInstalls to .claude/skills/python-code-quality
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Python code quality standards. Use when working with types, linting, type checking, exceptions, logging, or configuring ruff/ty/pyproject.toml.Key capabilities
- →Enforce type annotations for all function signatures
- →Require Pydantic models for HTTP responses
- →Use `ruff` for linting and formatting
- →Use `ty` for type checking
- →Define a base `ServiceError` for exceptions
How it works
The skill defines and enforces Python code quality standards, including typing rules, linting with `ruff`, type checking with `ty`, and structured logging practices. It specifies tooling commands for pre-commit checks.
Inputs & outputs
When to use python-code-quality
- →Configure python linting
- →Enforce typing standards
- →Setup ruff config
About this skill
Python Code Quality
Typing Rules
- Must annotate all function signatures (parameters and return)
- Must type HTTP responses with Pydantic models—never return raw
dictfrom API endpoints - Must use generics (
list[str],dict[str, Any])—never barelist,dict,tuple - Must use Pydantic models at API boundaries (requests, responses, external data)
- Should use
T | NoneoverOptional[T] - Should use keyword-only args (
*) for functions with 3+ parameters - Should use
TypeAliasfor complex dict types instead of repeatingdict[str, Any] - Avoid
Anyexcept at true boundaries; prefer specific types or generics - Never use mutable defaults (
def f(items=[])); useNoneand initialize inside
Type Choice Guide
| Need | Use |
|---|---|
| API request/response | Pydantic BaseModel |
| DB + API unified | SQLModel |
| Internal data transfer | dataclass(frozen=True, slots=True) |
| Dict with known keys | TypedDict |
| Primitive wrapper | NewType |
| Fixed string values | Literal |
- Should use
NewTypefor domain primitives (UserId,OrderId) to prevent mixing - Avoid stringly-typed code—prefer enums or
Literalfor fixed values
Tooling
- Must use
rufffor linting and formatting - Must use
ty(astral.sh) for type checking - Must run before committing:
ruff format . && ruff check --fix . && ty check . - Must enable
ANN,TCH,I,E,F,Wruff rules - Should use
line-length = 120
See ../project-setup/references/pyproject.template.toml for complete configuration.
Exceptions
- Must define a base
ServiceErrorwithmessage,code,status_code - Must create specific exceptions inheriting from base (
NotFoundError,ConflictError) - Never swallow exceptions silently—always re-raise or wrap with context
- Should use
logger.exception()to include traceback before re-raising
Logging
- Must use structured logging (
structlogorloguruwith JSON sink in production) - Must include
request_idin all log entries - Never log sensitive data (tokens, passwords, PII)
Caching
- Should use
@lru_cachefor expensive pure functions - Must set
maxsizebased on expected input cardinality - Never cache functions with side effects or mutable state
- Should use
async-lru(@alru_cache) for async functions (not bare@lru_cache)
When not to use it
- →When `Any` type is required beyond true boundaries
- →When mutable defaults are used in function parameters
- →When exceptions are swallowed silently
Limitations
- →Avoid `Any` except at true boundaries.
- →Never use mutable defaults (`def f(items=[])`).
- →Never swallow exceptions silently.
How it compares
This skill provides a prescriptive set of rules and tools for Python code quality, ensuring consistency in typing, linting, and error handling across a project, rather than relying on ad-hoc developer practices.
Compared to similar skills
python-code-quality side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| python-code-quality (this skill) | 0 | 5mo | No flags | Intermediate |
| python-testing-patterns | 77 | 2mo | Review | Intermediate |
| pr-review | 6 | 2mo | Review | Intermediate |
| pytest | 8 | 7mo | Review | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
You might also like
python-testing-patterns
wshobson
Implement comprehensive testing strategies with pytest, fixtures, mocking, and test-driven development. Use when writing Python tests, setting up test suites, or implementing testing best practices.
pr-review
pytorch
Review PyTorch pull requests for code quality, test coverage, security, and backward compatibility. Use when reviewing PRs, when asked to review code changes, or when the user mentions "review PR", "code review", or "check this PR".
pytest
prowler-cloud
Pytest testing patterns for Python. Trigger: When writing or refactoring pytest tests (fixtures, mocking, parametrize, markers). For Prowler-specific API/SDK testing conventions, also use prowler-test-api or prowler-test-sdk.
code-change-verification
openai
Run the mandatory verification stack when changes affect runtime code, tests, or build/test behavior in the OpenAI Agents Python repository.
django-verification
affaan-m
Verification loop for Django projects: migrations, linting, tests with coverage, security scans, and deployment readiness checks before release or PR.
python
alinaqi
Python development with ruff, mypy, pytest - TDD and type safety