in tfx/types/component_spec.py [0:0]
def type_check(self, arg_name: str, value: Any):
"""Perform type check to the parameter passed in."""
if isinstance(value, placeholder.Placeholder):
# TODO(b/266800844): Insert a type plausibility check.
return
is_runtime_param = _is_runtime_param(value)
value = _make_default(value)
if self.type == Any:
return
# types.GenericAlias was added in Python 3.9, and we use string
# comparisons as a workaround for Python<3.9.
if type(self.type).__name__ in ('_GenericAlias', 'GenericAlias'):
if not check_strict_json_compat(value, self.type):
raise TypeError(
f'Expected type {self.type!s} for parameter {arg_name!r} but got '
f'{value!s} instead.'
)
elif isinstance(value, dict) and issubclass(self.type, message.Message):
# If a dict is passed in and is compared against a pb message,
# do the type-check by converting it to pb message.
proto_utils.dict_to_proto(value, self.type())
elif (
isinstance(value, str)
and not isinstance(self.type, tuple)
and issubclass(self.type, message.Message)
):
# Skip check for runtime param string proto.
if not is_runtime_param:
# If a text is passed in and is compared against a pb message,
# do the type-check by converting text (as json) to pb message.
proto_utils.json_to_proto(value, self.type())
else:
if not isinstance(value, self.type):
raise TypeError(
f'Expected type {self.type!s} for parameter {arg_name!r} but got '
f'{value!s} instead.'
)