Two Python branches went end-of-life within twelve months of each other: 3.9 in October 2025 and 3.10 in October 2026. That means a large share of production services are now running interpreters that receive no security patches, and many of them cannot simply be pointed at a newer binary — because the code itself still depends on modules that were removed in 3.13, on annotation semantics that changed in 3.14, or on C extensions whose wheels do not exist for the new ABI.
The version bump is the easy part. The hard part is knowing what in your codebase will break without running the full test suite forty times to find out. That is what three tools solve, from three different angles:
- vermin tells you the actual minimum Python version your code requires, per file and per line.
- pyupgrade rewrites syntax to the idioms of a newer version, automatically.
- Ruff enforces the whole thing as policy, with a target version and a rule set that fails CI.
TL;DR: Target 3.13 Today, Test Against 3.14
Ship on 3.13, keep 3.14 in the test matrix. 3.13 has mature wheel coverage for nearly every C extension and a full year of production burn-in. 3.14 is the right compile target for the next twelve months, but free-threaded builds and deferred annotations change behavior in ways that deserve a separate migration.
The practical sequence: run vermin to find your real floor, run pyupgrade to remove legacy syntax, then enforce the result with Ruff’s UP rules pinned to py313. Do it in that order — Ruff will flag syntax that pyupgrade could have fixed automatically.
What Actually Changed in 3.13 and 3.14
| Area | Change | Migration impact |
|---|---|---|
| Removed modules (3.13) | cgi, cgitb, crypt, imghdr, mailcap, nntplib, pipes, telnetlib, uu, xdrlib, aifc, audioop, chunk, sunau | Imports fail outright; find replacements before upgrading |
| Annotations (3.14) | PEP 649 deferred evaluation replaces PEP 563 behavior | Frameworks that read __annotations__ at import time must be retested |
| Free-threading (3.14) | Officially supported build, no longer experimental | Third-party C extensions must declare GIL safety |
| Template strings (3.14) | PEP 750 t'' strings | New syntax only; no forced migration |
asyncio (3.14) | Introspection and task-factory changes | Custom task factories need review |
| Standard library (3.14) | compression.zstd added | Replaces the zstandard dependency in some services |
The removed-modules row is the one that breaks deployments. telnetlib and cgi in particular show up in older internal tooling and in forked web frameworks, and there is no deprecation warning left to save you — the import simply raises ModuleNotFoundError.
Tool Comparison: pyupgrade vs vermin vs Ruff
Star counts and last-push dates were read from GitHub at publication time.
| Dimension | pyupgrade | vermin | Ruff |
|---|---|---|---|
| Repository | asottile/pyupgrade | netromdk/vermin | astral-sh/ruff |
| GitHub stars | 4,124 | 540 | 51,781 |
| Last push | 2026-11-04 | 2026-10-25 | 2026-12-04 |
| Primary job | Rewrites syntax in place | Detects minimum required version | Lints and enforces a target version |
| Modifies files | Yes | No | With --fix |
| Per-line detection | No | Yes | Via rule locations |
| CI exit code | No (it is a fixer) | Yes (--violations) | Yes |
| Coverage of removed stdlib modules | Partial | Yes | Yes (UP + PY rules) |
| Runtime cost | Seconds per thousand files | Fast, pure AST walk | Very fast, Rust core |
They are complementary, not competing. vermin answers “what version do I need”, pyupgrade answers “what can I simplify”, and Ruff answers “does this repository comply”.
Scenario Decision Matrix
| Your situation | Recommended tool | Why |
|---|---|---|
| Inherited codebase, unknown version floor | vermin | Produces a concrete minimum per file without changing code |
| Large codebase with Python 2-era idioms | pyupgrade | Mechanical rewrites are safer than manual edits |
| Enforcing a version policy across many repos | Ruff with target-version | One config, one CI step, exit codes |
| Library published to PyPI | vermin + a tox matrix | You must support the oldest version your users run |
| Internal service, single runtime | pyupgrade then Ruff | Fix once, then prevent regressions |
| Pre-commit hook | Ruff (and pyupgrade) | Both ship pre-commit hooks that run fast |
vermin: Find the Real Minimum Version
vermin walks the AST and reports the minimum Python version required by each construct it finds, including standard library imports, f-strings, walrus operators, match statements, and annotation syntax. Crucially, it reports what you actually use, not what your pyproject.toml claims.
| |
The --violations flag is what makes vermin a gate rather than a report. Set -t to the version you claim to support; if vermin finds syntax requiring something newer, the build fails and tells you exactly which file and line.
The most common surprise is a transitive annotation dependency: from __future__ import annotations hides runtime annotation evaluation, but vermin still counts the syntax used inside those annotations. That is correct behavior — a library consumer on an older interpreter will parse the same file.
pyupgrade: Mechanical Syntax Rewrites
pyupgrade rewrites your code to use the idioms of a target version: super() calls without arguments, f-strings instead of .format(), dict comprehensions instead of dict(...), os.path simplifications, and dozens of other transformations that are tedious to do by hand and easy to get wrong.
| |
Two rules for using it safely. First, run it on a clean working tree and commit the result as a standalone change — a pyupgrade commit mixed with feature work is impossible to review. Second, run your test suite immediately after, because a small number of rewrites change evaluation order in code that relied on it.
pyupgrade does not understand your minimum supported version for libraries. If you publish a package that still supports 3.9, --py39-plus is the correct flag; using --py313-plus will silently raise your floor.
Ruff: The Policy Engine
Ruff’s UP rule family (pyupgrade) and PYI/F/E families can enforce a target version across an entire monorepo in one config. The target-version setting changes which rules fire and which syntax Ruff considers valid, so this is where the migration becomes durable.
| |
| |
The subtlety is --unsafe-fixes. Ruff classifies some rewrites as unsafe because they can change behavior — for example, rewriting dict.keys() usage or collapsing nested if statements. Run only safe fixes automatically, and handle unsafe ones as reviewed commits.
The Migration Sequence
This is the order that minimizes wasted work:
- Inventory the fleet.
grep -rn "python_requires\|requires-python" --include=pyproject.toml --include=setup.py .tells you which repos claim which floor. Anything claiming 3.9 or 3.10 is now unsupported. - Freeze dependencies. Regenerate lockfiles on the old interpreter before upgrading, so you have a known-good reference. Then regenerate on the new interpreter and diff the resolved set.
- Check wheel availability first.
uv pip install --python 3.13 -r requirements.txt --dry-runsurfaces missing wheels before you touch code. C extensions are the long pole. - Run vermin to establish the true floor, then decide whether the library still needs to support older versions.
- Run pyupgrade as an isolated commit, then the full test suite.
- Enable Ruff
UPrules withtarget-versionset to the new baseline, and fix remaining violations. - Add the new interpreter to CI, but keep the old one for one release cycle if you publish a library.
- Update Docker base images and CI runners last, after the code passes on the new interpreter locally.
Step 3 is where most migrations stall. A service that depends on a compiled extension with no 3.13 wheel has two options: find a maintained fork, or build from source in the image. Building from source is acceptable for internal services and a maintenance burden for anything you distribute.
Pitfalls That Cost Real Time
python_requires is not the same as tested. A library declaring >=3.9 but only testing on 3.12 is effectively unsupported on 3.9. During the migration, run the matrix on the versions you claim.
Annotation evaluation order. Under PEP 649 in 3.14, annotations are evaluated lazily by default. Frameworks that inspect annotations at class creation time — dependency injection containers, ORM models, validation libraries — can see different results. Test those integrations explicitly rather than assuming the test suite covers them.
Free-threaded builds are not a drop-in. A python3.14t build without the GIL will run pure-Python code fine and may crash or silently corrupt state in C extensions that were not audited. Keep free-threaded builds in a separate CI job until every dependency declares support.
Virtualenvs do not survive the interpreter bump. Rebuild them; do not patch pyvenv.cfg. This is especially important in Docker images, where a stale venv can hide a missing system interpreter.
distutils removal fallout. Any dependency still importing distutils fails on 3.12+. The fix is usually upgrading the dependency, not shimming setuptools._distutils.
For dependency and lockfile strategy around the upgrade, see our Python dependency management comparison. If you run ASGI services, the ASGI server comparison covers which servers have 3.13 and 3.14 wheels. And when performance regressions appear after the bump, the Python profiling tools guide is the fastest way to find them.
FAQ
Is Python 3.10 really end-of-life?
Yes. Python 3.10 reached end of security support in October 2026, following 3.9 in October 2025. Both branches now receive no security patches, so any service still running them is accumulating unfixed vulnerabilities.
Should I migrate to 3.13 or 3.14?
Use 3.13 for production today: it has the broadest wheel coverage and a full year of ecosystem testing. Add 3.14 to your test matrix now and make it the default once your C extension dependencies publish audited wheels and you have validated annotation-dependent frameworks.
Does pyupgrade change my minimum supported Python version?
Only if you tell it to. The --pyXY-plus flag defines the target syntax level, so publishing a library with --py313-plus raises your floor to 3.13. Use the flag matching the oldest version you actually support.
Can vermin replace a test matrix?
No. vermin detects syntax and standard library requirements statically; it cannot catch behavioral differences, C extension ABI issues, or dependency incompatibilities. It narrows the search space, and the test matrix proves the result.
How do I find code that imports modules removed in 3.13?
ruff check --select F reports unresolved imports, and python -X importtime or a simple grep -rE "import (cgi|telnetlib|imghdr|mailcap|pipes|uu|xdrlib)" gives you the shortlist. Fix these before upgrading the interpreter, not after.
What breaks first in a typical migration?
Compiled dependencies without wheels for the new ABI, followed by removed standard library modules, then annotation-dependent frameworks under 3.14. Lockfile regeneration and a dry-run install surface the first category before any code changes.
💰 想测试你的市场判断力?我用 Polymarket 做预测市场交易——这是全球最大的预测市场平台,从大选结果到技术监管时间线,什么都可以押注。和赌博不同,这是真正的信息市场:你懂的信息越多,胜率越高。我靠预测技术相关事件的走向已经赚了不少。用我的邀请链接注册:Polymarket.com