Open dkamm opened 1 year ago
Right! I've been meaning to fix this for a while. (Thankfully beartype is normally happy with being decorated on methods, so this issue isn't high-priority.)
The problem is that (a) I'd need to think a lot more carefully about how to write the AST transformer, which is quite finickity, and (b) non-beartype runtime type checkers may prefer to have functions decorated, so we need to support both behaviours.
I'd be happy to accept a PR on this.
Can take a look! Was thinking the same about part b
Hello! I was wondering if there is an update on this PR. I make heavy use of Self
in my library and would like to use the the import hook with beartype
, so deciding what the best course of action for myself is! Much appreciated in advance 😊
So the current state is essentially this comment. Which is to say, right now this still doesn't work, but we do we know how we want to fix it: our desired end-goal is for the jaxtyping import hook and the beartpe import hook to be usable together.
Rather than having jaxtyping in the driver's seat, (and it having to apply the @beartype.beartype
decorator correctly, as discussed earlier in this thread), then this approach would allow each library to just do its own thing independently.
However, at the moment, when the beartype hook is used then the jaxtyping hook seems to be entirely ignored. :(
If you or anyone else would be interested in taking this one, then I'm sure either @leycec or I would be happy to receive a PR so that this combination plays nicely with each other!
(For anyone else reading this issue, the best practice for now is to do jaxtyping.install_import_hook(typechecker=beartype.beartype)
, and simply avoid using Self
.)
This is very helpful to know! Thank you for the update, this sounds like a good solution.
This seems like the correct thing to do? See https://beartype.readthedocs.io/en/latest/faq/#the-current-class and the following code sample
errors with