Skip to content

Commit 92991ef

Browse files
Fix ament mypy (#5322)
* Configured nav2_common to be compatible with ament_mypy. Signed-off-by: Leander Stephen D'Souza <leanderdsouza1234@gmail.com> * Configured nav2_bringup to be compatible with ament_mypy. Signed-off-by: Leander Stephen D'Souza <leanderdsouza1234@gmail.com> * Configured nav2_costmap_2d to be compatible with ament_mypy. Signed-off-by: Leander Stephen D'Souza <leanderdsouza1234@gmail.com> * Configured nav2_docking to be compatible with ament_mypy. Signed-off-by: Leander Stephen D'Souza <leanderdsouza1234@gmail.com> * Configured nav2_lifecycle_manager to be compatible with ament_mypy. Signed-off-by: Leander Stephen D'Souza <leanderdsouza1234@gmail.com> * Configured nav2_map_server to be compatible with ament_mypy. Signed-off-by: Leander Stephen D'Souza <leanderdsouza1234@gmail.com> * Configured nav2_simple_commander to be compatible with ament_mypy. Signed-off-by: Leander Stephen D'Souza <leanderdsouza1234@gmail.com> * Configured nav2_system_tests to be compatible with ament_mypy. Signed-off-by: Leander Stephen D'Souza <leanderdsouza1234@gmail.com> --------- Signed-off-by: Leander Stephen D'Souza <leanderdsouza1234@gmail.com>
1 parent f6c5cc6 commit 92991ef

34 files changed

+140
-114
lines changed

‎nav2_bringup/launch/cloned_multi_tb3_simulation_launch.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
import os
1818
from pathlib import Path
1919
import tempfile
20+
from typing import Optional
2021

2122
from ament_index_python.packages import get_package_share_directory
22-
from launch import LaunchDescription
23+
from launch import LaunchDescription, LaunchDescriptionEntity
2324
from launch.actions import (AppendEnvironmentVariable, DeclareLaunchArgument, ExecuteProcess,
2425
ForEach, GroupAction, IncludeLaunchDescription, LogInfo,
2526
OpaqueFunction, RegisterEventHandler)
@@ -50,7 +51,9 @@ def count_robots(context: LaunchContext) -> list[LogInfo]:
5051
return [LogInfo(msg=[log_msg])]
5152

5253

53-
def generate_robot_actions(name: str = '', pose: dict[str, float] = {}) -> list[GroupAction]:
54+
def generate_robot_actions(
55+
name: str = '', pose: dict[str, float] = {}) -> \
56+
Optional[list[LaunchDescriptionEntity]]:
5457
"""Generate the actions to launch a robot with the given name and pose."""
5558
bringup_dir = get_package_share_directory('nav2_bringup')
5659
launch_dir = os.path.join(bringup_dir, 'launch')

‎nav2_bringup/launch/tb3_loopback_simulation_launch.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,11 @@ def generate_launch_description() -> LaunchDescription:
125125
rviz_cmd = IncludeLaunchDescription(
126126
PythonLaunchDescriptionSource(os.path.join(launch_dir, 'rviz_launch.py')),
127127
condition=IfCondition(use_rviz),
128-
launch_arguments={
129-
'namespace': namespace,
130-
'use_sim_time': 'True',
131-
'rviz_config': rviz_config_file,
132-
}.items(),
128+
launch_arguments=[
129+
('namespace', namespace),
130+
('use_sim_time', 'True'),
131+
('rviz_config', rviz_config_file),
132+
],
133133
)
134134

135135
bringup_cmd = IncludeLaunchDescription(

‎nav2_bringup/launch/tb4_loopback_simulation_launch.py‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ def generate_launch_description() -> LaunchDescription:
123123
rviz_cmd = IncludeLaunchDescription(
124124
PythonLaunchDescriptionSource(os.path.join(launch_dir, 'rviz_launch.py')),
125125
condition=IfCondition(use_rviz),
126-
launch_arguments={
127-
'namespace': namespace,
128-
'use_sim_time': 'True',
129-
'rviz_config': rviz_config_file,
130-
}.items(),
126+
launch_arguments=[
127+
('namespace', namespace),
128+
('use_sim_time', 'True'),
129+
('rviz_config', rviz_config_file),
130+
],
131131
)
132132

133133
bringup_cmd = IncludeLaunchDescription(
@@ -148,10 +148,10 @@ def generate_launch_description() -> LaunchDescription:
148148
loopback_sim_cmd = IncludeLaunchDescription(
149149
PythonLaunchDescriptionSource(
150150
os.path.join(loopback_sim_dir, 'loopback_simulation.launch.py')),
151-
launch_arguments={
152-
'params_file': params_file,
153-
'scan_frame_id': 'rplidar_link',
154-
}.items(),
151+
launch_arguments=[
152+
('params_file', params_file),
153+
('scan_frame_id', 'rplidar_link'),
154+
],
155155
)
156156

157157
static_publisher_cmd = Node(

‎nav2_bringup/launch/unique_multi_tb3_simulation_launch.py‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import os
2424
from pathlib import Path
2525
import tempfile
26+
from typing import TypedDict
2627

2728
from ament_index_python.packages import get_package_share_directory
2829
from launch import LaunchDescription
@@ -36,14 +37,26 @@
3637
from nav2_common.launch import LaunchConfigAsBool
3738

3839

40+
class RobotConfig(TypedDict):
41+
"""TypedDict for robot configuration."""
42+
43+
name: str
44+
x_pose: float
45+
y_pose: float
46+
z_pose: float
47+
roll: float
48+
pitch: float
49+
yaw: float
50+
51+
3952
def generate_launch_description() -> LaunchDescription:
4053
# Get the launch directory
4154
bringup_dir = get_package_share_directory('nav2_bringup')
4255
launch_dir = os.path.join(bringup_dir, 'launch')
4356
sim_dir = get_package_share_directory('nav2_minimal_tb3_sim')
4457

4558
# Names and poses of the robots
46-
robots = [
59+
robots: list[RobotConfig] = [
4760
{
4861
'name': 'robot1',
4962
'x_pose': 0.0,

‎nav2_common/nav2_common/launch/has_node_params.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import yaml
1717

1818

19-
class HasNodeParams(launch.Substitution): # type: ignore[misc]
19+
class HasNodeParams(launch.Substitution):
2020
"""
2121
Substitution that checks if a param file contains parameters for a node.
2222

‎nav2_common/nav2_common/launch/launch_config_as_bool.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from launch.utilities import perform_substitutions
1919

2020

21-
class LaunchConfigAsBool(launch.Substitution): # type: ignore[misc]
21+
class LaunchConfigAsBool(launch.Substitution):
2222
"""
2323
Converts a LaunchConfiguration value into a normalized boolean string: 'true' or 'false'.
2424

‎nav2_common/nav2_common/launch/replace_string.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
# limitations under the License.
1414

1515
import tempfile
16-
from typing import Optional
16+
from typing import IO, Optional
1717

1818
import launch
1919

2020

21-
class ReplaceString(launch.Substitution): # type: ignore[misc]
21+
class ReplaceString(launch.Substitution):
2222
"""
2323
Substitution that replaces strings on a given file.
2424
@@ -87,8 +87,8 @@ def resolve_replacements(self, context: launch.LaunchContext) -> dict[str, str]:
8787
)
8888
return resolved_replacements
8989

90-
def replace(self, input_file: launch.SomeSubstitutionsType,
91-
output_file: launch.SomeSubstitutionsType, replacements: dict[str, str]) -> None:
90+
def replace(self, input_file: IO[str], output_file: IO[str],
91+
replacements: dict[str, str]) -> None:
9292
for line in input_file:
9393
for key, value in replacements.items():
9494
if isinstance(key, str) and isinstance(value, str):

‎nav2_common/nav2_common/launch/rewritten_yaml.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def setValue(self, value: YamlValue) -> None:
3535
self.dictionary[self.dictKey] = value
3636

3737

38-
class RewrittenYaml(launch.Substitution): # type: ignore[misc]
38+
class RewrittenYaml(launch.Substitution):
3939
"""
4040
Substitution that modifies the given YAML file.
4141

‎nav2_costmap_2d/test/integration/costmap_tests_launch.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
from launch_testing.legacy import LaunchTestService
2525

2626

27-
def main(argv: list[str] = sys.argv[1:]) -> LaunchTestService:
27+
def main(argv: list[str] = sys.argv[1:]): # type: ignore[no-untyped-def]
2828
launchFile = os.path.join(
2929
os.getenv('TEST_LAUNCH_DIR', ''), 'costmap_map_server.launch.py'
3030
)
31-
testExecutable = os.getenv('TEST_EXECUTABLE')
31+
testExecutable = os.getenv('TEST_EXECUTABLE', '')
3232

3333
map_to_odom = launch_ros.actions.Node(
3434
package='tf2_ros',
@@ -86,11 +86,11 @@ def main(argv: list[str] = sys.argv[1:]) -> LaunchTestService:
8686
output='screen'
8787
)
8888

89-
lts = LaunchTestService()
90-
lts.add_test_action(ld, test1_action)
89+
lts = LaunchTestService() # type: ignore[no-untyped-call]
90+
lts.add_test_action(ld, test1_action) # type: ignore[no-untyped-call]
9191
ls = LaunchService(argv=argv)
9292
ls.include_launch_description(ld)
93-
return lts.run(ls)
93+
return lts.run(ls) # type: ignore[no-untyped-call]
9494

9595

9696
if __name__ == '__main__':

‎nav2_docking/opennav_docking/test/test_docking_server.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def generate_test_description() -> LaunchDescription:
9898
parameters=[{'autostart': True},
9999
{'node_names': ['docking_server']}]
100100
),
101-
launch_testing.actions.ReadyToTest(),
101+
launch_testing.actions.ReadyToTest(), # type: ignore[no-untyped-call]
102102
])
103103

104104

@@ -345,9 +345,9 @@ def test_docking_server(self) -> None:
345345
self.assertTrue(self.action_result[3].result.success)
346346

347347

348-
@launch_testing.post_shutdown_test()
348+
@launch_testing.post_shutdown_test() # type: ignore[no-untyped-call]
349349
class TestProcessOutput(unittest.TestCase):
350350

351351
def test_exit_code(self, proc_info: launch_testing.ProcInfoHandler) -> None:
352352
# Check that all processes in the launch exit with code 0
353-
launch_testing.asserts.assertExitCodes(proc_info)
353+
launch_testing.asserts.assertExitCodes(proc_info) # type: ignore[no-untyped-call]

0 commit comments

Comments
 (0)