purposely break numpydantic to check for linkml test failure

This commit is contained in:
sneakers-the-rat 2024-09-25 17:26:55 -07:00
parent c13daaf915
commit 5b59e9fc07
Signed by untrusted user who does not match committer: jonny
GPG key ID: 6DCB96EF1E4D232D

View file

@ -5,9 +5,7 @@ For literal dtypes intended for use by end-users, see :mod:`numpydantic.dtype`
""" """
import sys import sys
from typing import Any, Union, get_args, get_origin from typing import Any, Union, get_origin
import numpy as np
from numpydantic.types import DtypeType from numpydantic.types import DtypeType
@ -28,29 +26,31 @@ def validate_dtype(dtype: Any, target: DtypeType) -> bool:
Returns: Returns:
bool: ``True`` if valid, ``False`` otherwise bool: ``True`` if valid, ``False`` otherwise
""" """
if target is Any: return False
return True #
# if target is Any:
if isinstance(target, tuple): # return True
valid = dtype in target #
elif is_union(target): # if isinstance(target, tuple):
valid = any( # valid = dtype in target
[validate_dtype(dtype, target_dt) for target_dt in get_args(target)] # elif is_union(target):
) # valid = any(
elif target is np.str_: # [validate_dtype(dtype, target_dt) for target_dt in get_args(target)]
valid = getattr(dtype, "type", None) in (np.str_, str) or dtype in ( # )
np.str_, # elif target is np.str_:
str, # valid = getattr(dtype, "type", None) in (np.str_, str) or dtype in (
) # np.str_,
else: # str,
# try to match as any subclass, if target is a class # )
try: # else:
valid = issubclass(dtype, target) # # try to match as any subclass, if target is a class
except TypeError: # try:
# expected, if dtype or target is not a class # valid = issubclass(dtype, target)
valid = dtype == target # except TypeError:
# # expected, if dtype or target is not a class
return valid # valid = dtype == target
#
# return valid
def is_union(dtype: DtypeType) -> bool: def is_union(dtype: DtypeType) -> bool: