mirror of
https://github.com/p2p-ld/numpydantic.git
synced 2024-11-14 02:34:28 +00:00
python 3.9 compat
This commit is contained in:
parent
85cef50603
commit
e63d9268b1
1 changed files with 10 additions and 3 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue