Skip to content

Use typing_extensions backports so array aliases resolve on Python 3.10/3.11 - #10

Open
nstarman wants to merge 1 commit into
acecchini:mainfrom
nstarman:typing-extensions-backport
Open

Use typing_extensions backports so array aliases resolve on Python 3.10/3.11#10
nstarman wants to merge 1 commit into
acecchini:mainfrom
nstarman:typing-extensions-backport

Conversation

@nstarman

@nstarman nstarman commented Aug 17, 2026

Copy link
Copy Markdown

Fixes #9.

Problem

The predefined array aliases in bearshape/{jax,numpy,torch,cupy}.py are built with typing.TypeAliasType, added in Python 3.12, and typing.TypeVarTuple, added in 3.11 — but the package declares requires-python = ">=3.10". Any checker resolving 3.10 or 3.11 fails on every subscript of Shaped, F32, IntLike, and friends.

Two more constructs hit the same wall at the declared floor: typing.Self in bearshape/cupy.py (3.11+) and typing.Never in bearshape/_dimensions.py (3.11+). Fixing only TypeAliasType would 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], and ty.toml all pin 3.12, and the tox typecheck envs are py313 only.

Change

  • Import TypeAliasType, TypeVarTuple, Self, and Never from typing_extensions in the five affected modules.
  • Add typing_extensions>=4.6 to dependencies (the version that introduced TypeAliasType) and to uv.lock. It is already an installed transitive dependency in the dev environment.
  • CHANGELOG.md entry.

The rest of the diff is ruff format reflowing 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 under TYPE_CHECKING.

Verification

Before, on main:

pyright --pythonversion errors
3.10 480
3.12 0

After:

checker 3.10 3.11 3.12 3.13 3.14
pyright 0 0 0 0 0
mypy clean clean clean
ty clean clean clean

uv run pytest -n auto → 1064 passed, 5 skipped (CuPy and platform-specific longdouble skips). uv run prek run -a and uv lock --check clean.

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-version to "3.10" in pyproject.toml and ty.toml makes 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

…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>
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.

TypeAliasType aliases (jax.py/numpy.py/torch.py/cupy.py) break pyright under Python 3.10/3.11 despite requires-python >=3.10

1 participant