From 47d8039819b56bde14e47bae5710f49eda6ac050 Mon Sep 17 00:00:00 2001 From: sneakers-the-rat Date: Fri, 13 Dec 2024 17:17:47 -0800 Subject: [PATCH] simple enough fix - handle `typing.UnionType` in additional `dtype` metadata in json schema --- src/numpydantic/ndarray.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/numpydantic/ndarray.py b/src/numpydantic/ndarray.py index fa0fdc9..989dc58 100644 --- a/src/numpydantic/ndarray.py +++ b/src/numpydantic/ndarray.py @@ -204,9 +204,15 @@ class NDArray(NPTypingType, metaclass=NDArrayMeta): json_schema = handler(schema["metadata"]) json_schema = handler.resolve_ref_schema(json_schema) - if not isinstance(dtype, tuple) and dtype.__module__ not in ( - "builtins", - "typing", + if ( + not isinstance(dtype, tuple) + and dtype.__module__ + not in ( + "builtins", + "typing", + "types", + ) + and hasattr(dtype, "__name__") ): json_schema["dtype"] = ".".join([dtype.__module__, dtype.__name__])