Agent skill

modernpython

Use when reviewing Python code for modernization opportunities, writing new Python 3.11+ code to ensure modern patterns, or refactoring legacy code to current idioms. Covers proper types, DRY, SRP, framework patterns, and idiomatic Python improvements.

Stars 33
Forks 4

Install this agent skill to your Project

npx add-skill https://github.com/Jamie-BitFlight/claude_skills/tree/main/plugins/python3-development/skills/modernpython

SKILL.md

<modernization_targets>$ARGUMENTS</modernization_targets>

Python Modernization Guide

The model applies modern Python 3.11+ patterns when writing or reviewing Python code.

Arguments

<modernization_targets/>

Instructions

If file paths provided:

  1. Read each file
  2. Identify legacy patterns
  3. Apply modern transformations from the reference guide
  4. Report changes made or recommended

If topic provided (e.g., "typing", "match-case"):

  1. Provide guidance on that specific topic
  2. Show before/after examples

If no arguments:

  1. Ask what code to review or what topic to explain

Quick Reference: Modern Patterns

Type Hints (PEP 585, 604)

python
# Legacy (NEVER use)
from typing import List, Dict, Optional, Union

# Modern (ALWAYS use)
items: list[str]
config: dict[str, int] | None
value: int | str

Walrus Operator (PEP 572)

python
# Legacy
data = fetch_data()
if data:
    process(data)

# Modern
if data := fetch_data():
    process(data)

Match-Case (PEP 634)

Use match-case when using elif. Use if/elif only for inequalities or boolean operators.

python
# Modern (for any elif pattern)
match status_code:
    case 200: return "OK"
    case 404: return "Not Found"
    case _: return "Unknown"

Self Type (PEP 673)

python
from typing import Self

class Builder:
    def add(self, x: int) -> Self:
        self.value += x
        return self

Exception Notes (PEP 678)

python
except FileNotFoundError as e:
    e.add_note(f"Attempted path: {path}")
    raise

StrEnum (Python 3.11+)

python
from enum import StrEnum

class Status(StrEnum):
    PENDING = "pending"
    RUNNING = "running"

TOML Support (Python 3.11+)

python
import tomllib
from pathlib import Path

config = tomllib.load(Path("pyproject.toml").open("rb"))

Testing Patterns

ALWAYS use pytest-mock, NEVER unittest.mock:

python
# Legacy (NEVER use)
from unittest.mock import Mock, patch

# Modern (ALWAYS use)
from pytest_mock import MockerFixture

def test_feature(mocker: MockerFixture) -> None:
    mock_func = mocker.patch('module.function', return_value=42)

Framework Patterns

Typer CLI

ALWAYS use Annotated syntax:

python
from typing import Annotated
import typer

@app.command()
def process(
    input_file: Annotated[Path, typer.Argument(help="Input file")],
    verbose: Annotated[bool, typer.Option("--verbose", "-v")] = False,
) -> None:
    """Process input file."""
    pass

Rich Tables

Use explicit width control for production CLIs:

python
from rich.console import Console
from rich.table import Table
from rich.measure import Measurement

def _get_table_width(table: Table) -> int:
    temp_console = Console(width=9999)
    measurement = Measurement.get(temp_console, temp_console.options, table)
    return int(measurement.maximum)

Detailed Reference

For complete transformation rules, PEP references, and framework patterns, see:

references/modernization-guide.md


Core Principles

  1. Use Python 3.11+ as minimum baseline
  2. Leverage built-in generics (PEP 585) and pipe unions (PEP 604) exclusively
  3. Apply walrus operator to reduce line count
  4. Use match-case for elif patterns
  5. Implement comprehensive type hints with Protocol, TypeVar, TypeGuard
  6. Use Self type (PEP 673) for fluent APIs
  7. Follow Typer patterns with Annotated syntax for CLIs
  8. Use Rich for terminal output with proper width handling
  9. Write pytest tests with pytest-mock and AAA pattern
  10. Apply clean architecture with dependency injection

References

Expand your agent's capabilities with these related and highly-rated skills.

Jamie-BitFlight/claude_skills

ccc

This skill should be used when code search is needed (whether explicitly requested or as part of completing a task), when indexing the codebase after changes, or when the user asks about ccc, cocoindex-code, or the codebase index. Trigger phrases include 'search the codebase', 'find code related to', 'update the index', 'ccc', 'cocoindex-code'.

33 4
Explore
Jamie-BitFlight/claude_skills

agent-browser

Browser automation CLI for AI agents. Use when the user needs to interact with websites, including navigating pages, filling forms, clicking buttons, taking screenshots, extracting data, testing web apps, or automating any browser task. Triggers include requests to "open a website", "fill out a form", "click a button", "take a screenshot", "scrape data from a page", "test this web app", "login to a site", "automate browser actions", or any task requiring programmatic web interaction.

33 4
Explore
Jamie-BitFlight/claude_skills

delegate

Quick delegation template for sub-agent prompts. Use when assigning work to a sub-agent, before invoking the Agent tool, or when preparing prompts for specialized agents. Provides the WHERE-WHAT-WHY framework. For comprehensive delegation guidance, activate the agent-orchestration how-to-delegate skill.

33 4
Explore
Jamie-BitFlight/claude_skills

swarm-spawning

Spawn agents and teammates in Claude Code swarms. Use when choosing between subagents vs teammates, selecting agent types (Explore, Plan, general-purpose, plugin agents), configuring spawn backends (in-process, tmux, iterm2), or setting environment variables for spawned agents.

33 4
Explore
Jamie-BitFlight/claude_skills

knowledge-explorer

Manage the research/ knowledge base (KB) of tool and library research entries. Use when browsing KB topics, adding new research entries, updating existing entries with dated revisions, fetching GitHub repo metadata into a draft KB entry, or migrating old-format entries to skill-spec frontmatter. Triggers on tasks like "what do we have on X", "add this to the KB", "update the KB entry for Y", "fetch github info for owner/repo", or "migrate old entries".

33 4
Explore
Jamie-BitFlight/claude_skills

design-anti-patterns

Enforce anti-AI UI design rules based on the Uncodixfy methodology. Use when generating HTML, CSS, React, Vue, Svelte, or any frontend UI code. Prevents "Codex UI" — the generic AI aesthetic of soft gradients, floating panels, oversized rounded corners, glassmorphism, hero sections in dashboards, and decorative copy. Applies constraints from Linear/Raycast/Stripe/GitHub design philosophy: functional, honest, human-designed interfaces. Triggers on: UI generation, dashboard building, frontend component creation, CSS styling, landing page design, or any task producing visual interface code.

33 4
Explore

Didn't find tool you were looking for?

Be as detailed as possible for better results