python

Guides writing idiomatic Python code following PEP 8 and modern best practices.

Updated Nov 21, 2025
One-click install
npx skills add https://github.com/alatyshau/duet --skill python-alatyshau
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python
Source: https://github.com/alatyshau/duet/tree/main/packages/skills/coding/python
Command: npx skills add https://github.com/alatyshau/duet --skill python-alatyshau

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Python codebases often accumulate unidiomatic patterns, missing type hints, and poor error handling that reduce readability and maintainability. This Skill provides a concise reference of idiomatic Python conventions so generated or reviewed code follows modern best practices. ## Core Features & Use Cases - Type Hint Guidance: Enforces typed public APIs using built-in generics and typing constructs like Optional, Union, TypeVar, and Protocol. - Idiomatic Patterns: Promotes unpacking, context managers, comprehensions, and EAFP-style error handling over legacy constructs. - Anti-pattern Detection: Flags mutable default arguments, wildcard imports, bare except clauses, and deep inheritance hierarchies. - Use Case: When asking an AI to write a new Python module or refactor existing code, this Skill ensures the output follows PEP 8, uses specific exception handling, and maintains a clean project structure. ## Quick Start Write a Python module for parsing CSV files following the python skill's idioms and type hint 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, explicit over implicit logic, comprehensions over map/filter, context managers for resources, and EAFP-style error handling. Follow PEP 8 and PEP 20, and add type hints to public APIs.

How to add type hints to Python functions?

Annotate parameters and return types using built-in generics like list[str] and dict[str, int]. For complex cases, use typing constructs such as Optional, Union, TypeVar, and Protocol to keep the public API explicit.

What are common Python anti-patterns to avoid?

Avoid mutable default arguments like def f(items=[]), wildcard imports, bare except clauses that catch SystemExit, deep inheritance hierarchies, and using type() comparisons instead of isinstance().

Why is bare except bad in Python?

A bare except catches SystemExit and KeyboardInterrupt, making programs hard to interrupt and hiding real bugs. Catch specific exceptions like ValueError instead, and define custom exceptions inheriting from a domain base class.

Should I use EAFP or LBYL in Python?

Python convention prefers EAFP: attempt the operation inside a try block and handle specific exceptions, rather than checking conditions beforehand. This avoids race conditions and produces cleaner, more readable code.