modern-python-guidance 0.3.1__tar.gz → 0.3.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/CHANGELOG.md +15 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/CONTRIBUTING.md +1 -1
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/PKG-INFO +6 -6
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/README.md +5 -5
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/docs/design.md +1 -1
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/pyproject.toml +1 -1
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/skills/modern-python-guidance/SKILL.md +3 -3
- modern_python_guidance-0.3.2/skills/modern-python-guidance/guides/stdlib/template-strings.md +70 -0
- modern_python_guidance-0.3.2/skills/modern-python-guidance/guides/typing/deferred-annotations.md +63 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/src/modern_python_guidance/__init__.py +1 -1
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/src/modern_python_guidance/mcp_server.py +4 -4
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/src/modern_python_guidance/setup_cmd.py +3 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/tests/test_setup.py +16 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/tests/test_skill_sync.py +6 -6
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/.github/workflows/ci.yml +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/.github/workflows/publish.yml +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/.gitignore +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/LICENSE +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/LICENSE-MIT +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/SECURITY.md +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/bench/fixtures/variant-a-modern/pyproject.toml +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/bench/fixtures/variant-a-modern/src/app.py +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/bench/fixtures/variant-a-modern/src/config.py +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/bench/fixtures/variant-a-modern/src/crawler.py +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/bench/fixtures/variant-a-modern/src/models.py +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/bench/fixtures/variant-a-modern/src/scanner.py +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/bench/fixtures/variant-a-modern/src/utils.py +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/bench/fixtures/variant-a-outdated/pyproject.toml +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/bench/fixtures/variant-a-outdated/setup.py +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/bench/fixtures/variant-a-outdated/src/app.py +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/bench/fixtures/variant-a-outdated/src/config.py +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/bench/fixtures/variant-a-outdated/src/crawler.py +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/bench/fixtures/variant-a-outdated/src/models.py +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/bench/fixtures/variant-a-outdated/src/scanner.py +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/bench/fixtures/variant-a-outdated/src/utils.py +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/bench/fixtures/variant-b-modern/myapp/models.py +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/bench/fixtures/variant-b-modern/myapp/views.py +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/bench/fixtures/variant-b-outdated/myapp/models.py +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/bench/fixtures/variant-b-outdated/myapp/views.py +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/bench/fixtures/variant-c-modern/tests/test_calculator.py +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/bench/fixtures/variant-c-outdated/tests/test_calculator.py +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/bench/mcp-config.json +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/bench/prompt-v2.txt +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/bench/prompt-v3-mcp.txt +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/bench/prompt-v3.txt +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/bench/prompt-v4-a.txt +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/bench/prompt-v4-b.txt +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/bench/prompt-v4-c.txt +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/bench/prompt.txt +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/bench/run-mcp.sh +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/bench/run-v4.sh +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/bench/run.sh +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/bench/score-v2.sh +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/bench/score-v3.sh +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/bench/score-v4.sh +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/bench/score.sh +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/bench/test-scorer.sh +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/docs/benchmark-evaluation.md +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/docs/benchmark-procedure.md +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/skills/modern-python-guidance/guides/async/async-timeout-context.md +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/skills/modern-python-guidance/guides/async/exception-groups.md +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/skills/modern-python-guidance/guides/async/taskgroup-over-gather.md +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/skills/modern-python-guidance/guides/data-structures/dataclass-modern.md +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/skills/modern-python-guidance/guides/data-structures/dict-merge-operator.md +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/skills/modern-python-guidance/guides/data-structures/match-case-patterns.md +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/skills/modern-python-guidance/guides/django/django-async-views.md +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/skills/modern-python-guidance/guides/django/django-check-constraints.md +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/skills/modern-python-guidance/guides/django/django-json-field.md +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/skills/modern-python-guidance/guides/fastapi/fastapi-annotated-depends.md +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/skills/modern-python-guidance/guides/fastapi/fastapi-lifespan.md +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/skills/modern-python-guidance/guides/fastapi/fastapi-typed-state.md +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/skills/modern-python-guidance/guides/httpx/httpx-async-client-reuse.md +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/skills/modern-python-guidance/guides/httpx/httpx-streaming.md +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/skills/modern-python-guidance/guides/pydantic/pydantic-v2-config.md +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/skills/modern-python-guidance/guides/pydantic/pydantic-v2-model-api.md +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/skills/modern-python-guidance/guides/pydantic/pydantic-v2-serialization.md +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/skills/modern-python-guidance/guides/pydantic/pydantic-v2-validators.md +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/skills/modern-python-guidance/guides/pytest/pytest-parametrize.md +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/skills/modern-python-guidance/guides/pytest/pytest-raises-match.md +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/skills/modern-python-guidance/guides/pytest/pytest-tmp-path.md +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/skills/modern-python-guidance/guides/sqlalchemy/sqlalchemy-2-style.md +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/skills/modern-python-guidance/guides/sqlalchemy/sqlalchemy-async-session.md +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/skills/modern-python-guidance/guides/sqlalchemy/sqlalchemy-mapped-column.md +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/skills/modern-python-guidance/guides/stdlib/datetime-utc.md +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/skills/modern-python-guidance/guides/stdlib/pathlib-over-os-path.md +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/skills/modern-python-guidance/guides/stdlib/removeprefix-removesuffix.md +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/skills/modern-python-guidance/guides/stdlib/tomllib-builtin.md +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/skills/modern-python-guidance/guides/toolchain/no-pickle.md +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/skills/modern-python-guidance/guides/toolchain/pyproject-toml-over-setup.md +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/skills/modern-python-guidance/guides/toolchain/ruff-over-flake8.md +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/skills/modern-python-guidance/guides/toolchain/safe-subprocess.md +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/skills/modern-python-guidance/guides/toolchain/uv-over-pip.md +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/skills/modern-python-guidance/guides/typing/override-decorator.md +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/skills/modern-python-guidance/guides/typing/paramspec-decorators.md +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/skills/modern-python-guidance/guides/typing/type-parameter-syntax.md +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/skills/modern-python-guidance/guides/typing/typeis-vs-typeguard.md +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/skills/modern-python-guidance/guides/typing/union-syntax.md +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/skills/modern-python-guidance/guides/typing/use-builtin-generics.md +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/src/modern_python_guidance/__main__.py +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/src/modern_python_guidance/cli.py +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/src/modern_python_guidance/compat.py +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/src/modern_python_guidance/frontmatter.py +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/src/modern_python_guidance/guide_index.py +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/src/modern_python_guidance/retrieve.py +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/src/modern_python_guidance/search.py +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/src/modern_python_guidance/uninstall_cmd.py +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/src/modern_python_guidance/version_detect.py +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/tests/test_cli_integration.py +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/tests/test_frontmatter.py +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/tests/test_mcp_server.py +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/tests/test_retrieve.py +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/tests/test_search.py +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/tests/test_uninstall.py +0 -0
- {modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/tests/test_version_detect.py +0 -0
|
@@ -2,6 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [0.3.2] — 2026-05-29
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- `deferred-annotations` guide (PEP 649): drop unnecessary `from __future__ import annotations` on Python 3.14+ projects where annotations are lazily evaluated by default (closes #28)
|
|
10
|
+
- `template-strings` guide (PEP 750): use t-strings with processing functions for safe SQL/HTML parameterization instead of f-string interpolation (closes #28)
|
|
11
|
+
- Guide count: 39 → 41. Layer 1 coverage: 16 → 18
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
|
|
15
|
+
- `setup_mcp` now catches `OSError` from `subprocess.run`, matching `uninstall_mcp` behavior — an unexecutable `claude` binary produces a clean error message instead of a traceback (closes #65)
|
|
16
|
+
- MCP `retrieve_guides` schema `maxItems` and runtime guard updated from 39 to 41 to allow retrieval of all guides
|
|
17
|
+
|
|
5
18
|
## [0.3.1] — 2026-05-29
|
|
6
19
|
|
|
7
20
|
### Added
|
|
@@ -117,6 +130,8 @@ Initial release.
|
|
|
117
130
|
- Strict YAML-subset frontmatter parser (no PyYAML dependency)
|
|
118
131
|
- GitHub Actions CI (pytest + ruff on Python 3.11, 3.12, 3.13)
|
|
119
132
|
|
|
133
|
+
[0.3.2]: https://github.com/yottayoshida/modern-python-guidance/releases/tag/v0.3.2
|
|
134
|
+
[0.3.1]: https://github.com/yottayoshida/modern-python-guidance/releases/tag/v0.3.1
|
|
120
135
|
[0.3.0]: https://github.com/yottayoshida/modern-python-guidance/releases/tag/v0.3.0
|
|
121
136
|
[0.2.3]: https://github.com/yottayoshida/modern-python-guidance/releases/tag/v0.2.3
|
|
122
137
|
[0.2.2]: https://github.com/yottayoshida/modern-python-guidance/releases/tag/v0.2.2
|
|
@@ -15,7 +15,7 @@ src/modern_python_guidance/
|
|
|
15
15
|
|
|
16
16
|
skills/modern-python-guidance/
|
|
17
17
|
├── SKILL.md # Agent Skills plugin entry point
|
|
18
|
-
└── guides/ #
|
|
18
|
+
└── guides/ # 41 guide files by category
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
See [docs/design.md](docs/design.md) for the full design document.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: modern-python-guidance
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.2
|
|
4
4
|
Summary: Version-aware BAD/GOOD pattern guides that help AI coding agents generate modern Python
|
|
5
5
|
Project-URL: Homepage, https://github.com/yottayoshida/modern-python-guidance
|
|
6
6
|
Project-URL: Repository, https://github.com/yottayoshida/modern-python-guidance
|
|
@@ -36,12 +36,12 @@ Description-Content-Type: text/markdown
|
|
|
36
36
|
[](https://pypi.org/project/modern-python-guidance/)
|
|
37
37
|
[](LICENSE)
|
|
38
38
|
|
|
39
|
-
Stop your AI from writing `typing.List`, `@validator`, and `setup.py`.
|
|
39
|
+
Stop your AI from writing `typing.List`, `@validator`, and `setup.py`. 41 version-aware BAD/GOOD pattern guides that teach AI coding agents to write modern Python — delivered via MCP, CLI, or Agent Skills.
|
|
40
40
|
|
|
41
41
|
## Highlights
|
|
42
42
|
|
|
43
43
|
- **Measurable impact**: +14.7pp overall improvement in A/B benchmark via Agent Skills (38 scored items, [details](docs/benchmark-evaluation.md)). Largest variant (FastAPI, 32 items): Control 60.4% → Treatment 82.3%
|
|
44
|
-
- **
|
|
44
|
+
- **41 guides** across stdlib, Pydantic, FastAPI, Django, SQLAlchemy, pytest, and toolchain
|
|
45
45
|
- **Version-aware**: auto-detects your project's Python version and filters guides accordingly
|
|
46
46
|
- **3 delivery methods**: MCP server, CLI, Agent Skills plugin
|
|
47
47
|
- **Not Ruff**: Ruff auto-fixes syntax (`List` → `list`). mpg guides design decisions that Ruff can't touch — `TaskGroup` over `gather`, Pydantic V2 migration, SQLAlchemy 2.0 style
|
|
@@ -144,15 +144,15 @@ mpg search "typing" --format json | jq '.[0].id'
|
|
|
144
144
|
|
|
145
145
|
## Guide coverage
|
|
146
146
|
|
|
147
|
-
|
|
147
|
+
41 guides across 3 layers:
|
|
148
148
|
|
|
149
149
|
| Layer | Categories | Count | Examples |
|
|
150
150
|
|-------|-----------|-------|---------|
|
|
151
|
-
| **1 — stdlib** | typing, async, stdlib, data-structures |
|
|
151
|
+
| **1 — stdlib** | typing, async, stdlib, data-structures | 18 | `list` over `List`, `match`/`case`, `TaskGroup`, deferred annotations, t-strings |
|
|
152
152
|
| **2 — frameworks** | pydantic, fastapi, httpx, django, sqlalchemy, pytest | 18 | Pydantic V2 migration, SQLAlchemy 2.0 style, `Annotated[Depends]` |
|
|
153
153
|
| **3 — toolchain** | toolchain | 5 | `uv` over `pip`, `ruff` over flake8, `pickle` avoidance |
|
|
154
154
|
|
|
155
|
-
Run `mpg list` to see all
|
|
155
|
+
Run `mpg list` to see all 41 guides, or [browse them on GitHub](skills/modern-python-guidance/guides/).
|
|
156
156
|
|
|
157
157
|
## Version-aware filtering
|
|
158
158
|
|
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
[](https://pypi.org/project/modern-python-guidance/)
|
|
6
6
|
[](LICENSE)
|
|
7
7
|
|
|
8
|
-
Stop your AI from writing `typing.List`, `@validator`, and `setup.py`.
|
|
8
|
+
Stop your AI from writing `typing.List`, `@validator`, and `setup.py`. 41 version-aware BAD/GOOD pattern guides that teach AI coding agents to write modern Python — delivered via MCP, CLI, or Agent Skills.
|
|
9
9
|
|
|
10
10
|
## Highlights
|
|
11
11
|
|
|
12
12
|
- **Measurable impact**: +14.7pp overall improvement in A/B benchmark via Agent Skills (38 scored items, [details](docs/benchmark-evaluation.md)). Largest variant (FastAPI, 32 items): Control 60.4% → Treatment 82.3%
|
|
13
|
-
- **
|
|
13
|
+
- **41 guides** across stdlib, Pydantic, FastAPI, Django, SQLAlchemy, pytest, and toolchain
|
|
14
14
|
- **Version-aware**: auto-detects your project's Python version and filters guides accordingly
|
|
15
15
|
- **3 delivery methods**: MCP server, CLI, Agent Skills plugin
|
|
16
16
|
- **Not Ruff**: Ruff auto-fixes syntax (`List` → `list`). mpg guides design decisions that Ruff can't touch — `TaskGroup` over `gather`, Pydantic V2 migration, SQLAlchemy 2.0 style
|
|
@@ -113,15 +113,15 @@ mpg search "typing" --format json | jq '.[0].id'
|
|
|
113
113
|
|
|
114
114
|
## Guide coverage
|
|
115
115
|
|
|
116
|
-
|
|
116
|
+
41 guides across 3 layers:
|
|
117
117
|
|
|
118
118
|
| Layer | Categories | Count | Examples |
|
|
119
119
|
|-------|-----------|-------|---------|
|
|
120
|
-
| **1 — stdlib** | typing, async, stdlib, data-structures |
|
|
120
|
+
| **1 — stdlib** | typing, async, stdlib, data-structures | 18 | `list` over `List`, `match`/`case`, `TaskGroup`, deferred annotations, t-strings |
|
|
121
121
|
| **2 — frameworks** | pydantic, fastapi, httpx, django, sqlalchemy, pytest | 18 | Pydantic V2 migration, SQLAlchemy 2.0 style, `Annotated[Depends]` |
|
|
122
122
|
| **3 — toolchain** | toolchain | 5 | `uv` over `pip`, `ruff` over flake8, `pickle` avoidance |
|
|
123
123
|
|
|
124
|
-
Run `mpg list` to see all
|
|
124
|
+
Run `mpg list` to see all 41 guides, or [browse them on GitHub](skills/modern-python-guidance/guides/).
|
|
125
125
|
|
|
126
126
|
## Version-aware filtering
|
|
127
127
|
|
|
@@ -52,7 +52,7 @@ LLMs frequently generate outdated Python patterns: `typing.List` instead of `lis
|
|
|
52
52
|
│ typing/ async/ stdlib/ data-structures/ │
|
|
53
53
|
│ pydantic/ fastapi/ httpx/ toolchain/ │
|
|
54
54
|
│ django/ sqlalchemy/ pytest/ │
|
|
55
|
-
│ (
|
|
55
|
+
│ (41 guide files) │
|
|
56
56
|
└─────────────────────────────────────────────────────────┘
|
|
57
57
|
```
|
|
58
58
|
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "modern-python-guidance"
|
|
7
|
-
version = "0.3.
|
|
7
|
+
version = "0.3.2"
|
|
8
8
|
description = "Version-aware BAD/GOOD pattern guides that help AI coding agents generate modern Python"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "Apache-2.0 OR MIT"
|
{modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/skills/modern-python-guidance/SKILL.md
RENAMED
|
@@ -55,11 +55,11 @@ Pre-generation design patterns that Ruff cannot auto-fix. Apply these transforma
|
|
|
55
55
|
- `subprocess.run(f"cmd {arg}", shell=True)` → `subprocess.run(["cmd", arg], check=True)`
|
|
56
56
|
- Caveat: `shell=True` is valid when pipes/globs are needed; use `shlex.quote()` for user input
|
|
57
57
|
|
|
58
|
-
## All
|
|
58
|
+
## All 41 guides by category
|
|
59
59
|
|
|
60
|
-
- **typing** (
|
|
60
|
+
- **typing** (7): `use-builtin-generics`, `union-syntax`, `type-parameter-syntax`, `override-decorator`, `typeis-vs-typeguard`, `paramspec-decorators`, `deferred-annotations`
|
|
61
61
|
- **async** (3): `taskgroup-over-gather`, `exception-groups`, `async-timeout-context`
|
|
62
|
-
- **stdlib** (
|
|
62
|
+
- **stdlib** (5): `datetime-utc`, `pathlib-over-os-path`, `tomllib-builtin`, `removeprefix-removesuffix`, `template-strings`
|
|
63
63
|
- **data-structures** (3): `dict-merge-operator`, `match-case-patterns`, `dataclass-modern`
|
|
64
64
|
- **pydantic** (4): `pydantic-v2-validators`, `pydantic-v2-config`, `pydantic-v2-model-api`, `pydantic-v2-serialization`
|
|
65
65
|
- **fastapi** (3): `fastapi-lifespan`, `fastapi-annotated-depends`, `fastapi-typed-state`
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: template-strings
|
|
3
|
+
title: Use Template Strings (t-strings) for Structured String Processing
|
|
4
|
+
category: stdlib
|
|
5
|
+
layer: 1
|
|
6
|
+
tags:
|
|
7
|
+
- strings
|
|
8
|
+
- templates
|
|
9
|
+
- security
|
|
10
|
+
- sql
|
|
11
|
+
aliases:
|
|
12
|
+
- t-string
|
|
13
|
+
- 't"'
|
|
14
|
+
- Template
|
|
15
|
+
- string.templatelib
|
|
16
|
+
python: ">=3.14"
|
|
17
|
+
frequency: medium
|
|
18
|
+
pep: 750
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
# Use Template Strings for Structured String Processing
|
|
22
|
+
|
|
23
|
+
Python 3.14 introduces t-strings (PEP 750): a `t"..."` prefix that produces a `Template` object instead of a `str`. Pass the `Template` to a processing function that separates literal text from interpolated values, enabling safe parameterization for SQL, HTML, shell commands, and other injection-sensitive contexts.
|
|
24
|
+
|
|
25
|
+
## BAD
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
def query_user(db, user_id: str) -> dict:
|
|
29
|
+
sql = f"SELECT * FROM users WHERE id = '{user_id}'"
|
|
30
|
+
return db.execute(sql).fetchone()
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## GOOD
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
from string.templatelib import Interpolation
|
|
37
|
+
|
|
38
|
+
def sql(template) -> tuple[str, list]:
|
|
39
|
+
parts, params = [], []
|
|
40
|
+
for item in template:
|
|
41
|
+
if isinstance(item, Interpolation):
|
|
42
|
+
parts.append("?")
|
|
43
|
+
params.append(item.value)
|
|
44
|
+
else:
|
|
45
|
+
parts.append(item)
|
|
46
|
+
return "".join(parts), params
|
|
47
|
+
|
|
48
|
+
def query_user(db, user_id: str) -> dict:
|
|
49
|
+
query, params = sql(t"SELECT * FROM users WHERE id = {user_id}")
|
|
50
|
+
return db.execute(query, params).fetchone()
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Why
|
|
54
|
+
|
|
55
|
+
- f-strings produce a final `str` with interpolated values already baked in, making it impossible to distinguish user input from literal SQL after the fact
|
|
56
|
+
- t-strings produce a `Template` that preserves the structure: literal segments as strings, interpolated values as `Interpolation` objects with `value`, `expression`, `conversion`, and `format_spec` attributes
|
|
57
|
+
- A processing function can then route each interpolated value through proper escaping or parameterization, preventing injection by construction
|
|
58
|
+
- t-strings do NOT make strings safe by themselves -- safety comes entirely from the processing function that receives the `Template`
|
|
59
|
+
|
|
60
|
+
## Version Notes
|
|
61
|
+
|
|
62
|
+
- 3.14+: `t"..."` syntax and `string.templatelib` module (`Template`, `Interpolation`)
|
|
63
|
+
- Pre-3.14: Use parameterized queries directly (`db.execute("SELECT ... WHERE id = ?", [user_id])`) or template engines with auto-escaping
|
|
64
|
+
- For simple string formatting where injection is not a concern, f-strings remain the appropriate choice
|
|
65
|
+
- `Template` objects do not render to `str` automatically -- a processing function is always required
|
|
66
|
+
|
|
67
|
+
## References
|
|
68
|
+
|
|
69
|
+
- [PEP 750 -- Template Strings](https://peps.python.org/pep-0750/)
|
|
70
|
+
- [string.templatelib documentation](https://docs.python.org/3/library/string.templatelib.html)
|
modern_python_guidance-0.3.2/skills/modern-python-guidance/guides/typing/deferred-annotations.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: deferred-annotations
|
|
3
|
+
title: 'Drop "from __future__ import annotations" on Python 3.14+'
|
|
4
|
+
category: typing
|
|
5
|
+
layer: 1
|
|
6
|
+
tags:
|
|
7
|
+
- type-hints
|
|
8
|
+
- annotations
|
|
9
|
+
- forward-reference
|
|
10
|
+
aliases:
|
|
11
|
+
- "from __future__ import annotations"
|
|
12
|
+
- "__future__.annotations"
|
|
13
|
+
- ForwardRef
|
|
14
|
+
python: ">=3.14"
|
|
15
|
+
frequency: high
|
|
16
|
+
pep: 649
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
# Drop `from __future__ import annotations` on Python 3.14+
|
|
20
|
+
|
|
21
|
+
On Python 3.14+, annotations are lazily evaluated by default (PEP 649). The `from __future__ import annotations` import is no longer needed for forward references in 3.14-only projects.
|
|
22
|
+
|
|
23
|
+
## BAD
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
from __future__ import annotations
|
|
27
|
+
|
|
28
|
+
class Tree:
|
|
29
|
+
left: Tree | None = None
|
|
30
|
+
right: Tree | None = None
|
|
31
|
+
|
|
32
|
+
def children(self) -> list[Tree]:
|
|
33
|
+
return [c for c in (self.left, self.right) if c]
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## GOOD
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
class Tree:
|
|
40
|
+
left: Tree | None = None
|
|
41
|
+
right: Tree | None = None
|
|
42
|
+
|
|
43
|
+
def children(self) -> list[Tree]:
|
|
44
|
+
return [c for c in (self.left, self.right) if c]
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Why
|
|
48
|
+
|
|
49
|
+
- Python 3.14 evaluates annotations lazily by default, so forward references like `Tree` inside the `Tree` class body just work
|
|
50
|
+
- The future import forces all-string semantics (PEP 563), which is different from 3.14's lazy evaluation and can interact poorly with runtime annotation consumers
|
|
51
|
+
- Removing the unnecessary import keeps the module cleaner and avoids the subtle behavioral difference between stringified and lazily-evaluated annotations
|
|
52
|
+
|
|
53
|
+
## Version Notes
|
|
54
|
+
|
|
55
|
+
- 3.14+: Annotations are lazily evaluated by default. Remove `from __future__ import annotations` in 3.14-only projects
|
|
56
|
+
- Pre-3.14: The future import remains the correct way to enable string annotations for forward references
|
|
57
|
+
- `from __future__ import annotations` is deprecated but NOT removed in 3.14. It still works but forces all-string semantics. Removal is not expected before Python 3.13 EOL (~2029)
|
|
58
|
+
- Libraries that read annotations at runtime (`typing.get_type_hints()`, Pydantic, FastAPI, attrs) may need updates for 3.14's lazy evaluation. Verify library compatibility before removing the import in projects that depend on runtime annotation inspection
|
|
59
|
+
|
|
60
|
+
## References
|
|
61
|
+
|
|
62
|
+
- [PEP 649 -- Deferred Evaluation of Annotations Using Descriptors](https://peps.python.org/pep-0649/)
|
|
63
|
+
- [PEP 749 -- Implementing PEP 649](https://peps.python.org/pep-0749/)
|
|
@@ -121,8 +121,8 @@ TOOLS = [
|
|
|
121
121
|
"guide_ids": {
|
|
122
122
|
"type": "array",
|
|
123
123
|
"items": {"type": "string"},
|
|
124
|
-
"description": "Guide IDs to retrieve (max
|
|
125
|
-
"maxItems":
|
|
124
|
+
"description": "Guide IDs to retrieve (max 41)",
|
|
125
|
+
"maxItems": 41,
|
|
126
126
|
},
|
|
127
127
|
"python_version": {
|
|
128
128
|
"type": "string",
|
|
@@ -269,8 +269,8 @@ def _tool_retrieve(arguments: dict) -> dict:
|
|
|
269
269
|
guide_ids = arguments.get("guide_ids", [])
|
|
270
270
|
if not guide_ids:
|
|
271
271
|
return _tool_result("guide_ids is required and must not be empty", is_error=True)
|
|
272
|
-
if len(guide_ids) >
|
|
273
|
-
return _tool_result("guide_ids exceeds maximum of
|
|
272
|
+
if len(guide_ids) > 41:
|
|
273
|
+
return _tool_result("guide_ids exceeds maximum of 41", is_error=True)
|
|
274
274
|
|
|
275
275
|
pv = arguments.get("python_version")
|
|
276
276
|
err = _validate_python_version(pv)
|
|
@@ -92,6 +92,9 @@ def setup_mcp(
|
|
|
92
92
|
except subprocess.TimeoutExpired:
|
|
93
93
|
print("Error: 'claude mcp add' timed out after 30 seconds.", file=sys.stderr)
|
|
94
94
|
return False
|
|
95
|
+
except OSError as e:
|
|
96
|
+
print(f"Error: failed to run 'claude mcp add': {e}", file=sys.stderr)
|
|
97
|
+
return False
|
|
95
98
|
|
|
96
99
|
if result.returncode != 0:
|
|
97
100
|
stderr_text = result.stderr.decode(errors="replace").strip()
|
|
@@ -131,6 +131,22 @@ class TestSetupMcp:
|
|
|
131
131
|
assert ok is False
|
|
132
132
|
assert "failed" in capsys.readouterr().err
|
|
133
133
|
|
|
134
|
+
def test_oserror_fails_gracefully(self, capsys: pytest.CaptureFixture[str]):
|
|
135
|
+
"""V-036: claude on PATH but unexecutable (OSError) -> failure, no traceback."""
|
|
136
|
+
with (
|
|
137
|
+
patch(
|
|
138
|
+
"modern_python_guidance.setup_cmd.shutil.which",
|
|
139
|
+
return_value="/usr/bin/claude",
|
|
140
|
+
),
|
|
141
|
+
patch(
|
|
142
|
+
"modern_python_guidance.setup_cmd.subprocess.run",
|
|
143
|
+
side_effect=OSError("Exec format error"),
|
|
144
|
+
),
|
|
145
|
+
):
|
|
146
|
+
ok = setup_mcp()
|
|
147
|
+
assert ok is False
|
|
148
|
+
assert "failed to run" in capsys.readouterr().err
|
|
149
|
+
|
|
134
150
|
def test_dry_run(self, capsys: pytest.CaptureFixture[str]):
|
|
135
151
|
"""V-010: dry-run does not invoke subprocess."""
|
|
136
152
|
with (
|
|
@@ -66,12 +66,12 @@ class TestV001SkillGuideSync:
|
|
|
66
66
|
)
|
|
67
67
|
|
|
68
68
|
def test_catalog_heading_exists(self, skill_text):
|
|
69
|
-
assert "## All
|
|
69
|
+
assert "## All 41 guides by category" in skill_text, (
|
|
70
70
|
"Catalog heading missing from SKILL.md"
|
|
71
71
|
)
|
|
72
72
|
|
|
73
73
|
def test_catalog_ids_exist(self, skill_text, guide_index):
|
|
74
|
-
catalog_section = skill_text.split("## All
|
|
74
|
+
catalog_section = skill_text.split("## All 41 guides by category")[-1]
|
|
75
75
|
ids_in_catalog = _extract_backtick_ids(catalog_section)
|
|
76
76
|
for guide_id in ids_in_catalog:
|
|
77
77
|
assert guide_index.get(guide_id) is not None, (
|
|
@@ -79,14 +79,14 @@ class TestV001SkillGuideSync:
|
|
|
79
79
|
)
|
|
80
80
|
|
|
81
81
|
def test_catalog_count_matches(self, guide_index, skill_text):
|
|
82
|
-
assert "
|
|
83
|
-
assert len(guide_index) ==
|
|
84
|
-
f"SKILL.md says
|
|
82
|
+
assert "41 guides" in skill_text
|
|
83
|
+
assert len(guide_index) == 41, (
|
|
84
|
+
f"SKILL.md says 41 guides but found {len(guide_index)}"
|
|
85
85
|
)
|
|
86
86
|
|
|
87
87
|
def test_catalog_covers_all_guides(self, skill_text, guide_index):
|
|
88
88
|
"""Reverse check: every guide ID appears in the catalog section."""
|
|
89
|
-
catalog_section = skill_text.split("## All
|
|
89
|
+
catalog_section = skill_text.split("## All 41 guides by category")[-1]
|
|
90
90
|
catalog_ids = set(_extract_backtick_ids(catalog_section))
|
|
91
91
|
for guide_id in guide_index.guides:
|
|
92
92
|
assert guide_id in catalog_ids, (
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/src/modern_python_guidance/__main__.py
RENAMED
|
File without changes
|
{modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/src/modern_python_guidance/cli.py
RENAMED
|
File without changes
|
{modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/src/modern_python_guidance/compat.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/src/modern_python_guidance/retrieve.py
RENAMED
|
File without changes
|
{modern_python_guidance-0.3.1 → modern_python_guidance-0.3.2}/src/modern_python_guidance/search.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|