fix: restore Python 3.12/3.13 compatibility so import raja works on the declared minimum - #82
Open
eastagiletracker wants to merge 1 commit into
Open
Conversation
pyproject.toml declares requires-python = ">=3.12" and CI runs a 3.12/3.13 matrix, but eight except clauses used the unparenthesized multi-exception form (PEP 758), which only parses on 3.14. Installing the wheel on 3.12 raised SyntaxError from `import raja`, via enforcer.py -> scope.py. Parenthesize the exception tuples (identical semantics on 3.14) in the library and in both Lambda handlers, and let ruff infer target-version from requires-python so `poe check` stops reformatting them back to the 3.14-only form. Add tests/unit/test_python_floor.py, which parses every module under src/ and lambda_handlers/ at the declared minimum version, so the floor is enforced on whichever interpreter the suite happens to run on.
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.
This PR proposes restoring Python 3.12/3.13 compatibility, so that
import rajaworks on the interpretersrequires-pythondeclares. We include this PR work along with a full history of your repo at https://eastagiletracker.com/projects/342. You can sign in with your GitHub ID to claim ownership of the project.What is broken
pyproject.tomldeclaresrequires-python = ">=3.12", and the CI workflow's unit-test matrix listspython-version: ['3.12', '3.13']. On both of those interpreters the package cannot be imported at all: eightexceptclauses use the unparenthesized multi-exception form (except ClientError, BotoCoreError:), which is PEP 758 syntax and only parses on Python 3.14. Four of them are in code you ship —src/raja/scope.py,src/raja/datazone/service.py— and the rest are inlambda_handlers/rale_authorizer/handler.pyandlambda_handlers/rale_router/handler.py. Becausesrc/raja/__init__.pyre-exportsparse_scope/is_subsetthroughenforcer.py, the very first line of any user's script fails.Reproduced on
mainate7aa23b:The same thing happens to the test suite:
uv run --python 3.12 --extra test python -m pytest tests/unit/onmaincollects nothing and dies at the import above.Two things hide this today. The CI matrix does not actually vary the interpreter —
actions/setup-pythoninstalls 3.12/3.13, butuv syncthen builds the environment from.python-version, which has been3.14since #58, so all four matrix jobs run 3.14 and pass. And[tool.ruff] target-version = "py314", set whilerequires-pythonis>=3.12, meansruff formatactively rewrites the parenthesized form back to the 3.14-only one — running./poe checkon a corrected file undoes the correction.The change
Parenthesizing the exception tuples is semantically identical on 3.14 and restores parsing on 3.12/3.13, so no runtime behaviour changes on any supported interpreter. I also dropped the explicit
target-versionfrom[tool.ruff]; ruff then infers it fromproject.requires-python, so the formatter can never again emit syntax newer than what you support, and the setting follows automatically if you raise the floor later.tests/unit/test_python_floor.pyreads the minimum version out ofpyproject.tomland parses every module undersrc/andlambda_handlers/at that version, so the floor is enforced regardless of which interpreter the suite happens to run on.Verified before and after, from a clean checkout:
pytest tests/unit/test_python_floor.py.uv run --python 3.12 --extra test python -m pytest tests/unit/goes from a collection failure to266 passed..python-version),pytest tests/unit/goes from264 passedto266 passed— the two additions, no other movement.ruff check .reports the same four pre-existing findings underscripts/as before, andruff format --check .names exactly the same eight files as before this change (all underscripts/, none touched here).mypy src/rajaremains clean.is_subset(scope, ["not-a-scope"])still raisesScopeParseError, and exact/miss subset checks still returnTrue/False.Two related things I deliberately left alone, so this stays one change.
[tool.mypy] python_version = "3.14"is the same mismatch as the ruff setting; I checked thatpython_version = "3.12"is clean today, and I am happy to include that line if you want it. And making the CI matrix real — passing the action'spython-versioninput through touv sync --pythonin.github/actions/setup-raja— would catch this class in CI, but two dependency PRs are already open against that file, so I left it to you.How this was managed
I imported your issues and pull requests into an agile board — 79 stories — and tracked this work on it as Restore Python 3.12/3.13 compatibility, on the board at https://eastagiletracker.com/projects/342.
If you'd rather not receive contributions like this, reply
no-more-prson this pull request and we won't open any further ones on your repositories.Lawrence W. Sinclair
CEO / East Agile
linkedin.com/in/lwsinclair/
eastagile.com
Greptile Summary
This PR restores compatibility with the declared Python 3.12 minimum and adds a regression test for unsupported syntax.
project.requires-python.Confidence Score: 5/5
The PR appears safe to merge, with the compatibility fixes preserving existing exception-handling semantics and the new test covering all shipped Python sources.
The parenthesized handlers are valid across all declared interpreters, current Ruff invocations correctly infer Python 3.12 from the project metadata, and no concrete blocking or non-blocking defect remains.
Important Files Changed
Reviews (1): Last reviewed commit: "fix: restore Python 3.12/3.13 compatibil..." | Re-trigger Greptile