From e63d9268b1bb78f86a9426d9b3d3e66c7aa211f6 Mon Sep 17 00:00:00 2001 From: sneakers-the-rat Date: Mon, 23 Sep 2024 23:30:40 -0700 Subject: [PATCH] python 3.9 compat --- src/numpydantic/validation/dtype.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/numpydantic/validation/dtype.py b/src/numpydantic/validation/dtype.py index bc7723c..d930fc0 100644 --- a/src/numpydantic/validation/dtype.py +++ b/src/numpydantic/validation/dtype.py @@ -3,14 +3,18 @@ Helper functions for validation of dtype. For literal dtypes intended for use by end-users, see :mod:`numpydantic.dtype` """ - -from types import UnionType +import sys from typing import Any, Union, get_args, get_origin import numpy as np from numpydantic.types import DtypeType +if sys.version_info >= (3, 10): + from types import UnionType +else: + UnionType = None + def validate_dtype(dtype: Any, target: DtypeType) -> bool: """ @@ -52,4 +56,7 @@ def is_union(dtype: DtypeType) -> bool: """ Check if a dtype is a union """ - return get_origin(dtype) in (Union, UnionType) + if UnionType is None: + return get_origin(dtype) is Union + else: + return get_origin(dtype) in (Union, UnionType)