Python Modern Coding Guide
Paste the following prompt into your AI chat to install this skill:
Please follow https://skillhub.cn/install/skillhub.md to install @user_7b1db0fd/python-modern.
About this skill
Problem
Python projects often mix older syntax with inaccurate version assumptions. When an agent writes code without a clear target version, it may introduce match/case, type statements, or asyncio.TaskGroup that fail on older runtimes. It may also over-defer to legacy patterns, missing list[int], @dataclass, and tomllib.
How it works
The skill first identifies the target version from pyproject.toml, setup.cfg, Pipfile, setup.py, or .python-version, then generates code within that version ceiling. Core rules include top-level imports except for optional dependencies or circular-import workarounds, mandatory type annotations on functions and module/class variables, avoidance of from __future__ import annotations, quoted forward references, and sphinx-notypes docstrings. It prefers modern stdlib features by version, such as list[int], dict | dict, and zoneinfo for 3.9+, and ExceptionGroup, tomllib, and asyncio.TaskGroup for 3.11+.
Boundaries
This is a coding-style constraint, not a replacement for ruff, mypy, pytest, or a CI version matrix. If repository version metadata is missing, the target version must be chosen explicitly. Avoid using newer syntax in older projects, and be careful when adjusting annotation strategies for runtime-annotation-sensitive libraries.
Use Cases
- Refactor async task management in a Python 3.11 repo by replacing `create_task` and `gather` with structured concurrency.
- Add type annotations and sphinx-style docstrings to a FastAPI service while avoiding `from __future__ import annotations`.
- Review Python 3.10 branch logic and convert four or more `if/elif` conditions into `match/case` patterns.
- Update a Python 3.9 project from `typing.Dict` and `pytz` to `dict[str, int]` and `zoneinfo`.
Best For
- Engineers maintaining Python 3.9 through 3.13 backend services and requiring version-bound code from agents.
- Backend developers adding type annotations and sphinx-style docstrings to FastAPI or Pydantic projects.
- Tech leads reviewing legacy imports, annotations, and branching structure during code review.
- Maintainers replacing older patterns such as `pytz` and `typing.Dict` with modern stdlib equivalents.
Related Skills
Creates themed learning sites by generating flashcards, lessons, quizzes, index, and progress pages into a deployable website.
End-to-end mathematical optimization modeling with Gurobi and Python, covering data validation, code generation, solving, result analysis, and iterative revision.
Executes an Eversheet Web CDP login using externally supplied baseUrl, username, and password, then verifies the page reaches a logged-in home state.
Clarify product goals, user flows, pages, data, and permissions, then output an implementation-ready development prompt and lightweight spec.