Skip to content

Commit

Permalink
MNT: validators can only throw ValidationError
Browse files Browse the repository at this point in the history
  • Loading branch information
tangkong committed Feb 27, 2024
1 parent 4323c13 commit 7b9a861
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions superscore/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
get_type_hints)
from uuid import UUID, uuid4

from apischema.validation import validate, validator
from apischema.validation import ValidationError, validate, validator

from superscore.type_hints import AnyEpicsType

Expand Down Expand Up @@ -66,7 +66,7 @@ def validate_field(self, field_name: str, hint: Any) -> None:
Raises
------
TypeError
ValidationError
if a type mismatch is found
"""
field_value = getattr(self, field_name)
Expand All @@ -93,15 +93,15 @@ def validate_field(self, field_name: str, hint: Any) -> None:
return
elif (origin is None):
if not isinstance(field_value, hint):
raise TypeError('improper type found in field')
raise ValidationError('improper type found in field')
elif (origin is Union) and (UUID in get_args(hint)):
# Case of interest. A hint of Union[UUID, SomeType]
if is_list:
list_comp = (isinstance(it, get_args(hint)) for it in field_value)
if not all(list_comp):
raise TypeError('improper type in list-field')
raise ValidationError('improper type in list-field')
elif not isinstance(field_value, get_args(hint)):
raise TypeError('improper type found in field')
raise ValidationError('improper type found in field')


@dataclass
Expand Down

0 comments on commit 7b9a861

Please sign in to comment.