Modern Python Guidelines
Use the bundled CLI as the source of truth for modernization guidance. It delegates
to the target project's Ruff when available and otherwise uses a pinned fallback
without modifying the project.
Commands:
- macOS or Linux:
sh "<skill-dir>/scripts/run-tool.sh"
- Windows PowerShell:
& "<skill-dir>\scripts\run-tool.ps1"
Before editing Python
Run list for the file that will be edited, before choosing Python syntax or
APIs:
sh "<skill-dir>/scripts/run-tool.sh" list --file path/to/file.py
If list exits with status 3, it found a material Ruff capability or guideline
difference. Ask the user whether to update the project's Ruff. Do not update a
dependency or lockfile without approval.
- If approved, inspect how the project manages Ruff (Pixi, uv, Poetry, PDM,
pre-commit, or another tool), update it through that existing mechanism, and
rerun
list.
- If declined, rerun the same command with
--allow-stale. Do not ask again in
the same task. A degraded result may have no proactive list; in that case use
the resolved target as the boundary and rely on the post-edit check.
Read the complete compact output. Baseline rules are verified from Ruff's
executable documentation examples for the resolved target. Conditional rules
require postponed annotations. The post-edit check can still find
configuration-dependent cases that examples cannot prove proactively.
For every listed rule that may affect the planned code, read its authoritative
explanation before editing:
sh "<skill-dir>/scripts/run-tool.sh" explain --file path/to/file.py UP045 FURB123
Only then write or modify the Python. Use the reported target version as a
compatibility boundary. Preserve explicit Ruff ignores and established project
conventions unless the user asks to change them.
For a new path, list resolves the nearest project configuration and says that the
file context was inferred. If per-file targeting remains ambiguous, rerun with an
explicit target such as --target-version py312. probe remains available for
runner and settings debugging; it does not replace list.
After editing Python
Check only the files or focused directory touched by the task:
sh "<skill-dir>/scripts/run-tool.sh" check path/to/file.py
Read the complete JSON output. For every diagnostic that may apply, retrieve
its authoritative explanation before deciding how to handle it:
sh "<skill-dir>/scripts/run-tool.sh" explain --file path/to/file.py UP045 FURB123
Apply the guidance when it preserves intended behavior and fits the edited
code. Do not mechanically force a diagnostic whose documented caveat applies.
Safe automatic fixes may be applied with:
sh "<skill-dir>/scripts/run-tool.sh" fix path/to/file.py
This does not enable Ruff's unsafe fixes. Use --unsafe-fixes only after
explaining the behavior risk and only when the task authorizes that change.
Run check again, then run the project's formatter, type checker, and tests
relevant to the changed code. The modernization check supplements the
project's verification; it does not replace it.
Profiles
The default modern post-edit profile checks
UP,FURB,SIM,C4,PIE,PTH,FLY,PERF,F401. Use --profile core for the narrower
UP,FURB,F401 set when the task calls for a conservative modernization pass.
F401 cleans imports made unused by safe modernization fixes. Preview rules remain
disabled unless the user or project explicitly opts into them.
list intentionally loads the complete compact UP/FURB guidance before editing,
matching the proactive workflow. Keep full rule documentation progressive: call
explain only for IDs relevant to the planned or diagnosed code.
1---2name: use-modern-python3description: Use Ruff-backed, version-aware guidance whenever writing, modifying, fixing, or refactoring Python code. Read relevant modern idioms before editing and verify the resulting changes.4---56# Modern Python Guidelines78Use the bundled CLI as the source of truth for modernization guidance. It delegates9to the target project's Ruff when available and otherwise uses a pinned fallback10without modifying the project.1112Commands:1314- macOS or Linux: `sh "<skill-dir>/scripts/run-tool.sh"`15- Windows PowerShell: `& "<skill-dir>\scripts\run-tool.ps1"`1617## Before editing Python18191. Run `list` for the file that will be edited, before choosing Python syntax or20 APIs:2122 ```sh23 sh "<skill-dir>/scripts/run-tool.sh" list --file path/to/file.py24 ```25262. If `list` exits with status 3, it found a material Ruff capability or guideline27 difference. Ask the user whether to update the project's Ruff. Do not update a28 dependency or lockfile without approval.2930 - If approved, inspect how the project manages Ruff (Pixi, uv, Poetry, PDM,31 pre-commit, or another tool), update it through that existing mechanism, and32 rerun `list`.33 - If declined, rerun the same command with `--allow-stale`. Do not ask again in34 the same task. A degraded result may have no proactive list; in that case use35 the resolved target as the boundary and rely on the post-edit check.36373. Read the complete compact output. Baseline rules are verified from Ruff's38 executable documentation examples for the resolved target. Conditional rules39 require postponed annotations. The post-edit check can still find40 configuration-dependent cases that examples cannot prove proactively.41424. For every listed rule that may affect the planned code, read its authoritative43 explanation before editing:4445 ```sh46 sh "<skill-dir>/scripts/run-tool.sh" explain --file path/to/file.py UP045 FURB12347 ```48495. Only then write or modify the Python. Use the reported target version as a50 compatibility boundary. Preserve explicit Ruff ignores and established project51 conventions unless the user asks to change them.5253For a new path, `list` resolves the nearest project configuration and says that the54file context was inferred. If per-file targeting remains ambiguous, rerun with an55explicit target such as `--target-version py312`. `probe` remains available for56runner and settings debugging; it does not replace `list`.5758## After editing Python59601. Check only the files or focused directory touched by the task:6162 ```sh63 sh "<skill-dir>/scripts/run-tool.sh" check path/to/file.py64 ```65662. Read the complete JSON output. For every diagnostic that may apply, retrieve67 its authoritative explanation before deciding how to handle it:6869 ```sh70 sh "<skill-dir>/scripts/run-tool.sh" explain --file path/to/file.py UP045 FURB12371 ```72733. Apply the guidance when it preserves intended behavior and fits the edited74 code. Do not mechanically force a diagnostic whose documented caveat applies.75764. Safe automatic fixes may be applied with:7778 ```sh79 sh "<skill-dir>/scripts/run-tool.sh" fix path/to/file.py80 ```8182 This does not enable Ruff's unsafe fixes. Use `--unsafe-fixes` only after83 explaining the behavior risk and only when the task authorizes that change.84855. Run `check` again, then run the project's formatter, type checker, and tests86 relevant to the changed code. The modernization check supplements the87 project's verification; it does not replace it.8889## Profiles9091The default `modern` post-edit profile checks92`UP,FURB,SIM,C4,PIE,PTH,FLY,PERF,F401`. Use `--profile core` for the narrower93`UP,FURB,F401` set when the task calls for a conservative modernization pass.94`F401` cleans imports made unused by safe modernization fixes. Preview rules remain95disabled unless the user or project explicitly opts into them.9697`list` intentionally loads the complete compact UP/FURB guidance before editing,98matching the proactive workflow. Keep full rule documentation progressive: call99`explain` only for IDs relevant to the planned or diagnosed code.