Compare commits

...
2 Commits
Author SHA1 Message Date
Patrick Kidger 0c596ff373 Fix for non-JAX installations. 2023-05-10 17:16:42 -07:00
Patrick Kidger 7934d2afed Static typing fixes 2023-05-10 16:35:45 -07:00
3 changed files with 88 additions and 56 deletions
+55 -55
View File
@@ -69,64 +69,64 @@ elif has_jax:
# Import our dtypes # Import our dtypes
if typing.TYPE_CHECKING: if typing.TYPE_CHECKING:
# Note that `from typing_extensions import Annotated; Bool = Annotated` # Introduce an indirection so that we can `import X as X` to make it clear that
# does not work with static type checkers. `Annotated` is a typeform rather # these are public.
# than a type, meaning it cannot be assigned. from .indirection import (
from typing_extensions import ( BFloat16 as BFloat16,
Annotated as BFloat16, Bool as Bool,
Annotated as Bool, Complex as Complex,
Annotated as Complex, Complex64 as Complex64,
Annotated as Complex64, Complex128 as Complex128,
Annotated as Complex128, Float as Float,
Annotated as Float, Float16 as Float16,
Annotated as Float16, Float32 as Float32,
Annotated as Float32, Float64 as Float64,
Annotated as Float64, Inexact as Inexact,
Annotated as Inexact, Int as Int,
Annotated as Int, Int8 as Int8,
Annotated as Int8, Int16 as Int16,
Annotated as Int16, Int32 as Int32,
Annotated as Int32, Int64 as Int64,
Annotated as Int64, Integer as Integer,
Annotated as Integer, Key as Key,
Annotated as Key, Num as Num,
Annotated as Num, Shaped as Shaped,
Annotated as Shaped, UInt as UInt,
Annotated as UInt, UInt8 as UInt8,
Annotated as UInt8, UInt16 as UInt16,
Annotated as UInt16, UInt32 as UInt32,
Annotated as UInt32, UInt64 as UInt64,
Annotated as UInt64,
) )
else: else:
# noqas to work around ruff bug
from .array_types import ( from .array_types import (
BFloat16 as BFloat16, # noqa: F401 BFloat16 as BFloat16,
Bool as Bool, # noqa: F401 Bool as Bool,
Complex as Complex, # noqa: F401 Complex as Complex,
Complex64 as Complex64, # noqa: F401 Complex64 as Complex64,
Complex128 as Complex128, # noqa: F401 Complex128 as Complex128,
Float as Float, # noqa: F401 Float as Float,
Float16 as Float16, # noqa: F401 Float16 as Float16,
Float32 as Float32, # noqa: F401 Float32 as Float32,
Float64 as Float64, # noqa: F401 Float64 as Float64,
Inexact as Inexact, # noqa: F401 Inexact as Inexact,
Int as Int, # noqa: F401 Int as Int,
Int8 as Int8, # noqa: F401 Int8 as Int8,
Int16 as Int16, # noqa: F401 Int16 as Int16,
Int32 as Int32, # noqa: F401 Int32 as Int32,
Int64 as Int64, # noqa: F401 Int64 as Int64,
Integer as Integer, # noqa: F401 Integer as Integer,
Key as Key, # noqa: F401 Num as Num,
Num as Num, # noqa: F401 Shaped as Shaped,
Shaped as Shaped, # noqa: F401 UInt as UInt,
UInt as UInt, # noqa: F401 UInt8 as UInt8,
UInt8 as UInt8, # noqa: F401 UInt16 as UInt16,
UInt16 as UInt16, # noqa: F401 UInt32 as UInt32,
UInt32 as UInt32, # noqa: F401 UInt64 as UInt64,
UInt64 as UInt64, # noqa: F401
) )
if has_jax:
from .array_types import Key as Key
# Now import PyTree # Now import PyTree
if typing.TYPE_CHECKING: if typing.TYPE_CHECKING:
@@ -156,9 +156,9 @@ elif has_jax:
# Conveniences # Conveniences
if typing.TYPE_CHECKING: if typing.TYPE_CHECKING:
from jax import Array as Scalar
from jax.random import PRNGKeyArray as PRNGKeyArray from jax.random import PRNGKeyArray as PRNGKeyArray
from jax.typing import ArrayLike as ScalarLike
from .indirection import Scalar as Scalar, ScalarLike as ScalarLike
elif has_jax: elif has_jax:
from .array_types import PRNGKeyArray, Scalar, ScalarLike # noqa: F401 from .array_types import PRNGKeyArray, Scalar, ScalarLike # noqa: F401
+32
View File
@@ -0,0 +1,32 @@
# Note that `from typing_extensions import Annotated; Bool = Annotated`
# does not work with static type checkers. `Annotated` is a typeform rather
# than a type, meaning it cannot be assigned.
from typing_extensions import (
Annotated as BFloat16, # noqa: F401
Annotated as Bool, # noqa: F401
Annotated as Complex, # noqa: F401
Annotated as Complex64, # noqa: F401
Annotated as Complex128, # noqa: F401
Annotated as Float, # noqa: F401
Annotated as Float16, # noqa: F401
Annotated as Float32, # noqa: F401
Annotated as Float64, # noqa: F401
Annotated as Inexact, # noqa: F401
Annotated as Int, # noqa: F401
Annotated as Int8, # noqa: F401
Annotated as Int16, # noqa: F401
Annotated as Int32, # noqa: F401
Annotated as Int64, # noqa: F401
Annotated as Integer, # noqa: F401
Annotated as Key, # noqa: F401
Annotated as Num, # noqa: F401
Annotated as Shaped, # noqa: F401
Annotated as UInt, # noqa: F401
Annotated as UInt8, # noqa: F401
Annotated as UInt16, # noqa: F401
Annotated as UInt32, # noqa: F401
Annotated as UInt64, # noqa: F401
)
from jax import Array as Scalar # noqa: F401
from jax.typing import ArrayLike as ScalarLike # noqa: F401
+1 -1
View File
@@ -1,6 +1,6 @@
[project] [project]
name = "jaxtyping" name = "jaxtyping"
version = "0.2.16" version = "0.2.18"
description = "Type annotations and runtime checking for shape and dtype of JAX arrays, and PyTrees." description = "Type annotations and runtime checking for shape and dtype of JAX arrays, and PyTrees."
readme = "README.md" readme = "README.md"
requires-python ="~=3.8" requires-python ="~=3.8"