beartype+inheritance fix. Bool[int, '...'] now correctly raises an error.

This commit is contained in:
Patrick Kidger
2023-03-05 20:09:49 -08:00
parent e718f00cc5
commit 38be24f9c8
2 changed files with 7 additions and 3 deletions
+3 -1
View File
@@ -253,7 +253,7 @@ def _make_metaclass(base_metaclass):
def _check_scalar(dtype, dtypes, dims):
if len(dims) != 0:
return False
return dims == (_anonymous_variadic_dim,)
return (_any_dtype is dtypes) or any(d.startswith(dtype) for d in dtypes)
@@ -469,6 +469,8 @@ class _MetaAbstractDtype(type):
out = Union[out]
else:
out = _make_array(array_type, dim_str, cls.dtypes, cls.__name__)
if out is _not_made:
raise ValueError("Invalid jaxtyping type annotation.")
return out
+4 -2
View File
@@ -77,8 +77,10 @@ def _jaxtyped_typechecker(typechecker):
def _wrapper(kls):
assert inspect.isclass(kls)
if dataclasses.is_dataclass(kls):
init = jaxtyped(typechecker(kls.__init__))
kls.__init__ = init
if type(kls.__init__) is not _Jaxtyped:
# Extra `if` check to work around beartype bug #211
init = jaxtyped(typechecker(kls.__init__))
kls.__init__ = init
return kls
return _wrapper