diff --git a/src/specklepy/objects/base.py b/src/specklepy/objects/base.py index a4b09888..51765f1a 100644 --- a/src/specklepy/objects/base.py +++ b/src/specklepy/objects/base.py @@ -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 diff --git a/tests/unit/test_type_validation.py b/tests/unit/test_type_validation.py index 1980ca21..5ca9aece 100644 --- a/tests/unit/test_type_validation.py +++ b/tests/unit/test_type_validation.py @@ -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(