jaxtyping
jaxtyping copied to clipboard
Failed to compile with Union
I have a function with signature:
from typing import Union
from jaxtyping import Float, jaxtyped
from typeguard import typechecked
@jaxtyped
@typechecked
def fn(x: Union[Float[torch.Tensor, "B F"], int]): ...
which doesn't work. It fails to compile the AST
What version of typeguard? I think this was a bug in earlier versions of typeguard.
4.1.0
Thanks!
Looks like this is still an outstanding bug in typeguard. Here's a reproducer that doesn't use jaxtyping:
import numpy as np
from typeguard import typechecked
from typing import Annotated, Union
@typechecked
def fn(x: Union[Annotated[np.ndarray, "B F"], int]): ...
I'd recommend reporting this as a bug on their issue tracker.
As a workaround for now, I'd recommend either downgrading to typeguard 2.*, or to use beartype instead.