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:
ebrevdo
2022-09-22 13:25:29 -07:00
committed by GitHub
parent f175c7f315
commit dcd73e3431
+6 -1
View File
@@ -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: