From python3-development
Reviews and refactors Python 3.11+ code to modern idioms: type hints, walrus operator, match-case, Self type, pytest-mock, Typer CLI, Rich tables.
npx claudepluginhub jamie-bitflight/claude_skills --plugin python3-developmentThis skill uses the workspace's default tool permissions.
<modernization_targets>$ARGUMENTS</modernization_targets>
Identifies legacy Python patterns and applies 3.11+ modernizations like walrus operator, match-case, Self type, and pytest-mock. Reviews files or explains topics with PEP examples.
Guides Python 3.11+ CLI apps with Typer/Rich, pytest test suites, ruff/mypy fixes, pyproject.toml config, portable scripts, and code reviews. Routes to specialist sub-skills.
Enforces opinionated production standards for Python 3.10-3.13 including modern type syntax, explicit checks, pathlib, interfaces, and CLI patterns. Use for writing, reviewing, refactoring code.
Share bugs, ideas, or general feedback.
<modernization_targets>$ARGUMENTS</modernization_targets>
The model applies modern Python 3.11+ patterns when writing or reviewing Python code.
<modernization_targets/>
If file paths provided:
If topic provided (e.g., "typing", "match-case"):
If no arguments:
# Legacy (NEVER use)
from typing import List, Dict, Optional, Union
# Modern (ALWAYS use)
items: list[str]
config: dict[str, int] | None
value: int | str
# Legacy
data = fetch_data()
if data:
process(data)
# Modern
if data := fetch_data():
process(data)
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"
from typing import Self
class Builder:
def add(self, x: int) -> Self:
self.value += x
return self
except FileNotFoundError as e:
e.add_note(f"Attempted path: {path}")
raise
from enum import StrEnum
class Status(StrEnum):
PENDING = "pending"
RUNNING = "running"
import tomllib
from pathlib import Path
config = tomllib.load(Path("pyproject.toml").open("rb"))
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)
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
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)
For complete transformation rules, PEP references, and framework patterns, see:
references/modernization-guide.md