Skip to content

Commit 54f823d

Browse files
authored
fix: ament_mypy errors (#1039)
1 parent e5a672f commit 54f823d

File tree

8 files changed

+30
-12
lines changed

8 files changed

+30
-12
lines changed

rosapi/src/rosapi/params.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
import fnmatch
3535
from json import dumps, loads
36+
from typing import TYPE_CHECKING
3637

3738
from rcl_interfaces.msg import Parameter, ParameterType, ParameterValue
3839
from rcl_interfaces.srv import GetParameters, ListParameters, SetParameters
@@ -44,6 +45,9 @@
4445
from rosapi.async_helper import futures_wait_for
4546
from rosapi.proxy import get_nodes
4647

48+
if TYPE_CHECKING:
49+
from rclpy.client import Client
50+
4751
""" Methods to interact with the param server. Values have to be passed
4852
as JSON in order to facilitate dynamically typed SRV messages """
4953

@@ -120,7 +124,7 @@ async def _set_param(node_name: str, name: str, value: str, parameter_type=None)
120124
setattr(parameter.value, _parameter_type_mapping[parameter_type], loads(value))
121125

122126
assert _node is not None
123-
client = _node.create_client(
127+
client: Client = _node.create_client(
124128
SetParameters,
125129
f"{node_name}/set_parameters",
126130
callback_group=MutuallyExclusiveCallbackGroup(),
@@ -175,7 +179,7 @@ async def _get_param(node_name: str, name: str) -> ParameterValue:
175179
"""Internal helper function for get_param"""
176180

177181
assert _node is not None
178-
client = _node.create_client(
182+
client: Client = _node.create_client(
179183
GetParameters,
180184
f"{node_name}/get_parameters",
181185
callback_group=MutuallyExclusiveCallbackGroup(),
@@ -250,7 +254,7 @@ async def get_param_names(params_glob: str | None) -> list[str]:
250254
if node_name == _node.get_fully_qualified_name():
251255
continue
252256

253-
client = _node.create_client(
257+
client: Client = _node.create_client(
254258
ListParameters,
255259
f"{node_name}/list_parameters",
256260
callback_group=MutuallyExclusiveCallbackGroup(),

rosbridge_library/src/rosbridge_library/internal/actions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def send_goal(
167167
args_to_action_goal_instance(action_name, inst, args)
168168

169169
self.result = None
170-
client = ActionClient(node_handle, action_class, action_name)
170+
client: ActionClient = ActionClient(node_handle, action_class, action_name)
171171
client.wait_for_server(timeout_sec=self.server_timeout_time)
172172
send_goal_future = client.send_goal_async(inst, feedback_callback=feedback_cb)
173173
send_goal_future.add_done_callback(self.goal_response_cb)

rosbridge_library/src/rosbridge_library/internal/services.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
# POSSIBILITY OF SUCH DAMAGE.
3232

3333
from threading import Event, Thread
34-
from typing import Any, Callable, Optional
34+
from typing import TYPE_CHECKING, Any, Callable, Optional
3535

3636
from rclpy.callback_groups import ReentrantCallbackGroup
3737
from rclpy.expand_topic_name import expand_topic_name
@@ -45,6 +45,9 @@
4545
get_service_request_instance,
4646
)
4747

48+
if TYPE_CHECKING:
49+
from rclpy.client import Client
50+
4851

4952
class InvalidServiceException(Exception):
5053
def __init__(self, service_name) -> None:
@@ -146,7 +149,7 @@ def call_service(
146149
# Populate the instance with the provided args
147150
args_to_service_request_instance(service, inst, args)
148151

149-
client = node_handle.create_client(
152+
client: Client = node_handle.create_client(
150153
service_class, service, callback_group=ReentrantCallbackGroup()
151154
)
152155

rosbridge_server/test/websocket/advertise_action.test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ async def test_two_concurrent_calls(self, node: Node, make_client):
4646
"type": "example_interfaces/Fibonacci",
4747
}
4848
)
49-
client = ActionClient(node, Fibonacci, "/test_fibonacci_action")
49+
client: ActionClient = ActionClient(node, Fibonacci, "/test_fibonacci_action")
5050
client.wait_for_server()
5151

5252
requests_future, ws_client.message_handler = expect_messages(

rosbridge_server/test/websocket/advertise_action_feedback.test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ async def test_feedback(self, node: Node, make_client):
4343
"type": "example_interfaces/Fibonacci",
4444
}
4545
)
46-
client = ActionClient(node, Fibonacci, "/test_fibonacci_action")
46+
client: ActionClient = ActionClient(node, Fibonacci, "/test_fibonacci_action")
4747
client.wait_for_server()
4848

4949
requests_future, ws_client.message_handler = expect_messages(

rosbridge_server/test/websocket/advertise_service.test.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22
import os
33
import sys
44
import unittest
5+
from typing import TYPE_CHECKING
56

67
from rclpy.node import Node
78
from std_srvs.srv import SetBool
89
from twisted.python import log
910

11+
if TYPE_CHECKING:
12+
from rclpy.client import Client
13+
1014
sys.path.append(os.path.dirname(__file__)) # enable importing from common.py in this directory
1115

1216
import common # noqa: E402
@@ -28,7 +32,7 @@ async def test_two_concurrent_calls(self, node: Node, make_client):
2832
"service": "/test_service",
2933
}
3034
)
31-
client = node.create_client(SetBool, "/test_service")
35+
client: Client = node.create_client(SetBool, "/test_service")
3236
client.wait_for_service()
3337

3438
requests_future, ws_client.message_handler = expect_messages(

rosbridge_server/test/websocket/advertise_service_duplicate.test.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import os
22
import sys
33
import unittest
4+
from typing import TYPE_CHECKING
45

56
from rclpy.node import Node
67
from std_srvs.srv import SetBool
78
from twisted.python import log
89

10+
if TYPE_CHECKING:
11+
from rclpy.client import Client
12+
913
sys.path.append(os.path.dirname(__file__)) # enable importing from common.py in this directory
1014

1115
import common # noqa: E402
@@ -27,7 +31,7 @@ async def test_double_advertise(self, node: Node, make_client):
2731
"service": "/test_service",
2832
}
2933
)
30-
client = node.create_client(SetBool, "/test_service")
34+
client: Client = node.create_client(SetBool, "/test_service")
3135
client.wait_for_service()
3236

3337
requests1_future, ws_client1.message_handler = expect_messages(

rosbridge_server/test/websocket/common.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import functools
22
import json
3-
from typing import Any, Awaitable, Callable
3+
from typing import TYPE_CHECKING, Any, Awaitable, Callable
44

55
import launch
66
import launch_ros
@@ -15,6 +15,9 @@
1515
from twisted.internet import reactor
1616
from twisted.internet.endpoints import TCP4ClientEndpoint
1717

18+
if TYPE_CHECKING:
19+
from rclpy.client import Client
20+
1821

1922
class TestClientProtocol(WebSocketClientProtocol):
2023
"""
@@ -83,7 +86,7 @@ async def get_server_port(node: Node) -> int:
8386
"""
8487
Returns the port which the WebSocket server is running on
8588
"""
86-
client = node.create_client(GetParameters, "/rosbridge_websocket/get_parameters")
89+
client: Client = node.create_client(GetParameters, "/rosbridge_websocket/get_parameters")
8790
try:
8891
if not client.wait_for_service(5):
8992
raise RuntimeError("GetParameters service not available")

0 commit comments

Comments
 (0)