python-modernization-sweep

A plan for updating an older Python codebase to use modern Python 3 syntax and type hints after support for an older interpreter has ended. It divides the work into small mechanical pull requests rather than one large change.

In plain words
What is it for?
Use it to replace older Python patterns such as explicit superclass calls and old string formatting, adopt newer generics or language features, and add type hints without introducing bug fixes.
Why use it?
A single modernization change can be difficult to review and may mix style updates with bug fixes. Splitting the work makes each change easier to check and keeps the sweep focused on syntax and annotations.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/chen3feng/agent-skills/python-modernization-sweep
Any agent
npx skills add chen3feng/agent-skills --skill python-modernization-sweep
Clone the repo
git clone --depth 1 https://github.com/chen3feng/agent-skills

Made for: Claude Code, Codex.

Per session 37 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 4,798 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00037 $0.04798
Opus 5 $0.00018 $0.02399
Sonnet 5 $0.00007 $0.00960
Haiku 4.5 $0.00004 $0.00480

Measured 2d ago against content hash 6ebb4a8a8317, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

python-modernization-sweep scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Runs shell commandslowCapability

Expected in a hook, worth knowing in a rule or an instructions file.

# PLW1510 on a subprocess.run that returns returncode.
skills/python-modernization-sweep/SKILL.md · 401 lines

How it starts

The opening of the file, as written. The whole thing — 401 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Python modernization sweep

When to use

You own a Python codebase that has just dropped support for an old interpreter (Py2, or <3.10), and you want to actually use the newer language features that dropping support unlocked: f-strings, super(), PEP 585 generics, match statements, type hints, etc.

Signals this skill applies:

  • The user says "全面拥抱 Py3 新特性", "modernize this codebase", "clean up the Py2 shim residue", or similar.
  • The repo still has super(Cls, self), class X(object):, '%s' % x, u'...' literals, IOError/EnvironmentError, etc.
  • There is no (or patchy) type-hint coverage, and the user wants to start adding hints.

This is different from [python-code-audit-sweep] (which finds latent bugs with pyflakes + grep and splits them into bug / dead-code / style PRs). A modernization sweep introduces no bug fixes; every change is either a pure AST-level rewrite or a new type annotation.

Problem

The naive approach is one giant "modernize.py" PR that does everything at once:

  • f-string rewrites for every % and .format() call (often hundreds of sites).
  • super() call modernization.
  • Dropping (object) base class.
  • Adding type hints to every public function.
  • Killing deps=[] mutable-default args.
  • Turning except IOError into except OSError.

Reviewers cannot tell what is mechanical and what is semantic. The type-hint portion alone needs slow review; the f-string portion is 300 identical rewrites that no human should read line by line. They merge into one blob, one reviewer blocks on the hardest single line, and the whole modernization stalls for weeks.

A second failure mode: guessing what's in the repo. Without a tool-assisted census, you don't know whether f-string rewrites are 20 sites or 400, whether there are 3 mutable-default anti-patterns or 167, whether super() rewrites are AST-safe or whether something is calling a sibling class's __init__ manually. Picking tools before counting is how you end up writing manual sed scripts for something pyupgrade --py310-plus would do in one command.

Read the full file on GitHub · 401 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 401 lines · 37 tokens per session scan A 6ebb4a8a8317

Subscribe to this mod's changes

python-modernization-sweep is a skill published in the GitHub repository chen3feng/agent-skills (5 stars, last pushed 3mo ago), licensed Apache-2.0. It adds 37 tokens to every session and 4,798 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 1 finding (runs shell commands). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

ruff-docs

Ruff — fast Python linter and formatter in Rust. 900+ rules, Black-compatible formatter, LSP, CI/CD.

pledgeandgrow/pledge-skills · 31 tokens

sql-reporting

Conventions and review steps for writing analytics SQL against the warehouse. Use whenever the task involves querying tables, building a report, or aggregating metrics.

apache/airflow · 34 tokens

html-ppt-hermes-cyber-terminal

OpenDesign + BYOK: choosing and wiring your own model, hands-on — cost, quality, and the routing decision. Built as a decision-grade AI literacy deck for engineers, IT, applied-AI teams.

nexu-io/open-design · 53 tokens

verify-security

安全校验关卡。自动扫描代码安全漏洞,检测危险模式,确保安全决策有文档记录。当用户提到安全扫描、漏洞检测、安全审计、代码安全、OWASP、注入检测、敏感信息泄露时使用。在新建模块、安全相关变更、攻防任务、重构完成时自动触发。.

fengshao1227/ccg-workflow · 78 tokens

development

开发语言能力索引。Python、Go、Rust、TypeScript、Java、C++、Shell。当用户提到编程、开发、代码、语言时路由到此。.

fengshao1227/ccg-workflow · 41 tokens

post-build-flow

Handles workflow verification and setup after build-workflow succeeds, or when the message contains workflow-verification-follow-up or workflow-setup-required. Load after direct builds, when verificationReadiness requires action, or on orchestrator verify/setup follow-up turns.

n8n-io/n8n · 53 tokens