本文へ移動
cccskills
無料GitHub で公開

modernpython

Applies and teaches Python 3.11+ modernization patterns with PEP citations. Use when reviewing or writing Python code to apply built-in generics (PEP 585), pipe unions (PEP 604), walrus operator (PEP 572), match-case (PEP 634), Self type (PEP 673), exception notes (PEP 678), StrEnum, tomllib, pytest-mock fixtures, Typer Annotated syntax, or Rich terminal output — or when refactoring legacy typing imports or elif chains to modern equivalents.

インストール方法を見る

含まれるファイル(1)

  • SKILL.md4.5 KB

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)

# 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)

# 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.

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

Self Type (PEP 673)

from typing import Self


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

Exception Notes (PEP 678)

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

StrEnum (Python 3.11+)

from enum import StrEnum


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

TOML Support (Python 3.11+)

import tomllib
from pathlib import Path

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

Testing Patterns

ALWAYS use pytest-mock, NEVER unittest.mock:

# 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:

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:

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)

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

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

Add automated documentation updater to any Claude skill. Creates a Python sync script that downloads upstream docs, processes markdown for AI consumption, and maintains local cache with configurable refresh. Collects template variables, then delegates implementation through 5-phase workflow. Use when adding auto-updating reference documentation to plugins or skills.

日本語の概要は準備中です。原文の説明を表示しています。

Jamie-BitFlight/claude_skills672026年10月9日 更新

SAM-style feature initiation workflow — discovery through codebase analysis, architecture spec, task decomposition, validation, and context manifest. Use when a user asks to add a feature, plan a feature, or convert an idea into an executable SAM plan.

日本語の概要は準備中です。原文の説明を表示しています。

Jamie-BitFlight/claude_skills672026年10月9日 更新

Browser automation for AI agents using the agent-browser CLI and Playwright. Use when navigating pages, filling forms, clicking buttons, taking screenshots, extracting data, testing web apps, logging into sites, or automating any browser task. Triggers on "open a website", "fill out a form", "click a button", "scrape data", "test this web app", "automate browser actions", or any programmatic web interaction request.

日本語の概要は準備中です。原文の説明を表示しています。

Jamie-BitFlight/claude_skills672026年10月9日 更新

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.

日本語の概要は準備中です。原文の説明を表示しています。

Jamie-BitFlight/claude_skills672026年10月9日 更新

Runs the description-drift experiment — spawns all Claude Code agents simultaneously to collect self-reported capabilities, then compares them against static frontmatter descriptions to reveal how reliable orchestrator routing based on descriptions actually is. Use when measuring description drift across the agent fleet, re-running the capability collection experiment, analyzing a specific agent's self-reported capabilities, or auditing whether frontmatter descriptions accurately reflect agent behavior.

日本語の概要は準備中です。原文の説明を表示しています。

Jamie-BitFlight/claude_skills672026年10月9日 更新

Create or adapt Claude Code agent definitions. Use when creating an agent, changing subagent configuration, selecting agent scope, or designing a specialized delegation role.

日本語の概要は準備中です。原文の説明を表示しています。

Jamie-BitFlight/claude_skills672026年10月9日 更新

Jamie-BitFlight のスキルをすべて見る

このスキルの問題を報告する