question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typing (type hinting) in Haiku?

See original GitHub issue

Hey all!

I like using mypy as a smell test for my code and I was wondering if Haiku (and to a larger extent, Jax) has (well supported) built in typing? I tried doing

import jax.np as jnp
type(jnp.ones([3]))

I found Type Hints but it seems to only be a subset of supported ops. Does the team have any recommendations?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
tomhennigancommented, Sep 23, 2021

We tend to use aliases internally. There is a mixture of people aliasing jnp.ndarray and chex.Array.

I know that JAX team have plans to make rng keys a distinct type (PRNGKeyArray) which is a super common thing users want to type hint (currently jax.random.PRNGKey is a function not a type).

I am not aware of a good way to type a function that accepts a PyTree of arrays in a way that will actually make the type checker do something useful.

1reaction
tomhennigancommented, Sep 20, 2021

You could look at https://github.com/deepmind/tensor_annotations if you want a more complete type annotation (e.g. with rank and axis names). The JAX team also have some thoughts on import time type checking in JAX. So far we have not adopted any of these solutions in our libraries, there is definitely some energy from users to improve the state of typing in JAX libraries, however for now there is not a canonical solution that pleases most.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Type hints cheat sheet - mypy 0.991 documentation
Type hints cheat sheet#. This document is a quick cheat sheet showing how to use type annotations for various common types in Python....
Read more >
dm-haiku/transform.py at main - GitHub
import types. from typing import Any, Callable, List, Mapping, NamedTuple, Optional, Tuple, TypeVar, Union. from haiku._src import analytics. from haiku.
Read more >
PEP 484 – Type Hints - Python Enhancement Proposals
This PEP aims to provide a standard syntax for type annotations, opening up Python code to easier static analysis and refactoring, potential runtime...
Read more >
What are the best practices in using Python type hinting? (e.g. ...
Originally Answered: What is the strongest argument against statically typed programming languages? I am strongly pro-static typing. If I were tasked to build ......
Read more >
Python type hinting: how to tell X is a subclass for Foo?
According to PEP 484 (about Type Hints), there exists a hint for type of class objects, called Type[C]. And according to typing module's ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found