GithubHelp home page GithubHelp logo

Comments (3)

jeertmans avatar jeertmans commented on July 28, 2024

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.

patrick-kidger avatar patrick-kidger commented on July 28, 2024

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.

jeertmans avatar jeertmans commented on July 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.