jaxtyping icon indicating copy to clipboard operation
jaxtyping copied to clipboard

Failed to compile with Union

Open pfeatherstone opened this issue 2 years ago • 3 comments

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

pfeatherstone avatar Aug 24 '23 12:08 pfeatherstone

What version of typeguard? I think this was a bug in earlier versions of typeguard.

patrick-kidger avatar Aug 24 '23 12:08 patrick-kidger

4.1.0

pfeatherstone avatar Aug 24 '23 12:08 pfeatherstone

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.

patrick-kidger avatar Aug 24 '23 13:08 patrick-kidger