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

Is it possible to use torchtyping with pydantic? #33

Closed kharitonov-ivan closed 2 years ago

kharitonov-ivan commented 2 years ago

Hi! Is it an option to use the torchtyping annotations with other runtime type checkers instead of typeguard?

It is not directly related, but the question came up from the next case. For batch I use dataclass, and typeguard doesn't check in runtime constructor of dataclass. Maybe there is a more clever choice for from what inherit batch?

patrick-kidger commented 2 years ago

So it should be possible to use TensorType for documentation purposes. But probably not to perform runtime type checking.

TorchTyping relies on its own type checker to make that happen, and monkey-patches that into typeguard. Probably we'd need to do something similar and monkey patch into pydantic etc. as well. But I'm not a user of that so it's hard to say.

If you figure out any neat way of tackling the problem I'd be happy to accept a PR.

kharitonov-ivan commented 2 years ago

Okay! Understood. Thank you for fast reply. I am closing the issue.