patrick-kidger / jaxtyping

Type annotations and runtime checking for shape and dtype of JAX/NumPy/PyTorch/etc. arrays. https://docs.kidger.site/jaxtyping/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[DOC] Need better documentation about `from __future__ import annotations`

jeertmans opened this issue · comments

Hello~ Very recently, I lost quite some time searching why type-checking my dataclass did not work in my module (with a lot of other classes, imports, etc.), but well if I just declared the class in a plain .py file.

After some thinking, I realized that the issue was coming from my top-level from __future__ import annotations import. When removed, everything worked as expected.

I recognize that this issue is documented on your website, but I think there should be a specific section or better emphasize for that, since the place where you mention this issue is not directly related to that import.

I suggest writing a few words about the issues caused by this import, why it breaks runtime checkers, and how to mitigate this. What do you think?

Agreed! That seems reasonable to me. Actually as another point, this is no longer unique to install_import_hook, but also applies to jaxtyped.
(This is new because jaxtyped didn't use to support dataclasses at all; now it does.)

Should be fixed in #157.

Thanks for replying so quickly!