Skip to content

Commit 53cd7da

Browse files
committed
More mypy formatting manually
1 parent 6bbe5cf commit 53cd7da

File tree

8 files changed

+43
-38
lines changed

8 files changed

+43
-38
lines changed

spot_wrapper/cam_webrtc_client.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def get_sdp_offer_from_spot_cam(self, token):
6464
result = response.json()
6565
return result["id"], base64.b64decode(result["sdp"]).decode()
6666

67-
def send_sdp_answer_to_spot_cam(self, token, offer_id, sdp_answer)-> None:
67+
def send_sdp_answer_to_spot_cam(self, token, offer_id, sdp_answer) -> None:
6868
headers = {"Authorization": f"Bearer {token}"}
6969
server_url = f"https://{self.hostname}:{self.sdp_port}/{self.sdp_filename}"
7070

@@ -83,26 +83,26 @@ async def start(self) -> None:
8383
offer_id, sdp_offer = self.get_sdp_offer_from_spot_cam(token)
8484

8585
@self.pc.on("icegatheringstatechange")
86-
def _on_ice_gathering_state_change()-> None:
86+
def _on_ice_gathering_state_change() -> None:
8787
print(f"ICE gathering state changed to {self.pc.iceGatheringState}")
8888

8989
@self.pc.on("signalingstatechange")
90-
def _on_signaling_state_change()-> None:
90+
def _on_signaling_state_change() -> None:
9191
print(f"Signaling state changed to: {self.pc.signalingState}")
9292

9393
@self.pc.on("icecandidate")
94-
def _on_ice_candidate(event)-> None:
94+
def _on_ice_candidate(event) -> None:
9595
print(f"Received candidate: {event.candidate}")
9696

9797
@self.pc.on("iceconnectionstatechange")
98-
async def _on_ice_connection_state_change()-> None:
98+
async def _on_ice_connection_state_change() -> None:
9999
print(f"ICE connection state changed to: {self.pc.iceConnectionState}")
100100

101101
if self.pc.iceConnectionState == "checking":
102102
self.send_sdp_answer_to_spot_cam(token, offer_id, self.pc.localDescription.sdp.encode())
103103

104104
@self.pc.on("track")
105-
def _on_track(track)-> None:
105+
def _on_track(track) -> None:
106106
print(f"Received track: {track.kind}")
107107

108108
if self.media_recorder:

