python: make PEP 585/604 annotations parse on 3.8 and 3.9#70
Open
congwang-mk wants to merge 1 commit into
Open
python: make PEP 585/604 annotations parse on 3.8 and 3.9#70congwang-mk wants to merge 1 commit into
congwang-mk wants to merge 1 commit into
Conversation
… work on 3.8 Signed-off-by: Cong Wang <cwang@multikernel.io>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
pyproject.tomldeclaresrequires-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. Anyimport sandlockon 3.8/3.9 crashed at collection. The 3.10/3.11/3.12 CI matrix hid it.Add
from __future__ import annotationsto 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 literalstr | Noneanddict[str, int]parse fine on every supported version. Verified no runtime usage of these forms (noisinstance(x, str | None), notyping.cast, notyping.get_type_hints) so the future import alone is sufficient.Test plan
python3 -m pytest tests/(319 / 321 pass; the 2 failures are pre-existing: optionalmcpextra missing, and a sub-sandboxPYTHONPATHquirk, both unrelated to the syntax change)python3.8 -c "import sandlock"andpython3.9 -c "import sandlock"succeed.🤖 Generated with Claude Code