Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion launch/launch/actions/opaque_coroutine.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def __init__(
if not asyncio.iscoroutinefunction(coroutine):
raise TypeError(
"OpaqueCoroutine expected a coroutine function for 'coroutine', got '{}'".format(
type(coroutine)
type(coroutine).__name__
)
)
ensure_argument_type(
Expand Down
2 changes: 1 addition & 1 deletion launch/launch/actions/opaque_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(
super().__init__(**left_over_kwargs)
if not callable(function):
raise TypeError("OpaqueFunction expected a callable for 'function', got '{}'".format(
type(function)
type(function).__name__
))
ensure_argument_type(
args, (collections.abc.Iterable, type(None)), 'args', 'OpaqueFunction')
Expand Down
2 changes: 1 addition & 1 deletion launch/launch/event_handlers/on_action_event_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def event_matcher(event):
if not isinstance(entity, LaunchDescriptionEntity):
raise TypeError(
"expected all items in 'on_event' iterable to be of type "
"'LaunchDescriptionEntity' but got '{}'".format(type(entity)))
"'LaunchDescriptionEntity' but got '{}'".format(type(entity).__name__))
self.__actions_on_event = list(on_event) # Outside list is to ensure type is List
else:
self.__actions_on_event = [on_event]
Expand Down
4 changes: 3 additions & 1 deletion launch/launch/substitutions/text_substitution.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ def __init__(self, *, text: Text) -> None:

if not isinstance(text, Text):
raise TypeError(
"TextSubstitution expected Text object got '{}' instead.".format(type(text))
"TextSubstitution expected Text object got '{}' instead.".format(
type(text).__name__
)
)

self.__text = text
Expand Down
8 changes: 4 additions & 4 deletions launch/launch/utilities/ensure_argument_type_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,23 @@ def ensure_argument_type(
'types',
'type, collections.abc.Iterable of type',
types,
type(types),
type(types).__name__,
))
if not isinstance(argument_name, str):
raise TypeError(error_msg_template.format(
"'ensure_argument_type()' e",
'argument_name',
'str',
argument_name,
type(argument_name),
type(argument_name).__name__,
))
if caller is not None and not isinstance(caller, str):
raise TypeError(error_msg_template.format(
"'ensure_argument_type()' e",
'caller',
'str, None',
caller,
type(caller),
type(caller).__name__,
))

def check_argument(argument: Any, type_var: Type[Any]) -> bool:
Expand All @@ -76,5 +76,5 @@ def check_argument(argument: Any, type_var: Type[Any]) -> bool:
argument_name,
', '.join([str(x) for x in list_of_types]),
argument,
type(argument),
type(argument).__name__,
))
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def normalize(x: Union[Substitution, str]) -> Substitution:
return TextSubstitution(text=str(x))
raise TypeError(
"Failed to normalize given item of type '{}', when only "
"'str' or 'launch.Substitution' were expected.".format(type(x)))
"'str' or 'launch.Substitution' were expected.".format(type(x).__name__))

if isinstance(subs, (str, Path)):
return [TextSubstitution(text=str(subs))]
Expand Down
28 changes: 15 additions & 13 deletions launch/launch/utilities/type_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def extract_type(data_type: AllowedTypesType) -> Tuple[ScalarTypesType, bool]:
is_list = True
scalar_type = data_type.__args__[0] # type: ignore
if is_valid_scalar_type(scalar_type) is False:
raise ValueError(f'Unrecognized data type: {data_type}')
raise ValueError(f'Unrecognized data type: {data_type.__name__}')
return (scalar_type, is_list)


Expand Down Expand Up @@ -245,7 +245,7 @@ def convert_as_yaml(value: Text, error_msg: str) -> Any:

if not is_instance_of_valid_type(output, can_be_str=can_be_str):
raise ValueError(
f'{error_msg}: output type is not allowed, got {type(output)}'
f'{error_msg}: output type is not allowed, got {type(output).__name__}'
)
return output

