Skip to content

Commit

Permalink
Merge pull request #267 from RobClaessensRHDHV/feature/suppress_type_…
Browse files Browse the repository at this point in the history
…error_during_type_check

Fix: also suppress TypeError during type checking.
  • Loading branch information
gjedlicska authored Apr 6, 2023
2 parents 77e09b9 + d2685c5 commit c7f5e07
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/specklepy/objects/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def _validate_type(t: Optional[type], value: Any) -> Tuple[bool, Any]:
if isinstance(value, t):
return True, value

with contextlib.suppress(ValueError):
with contextlib.suppress(ValueError, TypeError):
if t is float and value is not None:
return True, float(value)
# TODO: dafuq, i had to add this not list check
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/test_type_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ def __init__(self, foo: str) -> None:
fake_bases,
),
(List["int"], [2, 3, 4], True, [2, 3, 4]),
(Union[float, Dict[str, float]], {"foo": 1, "bar": 2}, True, {"foo": 1.0, "bar": 2.0}),
(Union[float, Dict[str, float]], {"foo": "bar"}, False, {"foo": "bar"}),
],
)
def test_validate_type(
Expand Down

0 comments on commit c7f5e07

Please sign in to comment.