writing-python

Prescribe idiomatic Python 3.14+ patterns with protocol-based DI and flat control flow.

35|5|Updated Jul 5, 2025
One-click install
npx skills add https://github.com/alexei-led/claude-code-config --skill writing-python
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: writing-python
Source: https://github.com/alexei-led/claude-code-config/tree/main/skills/writing-python
Command: npx skills add https://github.com/alexei-led/claude-code-config --skill writing-python

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill cuts through Python complexity by enforcing idiomatic patterns, flat control flow, and strict typing, helping you write maintainable, bug-resistant code without the guesswork.

Core Features & Use Cases

  • Modern Python 3.14+ Patterns: Leverage protocols for dependency injection, pattern matching for control flow, and deferred annotations.
  • Zero-Tolerance for Anti-Patterns: Enforce guard clauses over nested conditions, concrete types over any, and explicit error handling.
  • Use Case: Imagine you're designing a new CLI tool. Use this Skill to structure it with Typer, implement a clean service layer using Protocol-based interfaces, and write flat, testable functions.

Quick Start

Use the writing-python skill to refactor this nested function into a flat control flow using guard clauses and early returns.

Frequently Asked Questions about writing-python

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

FAQPage Schema
How do I write Python code with type hints and avoid using Any?

Type hints without Any enforce concrete types throughout your codebase. This Skill prescribes replacing Any with explicit Protocol-based types and stdlib alternatives, catching type errors early and making code intent clearer for maintenance and testing.

What's the best way to structure a Python CLI tool with clean, flat control flow?

Use guard clauses and early returns to eliminate nested conditions, keeping functions flat and readable. This Skill guides you through Protocol-based dependency injection, pattern matching for control flow, and stdlib-first tooling like Typer to build maintainable CLI applications.

How do I refactor nested Python functions into guard clauses and flat logic?

Guard clauses exit early when conditions fail, reducing indentation and nesting depth to a maximum of two levels. This Skill teaches you to replace deep conditionals with explicit error handling and early returns, making functions testable and easier to follow.

When should I use Protocol instead of Abstract Base Classes in Python?

Protocols enable structural typing and dependency injection without inheritance constraints, aligning with modern Python 3.14+ patterns. This Skill enforces Protocol-based design over ABC to reduce coupling and support cleaner, more flexible service layer implementations.

What tooling should I use to enforce Python code quality and catch type errors?

Ruff for linting, mypy for static type checking, and pytest for testing form the modern Python quality stack. This Skill prescribes configuring these tools to enforce idiomatic patterns, guard clauses, explicit error handling, and stdlib-first solutions automatically.

Do I need to use custom exception hierarchies in Python applications?

Custom exception hierarchies enable explicit error handling and recovery paths specific to your domain. This Skill requires defining and raising custom exceptions rather than relying on built-in ones, improving clarity about failure modes in services, CLI tools, and scripts.