Skip to content

python: make PEP 585/604 annotations parse on 3.8 and 3.9#70

Open
congwang-mk wants to merge 1 commit into
mainfrom
python-future-annotations
Open

python: make PEP 585/604 annotations parse on 3.8 and 3.9#70
congwang-mk wants to merge 1 commit into
mainfrom
python-future-annotations

Conversation

@congwang-mk
Copy link
Copy Markdown
Contributor

Summary

pyproject.toml declares requires-python = ">=3.8", but the source and tests use PEP 604 (str | None) and PEP 585 (dict[str, int]) annotations at module load time, which only parse on 3.10+ and 3.9+ respectively. Any import sandlock on 3.8/3.9 crashed at collection. The 3.10/3.11/3.12 CI matrix hid it.

Add from __future__ import annotations to every file that uses the modern syntax and isn't already shimmed (16 files: one src module, the rest tests). PEP 563 postpones annotation evaluation to runtime lookups, so the literal str | None and dict[str, int] parse fine on every supported version. Verified no runtime usage of these forms (no isinstance(x, str | None), no typing.cast, no typing.get_type_hints) so the future import alone is sufficient.

Test plan

  • Python 3.8: python3 -m pytest tests/ (319 / 321 pass; the 2 failures are pre-existing: optional mcp extra missing, and a sub-sandbox PYTHONPATH quirk, both unrelated to the syntax change)
  • Python 3.9: same — 296 / 297 pass with the same single pre-existing failure.
  • Module imports cleanly on both versions: python3.8 -c "import sandlock" and python3.9 -c "import sandlock" succeed.

🤖 Generated with Claude Code

… work on 3.8

Signed-off-by: Cong Wang <cwang@multikernel.io>
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