python-anti-patterns

Use this skill when reviewing Python code for common anti-patterns to avoid. Use as a checklist when reviewing code, before finalizing implementations, or when debugging issues that might stem from known bad practices.

By wshobson · 11,666 installs

npx skills add wshobson/agents --skill python-anti-patterns

Source repository · Upstream listing

Python Anti Patterns Checklist A reference checklist of common mistakes and anti patterns in Python code. Review this before finalizing implementations to catch issues early. When to Use This Skill Reviewing code before merge Debugging mysterious issues Teaching or learning Python best practices Establishing team coding standards Refactoring legacy code Note: This skill focuses on what to avoid. For guidance on positive patterns and architecture, see the python design patterns skill. Infrastructure Anti Patterns Scattered Timeout/Retry Logic Fix: Centralize in decorators or client wrappers. Double Retry Fix: Retry at one layer only. Know your infrastructure's retry behavior. Hard Coded Configuration Fix: Use environment variables with typed settings. Architecture Anti Patterns Exposed Internal Types Fix: Use DTOs/response models. Mixed I/O and Business Logic Fix: Repository pattern. Keep business logic pure. Error Handling Anti Patterns Bare Exception Handling Fix: Catch specific exceptions. Log or handle appropriately. Ignored Partial Failures Fix: Capture both successes and failures. Missing Input Validation Fix: Validate early at API boundaries. Resource Anti Patterns Unclosed Resources Fix: Use context managers. Blocking in Async Fix: Use async native libraries. Type Safety Anti Patterns Missing Type Hints Fix: Annotate all public functions. Untyped Collections Fix: Use type parameters. Testing Anti Patterns Only Testing Happy Paths Fix: Test error conditions and edge cases. Over Mocking Fix: Use integration tests for critical paths. Mock only external services. Quick Review Checklist Before finalizing code, verify: [ ] No scattered timeout/retry logic (centralized) [ ] No double retry (app + infrastructure) [ ] No hard coded configuration or secrets [ ] No exposed internal types (ORM models, protobufs) [ ] No mixed I/O and business logic [ ] No bare except Exception: pass [ ] No ignored partial failures in batches [ ] No missing input validation [ ] No unclosed resources (using context managers) [ ] No blocking calls in async code [ ] All public functions have type hints [ ] Collections have type parameters [ ] Error paths are tested [ ] Edge cases are covered Common Fixes Summary Anti Pattern Fix Scattered retry logic Centralized decorators Hard coded config Environment variables + pydantic settings Exposed ORM models DTO/response schemas Mixed I/O + logic Repository pattern Bare except Catch specific exceptions Batch stops on error Return BatchResult with successes/failures No validation Validate at boundaries with Pydantic Unclosed resources Context managers Blocking in async Async native libraries Missing types Type annotations on all public APIs Only happy path tests Test errors and edge cases