python

Identify and summarize common Python pitfalls in production code.

13|Updated Mar 15, 2019
One-click install
npx skills add https://github.com/WTFox/dotfiles --skill python-wtfox
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python
Source: https://github.com/WTFox/dotfiles/tree/main/claude/.claude/skills/python
Command: npx skills add https://github.com/WTFox/dotfiles --skill python-wtfox

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Load when writing, reviewing, or debugging general Python code — not framework-specific. This guidance highlights the patterns Claude consistently gets wrong in production Python: mutable defaults, exception handling pitfalls, type hinting quirks, dataclass usage, closures, and other common gotchas.

Core Features & Use Cases

  • Identify and explain the most error-prone Python patterns that commonly slip into production code.
  • Provide concrete, ready-to-apply fixes for function definitions, class attributes, typing, and data modeling.
  • Offer real-world examples to illustrate how to correct issues and improve reliability and maintainability.

Quick Start

Review the supplied Python code for common production pitfalls and refactor it to follow best practices.

Frequently Asked Questions about python

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

FAQPage Schema
How do I fix mutable default arguments in Python function definitions?

Mutable default arguments in Python cause shared state bugs across calls. Use immutable defaults like None and initialize mutable objects inside the function body to ensure safe, isolated execution.

What are common Python exception handling pitfalls in production code?

Common Python exception handling pitfalls include overly broad except clauses and swallowing errors. Apply specific exception types and ensure errors are logged or re-raised to maintain production code reliability.

How do I use type hints correctly in Python to avoid common quirks?

Python type hints prevent runtime errors by enforcing static checks. Apply concrete types and avoid overly broad annotations to ensure robust code validation and maintainability.

What is the best way to structure dataclasses for reliable data modeling?

Dataclasses provide structured data modeling in Python. Define explicit type annotations and use frozen classes to prevent accidental mutation, ensuring robust and maintainable production code.

Why do Python closures capture variables by reference and how does this cause bugs?

Python closures capture variables by reference, leading to unexpected late-binding bugs. Use default arguments or factory functions to bind the current variable state and prevent production gotchas.

Does this Python code review guidance apply to framework-specific code?

This Python code review guidance targets general production code, not framework-specific logic. It focuses on core language gotchas like mutable defaults, typing, and closures across any standard Python application.