Comments (3)
Ok, nevermind, the not all was caused by the fact that I use from __future__ import annotations
in my plotting
module. In module where I do not import from __future__ import annotations
, it renders nicely.
from jaxtyping.
Ah, that's good to know! For what it's worth from __future__ import annotations
will often break runtime type checkers in unpredictable ways (resolving the stringified annotations correctly is intractable in general), so I'm afraid this should be avoided anyway.
(That aside, if this is a greenfield project then having tried both Sphinx and MkDocs, I've come to really enjoy the greater simplicity of the latter, and would recommend it!)
from jaxtyping.
I actually run in a problem where not solution is optimal because of that.
Because I use this library, I cannot use from __future__ import annotations
.
When Sphinx's autodoc tries to import the module, it first tries with typing.TYPE_CHECKING=True
, so I could do that:
if TYPE_CHECKING:
from some_optioal_deps import ReturnType
else:
ReturnType = Any
but will fail (Any
will be displayed in the docs) because your module depends on numpy
, which cannot be imported with TYPE_CHECKING
set to True. It then fallsback to ReturnType = Any
.
So the solution I came up with is
try:
from some_optioal_deps import ReturnType
except ImportError:
ReturnType = Any
which renders correctly in the docs (because I installed the optional deps to build the docs).
However, tools like Pyright will complain because ReturnType
can be Any, which is often a bad practice.
My current solution was to annotate each return type with # type: ignore
.
I think you could "fix" this issue by removing imports to NumPy load, and only import this when needed.
Anything, I thought it was interesting to document this here!
from jaxtyping.
Related Issues (20)
- Issues with torch.compile HOT 5
- Functions without type hints and import hook HOT 1
- Compatibility with multiprocessing / joblib - AttributeError: type object 'Float[Tensor, 'batch_size num_classes']' has no attribute 'index_variadic' HOT 4
- Can typeguard be an optional dependency? HOT 8
- Are pytorch named tensors supported, like in torchtyping? HOT 1
- numpy structured dtype support HOT 1
- Bug with default argument binding HOT 2
- Incompatibility with flax.linen.tabulate HOT 4
- Unions not working HOT 4
- jaxtyping with JAX severely slowing down training speed HOT 6
- `install_import_hook` skip `no_type_check` HOT 1
- add type annotation for jaxtyped HOT 1
- Installing `jaxtyping` makes Pytest slow(er) HOT 3
- Annotations for tensors with dynamics dimensions HOT 2
- Leading integer and ellipses in pytree raises error HOT 2
- `mypy` gives error for `np.ndarray` as container type HOT 2
- Misleading exception when runtime type checker is used directly HOT 4
- Creating instances of `jaxtyped` dataclasses is slow HOT 3
- Inconsistent shape checking for lists of tensors HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jaxtyping.