Expand Down Expand Up @@ -287,7 +287,7 @@ def convert_as_yaml(value: Text, error_msg: str) -> Any:
raise ValueError(
'data_type is invalid. Expected one of: '
'int, float, str, bool, List[int], List[float], List[str], List[bool]'
f'. Got {data_type}')
f'. Got {data_type.__name__}')
output = convert_as_yaml(value, f"Failed to convert '{value}' to '{type_obj}'")
if isinstance(output, valid_types):
return output
Expand All @@ -314,7 +314,8 @@ def coerce_list(
ensure_argument_type(value, list, 'value', 'coerce_list')
output = [coerce_to_type(i, data_type, can_be_str=can_be_str) for i in value]
if not is_instance_of_valid_type(output, can_be_str=can_be_str):
raise ValueError(f'cannot convert value to {data_type}. Got value=`{value}`')
typename = data_type.__name__ if data_type is not None else "inferred type"
raise ValueError(f'cannot convert value to {typename}. Got value=`{value}`')
return cast(ListValueType, output)


Expand Down Expand Up @@ -342,8 +343,8 @@ def get_typed_value(
data_type, is_list = extract_type(data_type)
if not is_list:
raise TypeError(
f"Cannot convert input '{value}' of type '{type(value)}' to"
f" '{data_type}'"
f"Cannot convert input '{value}' of type '{type(value).__name__}' to"
f" '{data_type.__name__}'"
)
return coerce_list(value, data_type, can_be_str=can_be_str)
else:
Expand Down Expand Up @@ -423,7 +424,7 @@ def execute(self, context):
# Resolve scalar types immediately
if isinstance(value, ScalarTypesTuple):
if not is_instance_of(value, data_type):
raise TypeError(f"value='{value}' is not an instance of {data_type}")
raise TypeError(f"value='{value}' is not an instance of {data_type.__name__}")
return value
# Resolve substitutions and list of substitutions immediately
if is_substitution(value):
Expand All @@ -433,7 +434,7 @@ def execute(self, context):
raise TypeError(
'value should be either a scalar, a substitutions,'
' or a mixed list of scalars and substitutions. '
f'Got `value={value}` of type `{type(value)}`. '
f'Got `value={value}` of type `{type(value).__name__}`. '
)
# Collect the types of the items of the list
types_in_list: Set[Optional[Type[Union[str, int, float, bool, Substitution]]]] = set()
Expand All @@ -455,13 +456,14 @@ def execute(self, context):
if not is_list:
raise TypeError(
'The provided value resolves to a list, though the required type is a scalar. '
f"Got value='{value}', data_type='{data_type}'."
f"Got value='{value}', data_type='{data_type.__name__}'."
)

# Normalize each specific uniform list input
type_name = data_type.__name__ if data_type is not None else "inferred type"
err_msg = (
"Got a list of '{}'"
f", expected a list of '{data_type}'. value='{value}'"
f", expected a list of '{type_name}'. value='{value}'"
)
if types_in_list == {Substitution}:
# list of substitutions, can be coerced later to anything
Expand Down Expand Up @@ -551,7 +553,7 @@ def perform_typed_substitution(
if isinstance(value, ScalarTypesTuple):
if data_type is not None and not is_instance_of(value, data_type):
raise TypeError(
f'value=`{value}` is a scalar and not an instance of `{data_type}`')
f'value=`{value}` is a scalar and not an instance of `{data_type.__name__}`')
return value
elif is_normalized_substitution(value):
return coerce_to_type(
Expand All @@ -565,7 +567,7 @@ def perform_typed_substitution(
if not is_list:
raise ValueError(
'The input value is a list, cannot convert it to a scalar. '
f"Got value='{value}', expected type {scalar_type}."
f"Got value='{value}', expected type {scalar_type.__name__}."
)
output = [
coerce_to_type(
Expand All @@ -575,7 +577,7 @@ def perform_typed_substitution(
if not is_instance_of(output, data_type):
raise ValueError(
'The output list does not match the expected type '
f"Got value='{value}', expected type {scalar_type}."
f"Got value='{value}', expected type {scalar_type.__name__}."
if scalar_type is not None else
'The output list is not uniform'
)
Expand Down
2 changes: 1 addition & 1 deletion launch_testing/launch_testing/util/proc_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,5 @@ def resolveProcesses(info_obj, *, process=None, cmd_args=None, strict_proc_match
else:
# Invalid argument passed for 'process'
raise TypeError(
"proc argument must be 'ExecuteProcess' or 'str' not {}".format(type(process))
"proc argument must be 'ExecuteProcess' or 'str' not {}".format(type(process).__name__)
)
4 changes: 2 additions & 2 deletions launch_xml/launch_xml/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def get_attr(
"""
attr_error = AttributeError(
"Attribute '{}' of type '{}' not found in Entity '{}'".format(
name, data_type, self.type_name
name, data_type.__name__, self.type_name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not reflected in the type annotation above, but data_type can be None apparently here and below :/ see the documentation for this method in the base class:

`data_type = None` will result in yaml parsing of the attribute value as a string.

  1. https://ci.ros2.org/job/ci_linux/24014/testReport/junit/test_launch_ros.test.test_launch_ros.frontend/test_component_container/test_launch_component_container_xml/
  2. https://ci.ros2.org/job/ci_linux/24014/testReport/junit/test_launch_ros.test.test_launch_ros.frontend/test_node_frontend/test_launch_frontend_xml/

I'll open an issue to fix the type annotation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll open an issue to fix the type annotation.

#888

)
)
if check_is_list_entity(data_type):
Expand Down Expand Up @@ -125,7 +125,7 @@ def get_attr(
raise TypeError(
"Attribute '{}' of Entity '{}' expected to be of type '{}'."
"'{}' can not be converted to one of those types".format(
name, self.type_name, data_type, value
name, self.type_name, data_type.__name__, value
)
)
return value
4 changes: 2 additions & 2 deletions launch_yaml/launch_yaml/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def children(self) -> List['Entity']:
self.__children_called = True
if not isinstance(self.__element, (dict, list)):
raise TypeError(
f'Expected a dict or list, got {type(self.element)}:'
f'Expected a dict or list, got {type(self.element).__name__}:'
f'\n---\n{self.__element}\n---'
)
if isinstance(self.__element, dict):
Expand Down Expand Up @@ -133,7 +133,7 @@ def get_attr(
if not is_instance_of(data, data_type, can_be_str=can_be_str):
raise TypeError(
"Attribute '{}' of Entity '{}' expected to be of type '{}', got '{}'".format(
name, self.type_name, data_type, type(data)
name, self.type_name, data_type.__name__, type(data).__name__
)
)
return data