Summary
bearshape's predefined array-type aliases (Shaped, Bool, I8…C128, Int, Integer, Float, etc., and the *Like variants) are defined via typing.TypeAliasType(...) inside if tp.TYPE_CHECKING: blocks in bearshape/jax.py, numpy.py, torch.py, and cupy.py (e.g. jax.py:234-265):
if tp.TYPE_CHECKING:
Shaped = tp.TypeAliasType("Shaped", JaxArray, type_params=(_Dims,))
...
typing.TypeAliasType (PEP 695) was only added to the stdlib in Python 3.12. bearshape declares requires-python = ">=3.10", so this is inconsistent with the package's own supported floor: any static type checker resolving Python 3.10 or 3.11 against these modules breaks.
Reproduction
With bearshape==0.0.1 installed under Python 3.11:
pyright --pythonversion 3.11 path/to/file_using_bearshape_types.py
produces, on every line that subscripts one of these types (e.g. Shaped[Array, "N"]):
error: Variable not allowed in type expression (reportInvalidTypeForm)
Re-running with --pythonversion 3.13 produces 0 errors for the same file — confirming this is purely a Python-version resolution issue in how these aliases are declared, not a usage error on the consumer's side.
This can silently escape a project's own CI if its pyright pre-commit hook (or any pinned pyright/mypy invocation) resolves a newer interpreter than the project's declared floor — the gap only surfaces when a downstream project explicitly checks at its own minimum supported Python version.
Suggested fix
Use the standard typing_extensions backport instead of typing.TypeAliasType when targeting <3.12, e.g.:
import typing_extensions as tpe
if tp.TYPE_CHECKING:
Shaped = tpe.TypeAliasType("Shaped", JaxArray, type_params=(_Dims,))
across jax.py, numpy.py, torch.py, and cupy.py. This would need adding typing_extensions as a runtime dependency (only exercised under TYPE_CHECKING, so effectively type-checker-only, but still needs to resolve for tools like pyright/mypy) — currently bearshape only declares beartype>=0.20,<0.23.
For reference, quax hit the identical issue for a local TypeAliasType alias and fixed it the same way (swap typing.TypeAliasType → typing_extensions.TypeAliasType), which is what prompted this report.
Happy to open a PR with this change across the four modules if useful.
Summary
bearshape's predefined array-type aliases (Shaped,Bool,I8…C128,Int,Integer,Float, etc., and the*Likevariants) are defined viatyping.TypeAliasType(...)insideif tp.TYPE_CHECKING:blocks inbearshape/jax.py,numpy.py,torch.py, andcupy.py(e.g.jax.py:234-265):typing.TypeAliasType(PEP 695) was only added to the stdlib in Python 3.12.bearshapedeclaresrequires-python = ">=3.10", so this is inconsistent with the package's own supported floor: any static type checker resolving Python 3.10 or 3.11 against these modules breaks.Reproduction
With
bearshape==0.0.1installed under Python 3.11:produces, on every line that subscripts one of these types (e.g.
Shaped[Array, "N"]):Re-running with
--pythonversion 3.13produces 0 errors for the same file — confirming this is purely a Python-version resolution issue in how these aliases are declared, not a usage error on the consumer's side.This can silently escape a project's own CI if its pyright pre-commit hook (or any pinned pyright/mypy invocation) resolves a newer interpreter than the project's declared floor — the gap only surfaces when a downstream project explicitly checks at its own minimum supported Python version.
Suggested fix
Use the standard
typing_extensionsbackport instead oftyping.TypeAliasTypewhen targeting <3.12, e.g.:across
jax.py,numpy.py,torch.py, andcupy.py. This would need addingtyping_extensionsas a runtime dependency (only exercised underTYPE_CHECKING, so effectively type-checker-only, but still needs to resolve for tools like pyright/mypy) — currentlybearshapeonly declaresbeartype>=0.20,<0.23.For reference,
quaxhit the identical issue for a localTypeAliasTypealias and fixed it the same way (swaptyping.TypeAliasType→typing_extensions.TypeAliasType), which is what prompted this report.Happy to open a PR with this change across the four modules if useful.