-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for beartype 0.17.0's __instancecheck_str__.
Recall that jaxtyping will currently generate rich error messages in precisely one scenario: about the arguments and return types when doing: ```python @jaxtyped(typechecker=beartype) def foo(...): ... ``` With this commit we add support for beartype 0.17.0's pseudo-standard `__instancecheck_str__`, which means the following: 1. For those using beartype decorators, the following will *also* generate an informative error message, and moreover it will state exactly why (shape mismatch, dtype mismatch etc): ```python @jaxtyped(typechecker=None) @beartype def foo(...): ... ``` (In practice we probably won't recommend the above combination in the docs just to keep things simple.) 2. For those using the beartype import hook together with the jaxtyping import hook, we can probably also check `assert isinstance(x, Float[Array, "foo"])` statements with rich error messages. (#153) We'll need to test + document that though. (@jeezrick interested?) 3. For those using plain `assert isinstance(...)` statements without beartype (#167, tagging @reinerp), then they can *also* get rich error messages by doing ```python tt = Float[Array, "foo"] assert isinstance(x, tt), tt.__instancecheck_str__(x) + "\n" + print_bindings() ``` which is still a bit long-winded right now but is a step in the right direction. (CC @leycec for interest.)
- Loading branch information
1 parent
28ad527
commit 1d4d402
Showing
1 changed file
with
40 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters