agentleFS
Phaedra-SolutionsPhaedra-Solutions/cursor-rules/skills/upgrade-python/SKILL.md

upgrade-python

Skill4 starsChanged 10 days agoMITView on GitHub

Upgrade a project's Python version one minor release at a time (for example 3.10 → 3.11 → 3.12 → 3.13) with pyupgrade, deprecation warnings treated as errors, dependency re-locking, C-extension checks and every pin (requires-python, .python-version, Docker, CI, deploy runtimes) updated together, then verify with tests and a production-image smoke test. Also covers starting a Python 2.7 port. Use when asked to upgrade Python, when legacy/python-legacy applies (3.10 reached EOL on 1 Oct 2026), or when a dependency needs a newer Python.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

7 rules. About 0 are common, 5 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Surface the next version's breakage now: run the tests with warnings as errors on the current version:

    line 32
  2. Distinctive:

    update packages without wheels for the new version, or replace unmaintained ones.

    line 42
  3. Very specific:

    run pyupgrade --py311-plus $(git ls-files '*.py') (match the flag to the new minimum: --py312-plus, --py313-plus, --py314-plus) and review …

    line 43
  4. Distinctive:

    Never jump several minor versions at once when C extensions or old frameworks are involved.

    line 72
  5. Distinctive:

    Never silence deprecation warnings globally to make tests pass.

    line 73
  6. Distinctive:

    Never leave pins out of sync between local, CI and production.

    line 74
  7. Very specific:

    Never auto-commit, push or deploy.

    line 75

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Upgrade Python

When to use

  • The user asks to upgrade Python, or the project runs an EOL version (3.10 or older; see legacy/python-legacy).
  • A dependency upgrade (Django 6.x, SQLAlchemy 2.1, Starlette 1.x) needs a newer Python.
  • Planning ahead: 3.11 reaches EOL in Oct 2027.

Before you start

  • List every place that pins Python: requires-python, .python-version, runtime.txt, tox.ini/noxfile.py, setup.cfg classifiers, Dockerfiles (FROM python:…), CI matrices, serverless/PaaS runtimes, and type-checker settings (pythonVersion, python_version).
  • List C-extension and binary dependencies (numpy, pandas, psycopg, cryptography, lxml, grpcio, pydantic-core, anything without wheels for the target).
  • Working tree clean; new branch (chore/python-3.13).
  • Ask the user:
    • the target: 3.13 (security support to Oct 2029; most compatible) or 3.14 (bugfix, to Oct 2030). 3.15 (Oct 2026) is fine for new work once dependencies publish wheels;
    • whether to stop for review after each minor hop;
    • whether network installs are approved (core/supply-chain cooldown applies).

Steps

  1. Baseline on the current version: locked install, lint, type check, tests, and the production image starting. Record failures first.
  2. Surface the next version's breakage now: run the tests with warnings as errors on the current version:

    uv run python -W error::DeprecationWarning -W error::PendingDeprecationWarning -m pytest

    Fix each warning (or record it with the owning dependency) before changing versions.

  3. Hop one minor version (for example 3.10 → 3.11):
    • install it (uv python install 3.11) and update all pins in one change (requires-python = ">=3.11", .python-version, Docker base image by digest, CI, runtimes, type-checker version);
    • re-lock (uv lock --upgrade-package <only what's needed> or a full uv lock if the user agrees) and sync;
    • update packages without wheels for the new version, or replace unmaintained ones;
    • run pyupgrade --py311-plus $(git ls-files '*.py') (match the flag to the new minimum: --py312-plus, --py313-plus, --py314-plus) and review the diff; Ruff's UP rules with target-version do the same.
  4. Fix version-specific changes listed in that version's "What's New" (Porting section). Common ones:
    • 3.11: asyncio.coroutine removed; stricter enum and typing behavior;
    • 3.12: distutils removed (use setuptools/packaging); imp removed; datetime.utcnow() deprecated (use datetime.now(UTC));
    • 3.13: dead batteries removed (cgi, crypt, telnetlib, nntplib, imghdr, pipes, …); locale.getdefaultlocale deprecated;
    • 3.14: deferred evaluation of annotations by default; asyncio child-watcher APIs removed.
  5. Verify (next section). Show the diff and results; wait for approval before the next hop. Commit only when asked (git-commit skill).
  6. Repeat until the target, then switch to languages/python and update the frameworks' version rules if needed.

Python 2.7

Port before upgrading: get a test suite running, run python -m pyupgrade --py3-plus after a 2→3 conversion pass (python-future's futurize or manual), fix bytes/str boundaries and integer division, then follow the steps above from 3.x. Plan this as its own project with the user.

Verify

uv run python --version                 # the hop's target, on every runner
uv sync --locked
uv run ruff check . && uv run ruff format --check .
uv run pyright                          # or: mypy
uv run python -W error::DeprecationWarning -m pytest
uv run pip-audit
grep -rnE "python_requires|requires-python|FROM python:|python-version|pythonVersion" pyproject.toml setup.cfg Dockerfile* .github/ .python-version 2>/dev/null   # no old pins left

Then build and start the production image: imports of C extensions succeed, the app serves key routes, workers and scheduled jobs start.

Safety

  • Never jump several minor versions at once when C extensions or old frameworks are involved; never upgrade Python and a framework major in one change.
  • Never silence deprecation warnings globally to make tests pass; fix or document them.
  • Never leave pins out of sync between local, CI and production.
  • Never auto-commit, push or deploy; don't hand-edit uv.lock; ask before a full re-lock.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.