Use typing_extensions backports so array aliases resolve on Python 3.10/3.11 - #10
Open
nstarman wants to merge 1 commit into
Open
Use typing_extensions backports so array aliases resolve on Python 3.10/3.11#10nstarman wants to merge 1 commit into
nstarman wants to merge 1 commit into
Conversation
…0/3.11 The predefined array aliases in bearshape.jax/numpy/torch/cupy were built with typing.TypeAliasType (3.12+) and typing.TypeVarTuple (3.11+), while the package declares requires-python = ">=3.10". Any checker resolving 3.10 or 3.11 reported "Variable not allowed in type expression" on every subscript of Shaped, F32, IntLike, and friends. Switch those aliases to the typing_extensions backports, and do the same for typing.Self in bearshape.cupy and typing.Never in bearshape._dimensions, which are 3.11+ and fail at the declared floor for the same reason. Add typing_extensions>=4.6 as a runtime dependency. Fixes acecchini#9 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Fixes #9.
Problem
The predefined array aliases in
bearshape/{jax,numpy,torch,cupy}.pyare built withtyping.TypeAliasType, added in Python 3.12, andtyping.TypeVarTuple, added in 3.11 — but the package declaresrequires-python = ">=3.10". Any checker resolving 3.10 or 3.11 fails on every subscript ofShaped,F32,IntLike, and friends.Two more constructs hit the same wall at the declared floor:
typing.Selfinbearshape/cupy.py(3.11+) andtyping.Neverinbearshape/_dimensions.py(3.11+). Fixing onlyTypeAliasTypewould leave the aliases still broken at 3.10, so this PR covers all four.The gap is invisible to CI today because
[tool.pyright],[tool.mypy], andty.tomlall pin 3.12, and the tox typecheck envs arepy313only.Change
TypeAliasType,TypeVarTuple,Self, andNeverfromtyping_extensionsin the five affected modules.typing_extensions>=4.6todependencies(the version that introducedTypeAliasType) and touv.lock. It is already an installed transitive dependency in the dev environment.CHANGELOG.mdentry.The rest of the diff is
ruff formatreflowing lines whose length changed with the import style; no other behavior is touched. Runtime behavior is unchanged — every touched name is used only in annotations or underTYPE_CHECKING.Verification
Before, on
main:--pythonversionAfter:
uv run pytest -n auto→ 1064 passed, 5 skipped (CuPy and platform-specific longdouble skips).uv run prek run -aanduv lock --checkclean.Suggested follow-up (not in this PR)
Nothing stops this from regressing, since the checkers are configured at 3.12/3.13 rather than the declared floor. Setting
pythonVersion/python_version/python-versionto"3.10"inpyproject.tomlandty.tomlmakes CI check the floor — all three checkers pass at 3.10 with this branch, so it would be a green change today. I left it out because pinning checker targets is a maintainer policy call; happy to add it here or in a separate PR if you want it.🤖 Generated with Claude Code