Added support for beartype 0.17.0's __instancecheck_str__. #169
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Recall that jaxtyping will currently generate rich error messages in precisely one scenario: about the arguments and return types when doing:
With this commit we add support for beartype 0.17.0's pseudo-standard
__instancecheck_str__
, which allows us to report exactly why aninstancecheck
failed -- was the shape of the array wrong, was the dtype wrong, etc?This means the following:
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):
(In practice we probably won't recommend the above combination in the docs just to keep things simple.)
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. (will runtime type checking go beyond function parameters and return type? #153) We'll need to test + document that though. (@jeezrick interested?)For those using plain
assert isinstance(...)
statements without beartype (Provide a way to get error diagnostics out of isinstance checks #167, tagging @reinerp), then they can also get rich error messages by doingwhich is still a bit long-winded right now but is a step in the right direction.
(CC @leycec for interest. Also CC @Qwlouse @Conchylicultor as I believe you're interested in this functionality.)