spot_wrapper/cam_wrapper.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def get_screen(self) -> str:
175175
"""
176176
return self.client.get_screen()
177177

178-
def set_ir_colormap(self, colormap, min_temp: float, max_temp: float, auto_scale: bool=True) -> None:
178+
def set_ir_colormap(self, colormap, min_temp: float, max_temp: float, auto_scale: bool = True) -> None:
179179
"""
180180
Set the colormap used for the IR camera
181181
@@ -188,7 +188,7 @@ def set_ir_colormap(self, colormap, min_temp: float, max_temp: float, auto_scale
188188
"""
189189
self.client.set_ir_colormap(colormap, min_temp, max_temp, auto_scale)
190190

191-
def set_ir_meter_overlay(self, x: float, y: float, enable: bool=True) -> None:
191+
def set_ir_meter_overlay(self, x: float, y: float, enable: bool = True) -> None:
192192
"""
193193
Set the reticle position on the Spot CAM IR.
194194
@@ -281,7 +281,7 @@ def get_volume(self) -> float:
281281
"""
282282
return self.client.get_volume()
283283

284-
def play_sound(self, sound_name: str, gain: float=1.0) -> None:
284+
def play_sound(self, sound_name: str, gain: float = 1.0) -> None:
285285
"""
286286
Play a sound which is on the device
287287
@@ -935,6 +935,6 @@ def __init__(self, hostname, username, password, logger, port: typing.Optional[i
935935

936936
self._logger.info("Finished setting up spot cam wrapper components")
937937

938-
def shutdown(self)-> None:
938+
def shutdown(self) -> None:
939939
self._logger.info("Shutting down Spot CAM wrapper")
940940
self.image.shutdown_flag.set()

spot_wrapper/spot_arm.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def ensure_arm_power_and_stand(self) -> typing.Tuple[bool, str]:
136136

137137
return True, "Spot has an arm, is powered on, and standing"
138138

139-
def wait_for_arm_command_to_complete(self, cmd_id, timeout_sec: typing.Optional[float]=None) -> None:
139+
def wait_for_arm_command_to_complete(self, cmd_id, timeout_sec: typing.Optional[float] = None) -> None:
140140
"""
141141
Wait until a command issued to the arm complets. Wrapper around the SDK function for convenience
142142
@@ -295,7 +295,9 @@ def arm_joint_move(self, joint_targets: typing.List[float]) -> typing.Tuple[bool
295295
except Exception as e:
296296
return False, f"Exception occured during arm movement: {e}"
297297

298-
def create_wrench_from_forces_and_torques(self, forces: typing.List[float], torques: typing.List[float]) -> geometry_pb2.Wrench:
298+
def create_wrench_from_forces_and_torques(
299+
self, forces: typing.List[float], torques: typing.List[float]
300+
) -> geometry_pb2.Wrench:
299301
force = geometry_pb2.Vec3(x=forces[0], y=forces[1], z=forces[2])
300302
torque = geometry_pb2.Vec3(x=torques[0], y=torques[1], z=torques[2])
301303
return geometry_pb2.Wrench(force=force, torque=torque)

spot_wrapper/spot_eap.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def _start_query(self) -> typing.Optional[FutureWrapper]:
4747
callback_future = self._client.get_point_cloud_async(self._point_cloud_requests)
4848
callback_future.add_done_callback(self._callback)
4949
return callback_future
50+
return None
5051

5152

5253
class SpotEAP:

spot_wrapper/spot_graph_nav.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def _get_lease(self) -> Lease:
5151
self._lease = self._lease_wallet.get_lease()
5252
return self._lease
5353

54-
def _init_current_graph_nav_state(self):
54+
def _init_current_graph_nav_state(self) -> None:
5555
# Store the most recent knowledge of the state of the robot based on rpc calls.
5656
self._current_graph = None
5757
self._current_edges = {} # maps to_waypoint to list(from_waypoint)
@@ -75,7 +75,7 @@ def navigate_initial_localization(
7575
upload_path: str,
7676
initial_localization_fiducial: bool = True,
7777
initial_localization_waypoint: typing.Optional[str] = None,
78-
):
78+
) -> typing.Tuple[bool, str]:
7979
"""Navigate with graphnav.
8080
8181
Args:
@@ -112,7 +112,7 @@ def navigate_initial_localization(
112112

113113
return True, "Localization done!"
114114

115-
def navigate_to_existing_waypoint(self, waypoint_id: str):
115+
def navigate_to_existing_waypoint(self, waypoint_id: str) -> typing.Tuple[bool, str]:
116116
"""Navigate to an existing waypoint.
117117
Args:
118118
waypoint_id : Waypoint id string for where to go
@@ -121,7 +121,7 @@ def navigate_to_existing_waypoint(self, waypoint_id: str):
121121
resp = self._navigate_to(waypoint_id)
122122
return resp
123123

124-
def navigate_through_route(self, waypoint_ids: typing.List[str]):
124+
def navigate_through_route(self, waypoint_ids: typing.List[str]) -> typing.Tuple[bool, str]:
125125
"""
126126
Args:
127127
waypoint_ids: List[str] of waypoints to follow
@@ -146,7 +146,7 @@ def navigation_close_loops(self, close_fiducial_loops: bool, close_odometry_loop
146146
def optmize_anchoring(self) -> typing.Tuple[bool, str]:
147147
return self._optimize_anchoring()
148148

149-
def _write_bytes_while_download(self, filepath: str, data: bytes):
149+
def _write_bytes_while_download(self, filepath: str, data: bytes) -> None:
150150
"""Write data to a file.
151151
Args:
152152
filepath (str) : Path of file where data will be written.
@@ -257,14 +257,14 @@ def download_graph(self, download_path: str) -> typing.Tuple[bool, str]:
257257
# Downloading, reproducing, distributing or otherwise using the SDK Software
258258
# is subject to the terms and conditions of the Boston Dynamics Software
259259
# Development Kit License (20191101-BDSDK-SL).
260-
def _get_localization_state(self, *args):
260+
def _get_localization_state(self, *args) -> None:
261261
"""Get the current localization and state of the robot."""
262262
state = self._graph_nav_client.get_localization_state()
263263
self._logger.info(f"Got localization: \n{str(state.localization)}")
264264
odom_tform_body = get_odom_tform_body(state.robot_kinematics.transforms_snapshot)
265265
self._logger.info(f"Got robot state in kinematic odometry frame: \n{str(odom_tform_body)}")
266266

267-
def set_initial_localization_fiducial(self, *args):
267+
def set_initial_localization_fiducial(self, *args) -> None:
268268
"""Trigger localization when near a fiducial."""
269269
robot_state = self._robot_state_client.get_robot_state()
270270
current_odom_tform_body = get_odom_tform_body(robot_state.kinematic_state.transforms_snapshot).to_proto()
@@ -276,7 +276,7 @@ def set_initial_localization_fiducial(self, *args):
276276
ko_tform_body=current_odom_tform_body,
277277
)
278278

279-
def set_initial_localization_waypoint(self, *args):
279+
def set_initial_localization_waypoint(self, *args) -> None:
280280
"""Trigger localization to a waypoint."""
281281
# Take the first argument as the localization waypoint.
282282
if len(args) < 1:
@@ -316,7 +316,7 @@ def _download_current_graph(self):
316316
self._current_graph = graph
317317
return graph
318318

319-
def _download_full_graph(self, *args):
319+
def _download_full_graph(self, *args) -> None:
320320
"""Download the graph and snapshots from the robot."""
321321
graph = self._graph_nav_client.download_graph()
322322
if graph is None:
@@ -330,12 +330,12 @@ def _download_full_graph(self, *args):
330330
self._download_and_write_waypoint_snapshots(graph.waypoints)
331331
self._download_and_write_edge_snapshots(graph.edges)
332332

333-
def _write_full_graph(self, graph):
333+
def _write_full_graph(self, graph) -> None:
334334
"""Download the graph from robot to the specified, local filepath location."""
335335
graph_bytes = graph.SerializeToString()
336336
self._write_bytes(self._download_filepath, "/graph", graph_bytes)
337337

338-
def _download_and_write_waypoint_snapshots(self, waypoints):
338+
def _download_and_write_waypoint_snapshots(self, waypoints) -> None:
339339
"""Download the waypoint snapshots from robot to the specified, local filepath location."""
340340
num_waypoint_snapshots_downloaded = 0
341341
for waypoint in waypoints:
@@ -359,7 +359,7 @@ def _download_and_write_waypoint_snapshots(self, waypoints):
359359
)
360360
)
361361

362-
def _download_and_write_edge_snapshots(self, edges):
362+
def _download_and_write_edge_snapshots(self, edges) -> None:
363363
"""Download the edge snapshots from robot to the specified, local filepath location."""
364364
num_edge_snapshots_downloaded = 0
365365
num_to_download = 0
@@ -383,7 +383,7 @@ def _download_and_write_edge_snapshots(self, edges):
383383
"Downloaded {} of the total {} edge snapshots.".format(num_edge_snapshots_downloaded, num_to_download)
384384
)
385385

386-
def _write_bytes(self, filepath: str, filename: str, data):
386+
def _write_bytes(self, filepath: str, filename: str, data) -> None:
387387
"""Write data to a file."""
388388
os.makedirs(filepath, exist_ok=True)
389389
with open(filepath + filename, "wb+") as f:
@@ -655,7 +655,9 @@ def _match_edge(
655655
return map_pb2.Edge.Id(from_waypoint=waypoint1, to_waypoint=waypoint2)
656656
return None
657657

658-
def _auto_close_loops(self, close_fiducial_loops: bool, close_odometry_loops: bool, *args):
658+
def _auto_close_loops(
659+
self, close_fiducial_loops: bool, close_odometry_loops: bool, *args
660+
) -> typing.Tuple[bool, str]:
659661
"""Automatically find and close all loops in the graph."""
660662
response: map_processing_pb2.ProcessTopologyResponse = self._map_processing_client.process_topology(
661663
params=map_processing_pb2.ProcessTopologyRequest.Params(
@@ -676,7 +678,7 @@ def _auto_close_loops(self, close_fiducial_loops: bool, close_odometry_loops: bo
676678
else:
677679
return False, "Unknown error during map processing."
678680

679-
def _optimize_anchoring(self, *args):
681+
def _optimize_anchoring(self, *args) -> typing.Tuple[bool, str]:
680682
"""Call anchoring optimization on the server, producing a globally optimal reference frame for waypoints to be
681683
expressed in.
682684
"""
@@ -712,7 +714,7 @@ def _optimize_anchoring(self, *args):
712714
return False, status_mapping[response.status]
713715
return False, "Unknown error during anchoring optimization."
714716

715-
def _id_to_short_code(self, id: str):
717+
def _id_to_short_code(self, id: str) -> typing.Optional[str]:
716718
"""Convert a unique id to a 2 letter short code."""
717719
tokens = id.split("-")
718720
if len(tokens) > 2:
@@ -726,7 +728,7 @@ def _pretty_print_waypoints(
726728
short_code_to_count: typing.Dict[str, int],
727729
localization_id: str,
728730
logger: logging.Logger,
729-
):
731+
) -> None:
730732
short_code = self._id_to_short_code(waypoint_id)
731733
if short_code is None or short_code_to_count[short_code] != 1:
732734
# If the short code is not valid/unique, don't show it.

spot_wrapper/spot_images.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def __init__(
216216
continue
217217
self._image_requests_by_camera[camera] = {}
218218
image_types = IMAGE_SOURCES_BY_CAMERA[camera]
219-
quality = 75
219+
quality = 75.0
220220
for image_type in image_types:
221221
if image_type.startswith("depth"):
222222
image_format = image_pb2.Image.FORMAT_RAW

spot_wrapper/tests/test_graph_nav_util.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ def __init__(self) -> None:
1616

1717

1818
class TestGraphNavUtilShortCode:
19-
def test_id_to_short_code(self):
19+
def test_id_to_short_code(self) -> None:
2020
assert graph_nav_util._id_to_short_code("ebony-pug-mUzxLNq.TkGlVIxga+UKAQ==") == "ep"
2121
assert graph_nav_util._id_to_short_code("erose-simian-sug9xpxhCxgft7Mtbhr98A==") == "es"
2222

2323

2424
class TestGraphNavUtilFindUniqueWaypointId:
25-
def test_short_code(self):
25+
def test_short_code(self) -> None:
2626
# Set up
2727
self.logger = logging.Logger("test_graph_nav_util", level=logging.INFO)
2828
self.graph = map_pb2.Graph()
@@ -34,7 +34,7 @@ def test_short_code(self):
3434
# Test annotation name that is unknown
3535
assert graph_nav_util._find_unique_waypoint_id("ABCDEF", self.graph, self.name_to_id, self.logger) == "ABCDEF"
3636

37-
def test_short_code_with_graph(self):
37+
def test_short_code_with_graph(self) -> None:
3838
# Set up
3939
self.logger = logging.Logger("test_graph_nav_util", level=logging.INFO)
4040
self.graph = map_pb2.Graph()
@@ -51,7 +51,7 @@ def test_short_code_with_graph(self):
5151

5252

5353
class TestGraphNavUtilUpdateWaypointsEdges:
54-
def test_empty_graph(self):
54+
def test_empty_graph(self) -> None:
5555
self.logger = logging.Logger("test_graph_nav_util", level=logging.INFO)
5656

5757
# Test empty graph
@@ -61,7 +61,7 @@ def test_empty_graph(self):
6161
assert len(self.graph.waypoints) == 0
6262
assert len(self.graph.edges) == 0
6363

64-
def test_one_waypoint(self):
64+
def test_one_waypoint(self) -> None:
6565
self.logger = logging.Logger("test_graph_nav_util", level=logging.INFO)
6666

6767
# Test graph with 1 waypoint
@@ -80,7 +80,7 @@ def test_one_waypoint(self):
8080
assert len(self.name_to_id) == 1
8181
assert self.name_to_id["Node1"] == "ABCDE"
8282

83-
def test_two_waypoints_with_edge(self):
83+
def test_two_waypoints_with_edge(self) -> None:
8484
self.logger = logging.Logger("test_graph_nav_util", level=logging.INFO)
8585

8686
# Test graph with 2 waypoints and an edge between them
@@ -107,7 +107,7 @@ def test_two_waypoints_with_edge(self):
107107
assert self.name_to_id["Node1"] == "ABCDE"
108108
assert self.name_to_id["Node2"] == "DE"
109109

110-
def test_two_waypoints_with_edge_and_localization(self):
110+
def test_two_waypoints_with_edge_and_localization(self) -> None:
111111
self.logger = logging.Logger("test_graph_nav_util", level=logging.INFO)
112112

113113
# Test graph with 2 waypoints and an edge between them. Mainly affects the pretty print.

spot_wrapper/wrapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def robotToLocalTime(timestamp: Timestamp, robot: Robot) -> Timestamp:
101101
class MissingSpotArm(Exception):
102102
"""Raised when the arm is not available on the robot"""
103103

104-
def __init__(self, message: str ="Spot arm not available"):
104+
def __init__(self, message: str = "Spot arm not available"):
105105
# Call the base class constructor with the parameters it needs
106106
super().__init__(message)
107107

0 commit comments

Comments
 (0)