patrick-kidger / torchtyping

Type annotations and dynamic checking for a tensor's shape, dtype, names, etc.
Apache License 2.0
1.39k stars 33 forks source link

Using `str: int` pairs in annotations does not verify names at runtime #12

Closed yohan-pg closed 3 years ago

yohan-pg commented 3 years ago

First of all, thanks for your work, this library is very useful.

While both name constraints (str) and size contraints (int) are combined, the runtime type checks seem to stop working. This example does not throw an error:

def f(x: TensorType["B" : 4, "F"]) -> TensorType["B"]:
    return torch.randn(3)

While if the : 4 is removed from the example, the correct behavior is obtained ("TypeError: Dimension 'B' of inconsistent size."). I have only tried this with Python 3.9

patrick-kidger commented 3 years ago

Thanks for the report -- this should now be fixed. Let me know if anything still seems wrong.