mirror of
https://github.com/wassname/jaxtyping.git
synced 2026-09-09 11:24:55 +08:00
Add support for e.g. jaxtyping.Float[Union[...], ...] in py3.8 (#31)
* Add support for e.g. jaxtyping.Float[Union[...], ...] in py3.8 Turns out that python3.8, Union lacks the __name__ attribute. Use repr() in these cases. * Fix linter. * Remove implicit cast to bool in favor of try/except.
This commit is contained in:
@@ -384,7 +384,12 @@ class _MetaAbstractDtype(type):
|
||||
elem = _SymbolicDim(elem, broadcastable)
|
||||
dims.append(elem)
|
||||
if _array_name_format == "dtype_and_shape":
|
||||
name = f"{cls.__name__}[{array_type.__name__}, '{dim_str}']"
|
||||
# In python 3.8, e.g., typing.Union lacks `__name__`.
|
||||
try:
|
||||
type_str = array_type.__name__
|
||||
except AttributeError:
|
||||
type_str = repr(array_type)
|
||||
name = f"{cls.__name__}[{type_str}, '{dim_str}']"
|
||||
elif _array_name_format == "array":
|
||||
name = array_type.__name__
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user