Skip to content

chore: Python 3.15 idioms, and the 3.15 features evaluated - #23

Merged
JsNcAr merged 5 commits into
mainfrom
chore/python-3-15-idioms
Oct 15, 2026
Merged

JsNcAr merged 5 commits into
mainfrom
chore/python-3-15-idioms

Conversation

@JsNcAr

@JsNcAr JsNcAr commented Oct 14, 2026

Copy link
Copy Markdown
Owner

The move to 3.15 (#19 to #22) changed no source line. This PR makes the code read like a 3.15 project and records, as #14 did for 3.14, which 3.15 features were considered and why each was adopted or left aside. One commit per topic.

Adopted

  • frozendict (PEP 814) for the four module-level mappings that are only read: _SECRET_MINIMUM_BYTES, _TAKEN_MESSAGES, _DESCRIPTIONS and the release script's SECTIONS. They are Mappings, so .get, .values() and subscripting are unchanged; a stray assignment is now a TypeError. mypy 2.4, flake8 and black all know the builtin.
  • collections.abc aliases: AsyncGenerator[AsyncSession] with the single parameter 3.13+ allows, in database.py and tests/conftest.py, instead of typing's deprecated spelling.
  • re.prefixmatch: 3.15's explicit name for match, which it soft-deprecates, in the three scripts/release.py call sites. Same behaviour.
  • Explicit UTF-8 (PEP 686): UTF-8 is now the default encoding, and the PEP's advice is to name it anyway. Every read_text, write_text and subprocess.run(text=True) in scripts/release.py and its test passes encoding="utf-8". python -X warn_default_encoding -W error::EncodingWarning is clean for the app import and the pure test set, and this is what found the call sites.
  • from __future__ import annotations removed from the release script, redundant since 3.14's deferred annotations.
  • Setup guide: the 3.15 sampling profiler (profiling.sampling, Tachyon) next to the asyncio introspection commands, in dump, attach and run form with --async-aware, plus the fact that decides whether it works: reading another process's memory needs ptrace permission on Linux, which run avoids by starting the server as its child. Tried here: run works unprivileged, dump on a sibling is refused with the default ptrace_scope=1.
  • AGENTS.md typing rule updated; changelog entry under Changed.

Evaluated and left unused (recorded in the changelog)

Lazy imports (PEP 810; the server imports everything at startup, the release script starts in milliseconds), sentinel (no sentinel pattern), unpacking in comprehensions (nothing to flatten), TaskGroup.cancel (no task groups), TypedDict closed and TypeForm (no TypedDicts), free-threading and the JIT (nothing CPU-bound). Also checked and needing nothing: the 3.15 removals (the suite already ran with -W error), and importlib.metadata.MetadataNotFound, which config._package_version does not need to catch.

Verification, local on Python 3.15.0 with PostgreSQL 17

black, flake8, mypy clean; encoding audit clean; scripts/release.py version and check-version v0.1.0 work; full suite, 140 passed, with -W error.

🤖 Generated with Claude Code

JsNcAr and others added 5 commits October 14, 2026 12:23
AsyncGenerator comes from collections.abc with the single type parameter
3.13+ allows; typing's alias is the deprecated spelling. scripts/release.py
drops `from __future__ import annotations`, redundant since 3.14's deferred
annotations, and uses re.prefixmatch, the explicit name 3.15 adds for match,
which it soft-deprecates. No behaviour change. AGENTS.md records the rules.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Python 3.15's frozendict builtin for the four module-level mappings that are
only read: _SECRET_MINIMUM_BYTES (config), _TAKEN_MESSAGES (services.users),
_DESCRIPTIONS (schemas.errors) and SECTIONS (scripts/release.py). They are
Mappings, so .get, .values() and subscripting are unchanged; a stray
assignment is now a TypeError instead of a silent edit.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
scripts/release.py and its test decoded git and poetry output and read or
wrote pyproject.toml and CHANGELOG.md with the default encoding. Python 3.15
makes UTF-8 that default (PEP 686) and advises naming it; every read_text,
write_text and subprocess.run(text=True) now passes encoding="utf-8", and
`python -X warn_default_encoding -W error::EncodingWarning` is clean for the
app import and the pure test set.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
profiling.sampling (Tachyon) in dump, attach and run form with --async-aware,
and the one fact that decides whether it works: reading another process's
memory needs ptrace permission on Linux (scope 0, root or CAP_SYS_PTRACE),
which `run` avoids by starting the server as its child. Tried on this
machine: run works unprivileged, dump on a sibling is refused with
ptrace_scope=1, as the text says.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…23)

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@JsNcAr
JsNcAr merged commit f99808c into main Oct 15, 2026
2 checks passed
@JsNcAr
JsNcAr deleted the chore/python-3-15-idioms branch October 15, 2026 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant