mirror of
https://github.com/p2p-ld/numpydantic.git
synced 2024-11-12 17:54:29 +00:00
update changelog, bump version
This commit is contained in:
parent
e9d766aad1
commit
a8ba11f772
2 changed files with 13 additions and 1 deletions
|
@ -128,7 +128,13 @@ class Interface(ABC, Generic[T]):
|
|||
elif self.dtype is np.str_:
|
||||
valid = getattr(dtype, "type", None) is np.str_ or dtype is np.str_
|
||||
else:
|
||||
valid = dtype == self.dtype
|
||||
# try to match as any subclass, if self.dtype is a class
|
||||
try:
|
||||
valid = issubclass(dtype, self.dtype)
|
||||
except TypeError:
|
||||
# expected, if dtype or self.dtype is not a class
|
||||
valid = dtype == self.dtype
|
||||
|
||||
return valid
|
||||
|
||||
def raise_for_dtype(self, valid: bool, dtype: DtypeType) -> None:
|
||||
|
|
|
@ -66,6 +66,10 @@ class BadModel(BaseModel):
|
|||
x: int
|
||||
|
||||
|
||||
class SubClass(BasicModel):
|
||||
pass
|
||||
|
||||
|
||||
RGB_UNION: TypeAlias = Union[
|
||||
NDArray[Shape["* x, * y"], Number],
|
||||
NDArray[Shape["* x, * y, 3 r_g_b"], Number],
|
||||
|
@ -143,6 +147,7 @@ def shape_cases(request) -> ValidationCase:
|
|||
ValidationCase(annotation=MODEL, dtype=BasicModel, passes=True),
|
||||
ValidationCase(annotation=MODEL, dtype=BadModel, passes=False),
|
||||
ValidationCase(annotation=MODEL, dtype=int, passes=False),
|
||||
ValidationCase(annotation=MODEL, dtype=SubClass, passes=True),
|
||||
],
|
||||
ids=[
|
||||
"float",
|
||||
|
@ -169,6 +174,7 @@ def shape_cases(request) -> ValidationCase:
|
|||
"model-model",
|
||||
"model-badmodel",
|
||||
"model-int",
|
||||
"model-subclass",
|
||||
],
|
||||
)
|
||||
def dtype_cases(request) -> ValidationCase:
|
||||
|
|
Loading…
Reference in a new issue