Skip to content

Commit

Permalink
SomeParameterValue multi value substitutions
Browse files Browse the repository at this point in the history
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
  • Loading branch information
sloretz committed Mar 6, 2019
1 parent a4ac02b commit 65f23a6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 4 additions & 1 deletion launch_ros/launch_ros/parameters_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@

SomeParameterFile = Union[SomeSubstitutionsType, pathlib.Path]
SomeParameterName = Sequence[Union[Substitution, str]]
SomeParameterValue = Union[SomeSubstitutionsType, _SingleValueType, _MultiValueType]
SomeParameterValue = Union[SomeSubstitutionsType,
Sequence[SomeSubstitutionsType],
_SingleValueType,
_MultiValueType]

# TODO(sloretz) Recursive type when mypy supports them python/mypy#731
_SomeParametersDict = Mapping[SomeParameterName, Any]
Expand Down
8 changes: 5 additions & 3 deletions launch_ros/launch_ros/utilities/normalize_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,13 @@ def _normalize_parameter_array_value(value: SomeParameterValue) -> ParameterValu
raise RuntimeError('Failed to handle type {}'.format(repr(subvalue)))

if {int} == has_types:
# all integers
return tuple(int(e) for e in value)
# everything is an integer
make_mypy_happy_int = cast(List[int], value)
return tuple(int(e) for e in make_mypy_happy_int)
elif has_types in ({float}, {int, float}):
# all were floats or ints, so return floats
return tuple(float(e) for e in value)
make_mypy_happy_float = cast(List[Union[int, float]], value)
return tuple(float(e) for e in make_mypy_happy_float)
elif Substitution in has_types and has_types.issubset({str, Substitution, tuple}):
# make a list of substitutions forming a single string
return tuple(normalize_to_list_of_substitutions(cast(SomeSubstitutionsType, value)))
Expand Down

0 comments on commit 65f23a6

Please sign in to comment.