Open addisonklinke opened 2 years ago
Hmm. Unless there's a big outcry from lots of people wanting this feature, then I'm inclined to keep things as-is just for simplicity.
However I expect it should be possible for you to piggy-back off of torchtyping
and write your own library that does this. Parse the docstring, and then set __annotations__
appropriately, and then torchtyping/typeguard will take it from there. WDYT?
Sure I'll take a look into customizing via your suggested approach - thanks!
First off - I've been thinking of almost the same idea as this library for a while because I see runtime errors from tensor shape/dtype mismatches all the time, so glad that there's already something in place!
My initial approach was going to be parsing docstrings of various formats (with an existing library like docstring_parser) and performing validation on these, rather than type annotations. Is that a feature you'd consider accepting into your library? I'd be interested in writing a PR for it with some guidance
For example, I currently write Sphinx style docstrings like this
I realize the
[N, C, H, W]
notation is not quite as rigid as what this project proposes, and that's one reason I've been looking for a more structured approach. But regardless, I do find it nice sometimes to have this information in the docstrings instead of type annotations, particularly for functions with many parameters