python

Enforces idiomatic Python style, patterns, and conventions when writing or reviewing Python code.

10|2|Updated Jan 24, 2026
One-click install
npx skills add https://github.com/nrdxp/predicate --skill python-nrdxp
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python
Source: https://github.com/nrdxp/predicate/tree/main/skills/python
Command: npx skills add https://github.com/nrdxp/predicate --skill python-nrdxp

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Python codebases drift into inconsistent formatting, unidiomatic constructs, and subtle bugs like mutable default arguments or bare except clauses. This Skill anchors the agent to idiomatic Python conventions so generated and reviewed code follows PEP 8 style, modern typing syntax, and safe language patterns. ## Core Features & Use Cases - Style and Naming Enforcement: Applies snake_case/PascalCase conventions, 4-space indentation, isort-ordered imports, and formatter-driven line lengths via ruff or black. - Idiom Guidance: Covers truthiness checks, comprehensions, generators, context managers, dataclasses with slots, structural pattern matching, and modern type annotations like int | str. - Anti-Pattern Detection: Flags mutable default arguments, bare except clauses, builtin shadowing, god classes, and isinstance chains, with concrete remedies. - Use Case: When asked to refactor a legacy module, the agent rewrites nested conditionals into guard clauses, replaces type(x) == int with isinstance, converts manual __init__ classes into frozen dataclasses, and annotates function signatures with modern union syntax. ## Quick Start Ask the agent to review or write Python code in this project and it will apply these idioms, for example: refactor my utils.py file to follow idiomatic Python conventions.

Frequently Asked Questions about python

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

FAQPage Schema
How do I write idiomatic Python code?

Idiomatic Python favors readability, comprehensions for simple transforms, context managers for resource cleanup, and duck typing over inheritance hierarchies. Use truthiness checks like `if not seq` instead of `len(seq) == 0`, and let a formatter like ruff or black handle style enforcement.

How to avoid mutable default argument bugs in Python?

Never use a mutable object like a list as a default parameter value, since it is shared across all calls. Use `None` as a sentinel and create the list inside the function body instead.

Should I use dataclasses or NamedTuple in Python?

Use @dataclass for mutable data with behavior and @dataclass(frozen=True) for immutable value objects that are hashable. NamedTuple fits lightweight immutable records needing tuple compatibility, while TypedDict suits typed dictionary shapes from JSON APIs.

What is the difference between ruff and black for formatting?

Ruff provides both linting and formatting in one fast tool, while black is a dedicated opinionated formatter. Pick one formatter project-wide and enforce it in CI rather than mixing tools.

Why should I use isinstance instead of type comparison?

isinstance(x, int) respects inheritance, so subclasses pass the check, while type(x) == int only matches the exact class. This makes isinstance the safer and more flexible choice for type checking.

When should I use match/case instead of if-elif chains?

Use match/case in Python 3.10+ when destructuring a single subject by structure, type, or value, such as parsing command dictionaries or class instances. Long isinstance chains are a strong signal to switch to structural pattern matching.