Apply modern Python 3.11+ best practices with proper types, DRY, SRP, and framework patterns. Use when reviewing Python code for modernization opportunities, when writing new Python code to ensure modern patterns, or when refactoring legacy Python code to use current idioms.
<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
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer