nested NamedTuples don't work with beartype + jaxtyping
See original GitHub issueThis works
from beartype import beartype as typechecker
from jaxtyping import Array, Float, jaxtyped
from typing import NamedTuple, Union, Optional
@typechecker
class ParamsLGSSMInitial(NamedTuple):
mean: float
cov: float
p = ParamsLGSSMInitial(mean=5.0, cov=10.0) # fine
@typechecker
class ParamsLGSSM(NamedTuple): # fine
initial: ParamsLGSSMInitial
but this does not
@jaxtyped
@typechecker
class ParamsLGSSMInitial2(NamedTuple):
mean: float
cov: float
p = ParamsLGSSMInitial2(mean=5.0, cov=10.0) # fine
@typechecker
class ParamsLGSSM(NamedTuple):
initial2: ParamsLGSSMInitial2 # fail
I get the error
beartype.roar.BeartypeDecorHintNonpepException: @beartyped namedtuple_ParamsLGSSM.ParamsLGSSM.__new__() parameter "initial2" type hint <jaxtyping.decorator._Jaxtyped object at 0x7f7ae90450a0> either PEP-noncompliant or currently unsupported by @beartype.
I realize this may be a problem with jaxtyping and not beartype…
(Also I realize I don’t need the @jaxtyped
decorator in this example, but in the real code, float
is actually an Array.)
Issue Analytics
- State:
- Created 10 months ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Iterating a list of nested named tuples causes type error #7902
I am reporting a bug. Consider this code: from typing import List, NamedTuple, Union class A(NamedTuple): p: int class B(NamedTuple): q: int ...
Read more >Name a nested typing.NamedTuple in the same outer class in ...
I have a class A which has nested typing.NamedTuple s B and C. So far so good. The problem arises when the nested...
Read more >Write Pythonic and Clean Code With namedtuple - Real Python
Have a helpful docstring based on the type and field names; Provide a helpful string representation that prints the tuple content in a...
Read more >Release develop Evan Hubinger - Coconut
How do I use a runtime type checker like beartype when Coconut seems to compile all ... I don't like functional programming, should...
Read more >++namedtuple - Python-style Named Tuples in C++20
https://cppcon.org/https://github.com/CppCon/CppCon2021---In this workshop, we will take a look into how Python-style named tuples can be ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
So for context,
jaxtyped(fn)
returns afunctools.wraps(fn)(_Jaxtyped(fn))
. I feel like that should still be a valid type annotation (whether or notbeartype
respects thewraps
).FWIW one possible fix might be to make
jaxtyped
of a class actually just wrap the__init__
method.I’d be happy to accept a PR on this over in the jaxtyping repo.
The sweet words I’ve waited a lifetime to hear. 🥰 😍 😻 :heart_on_fire:
The ML Dream Team of @murphyk + @patrick-kidger capably resolved this without my needing to lift a paw. Thanks so much for resolving this for me. I can now quietly close this and pretend I knew what was going on here.