Skip to content

Commit

Permalink
Type annotations for Flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
Xierumeng committed Feb 19, 2024
1 parent caea728 commit e1e68f9
Show file tree
Hide file tree
Showing 33 changed files with 84 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class AddRandom:
A new random number is generated every `__ADD_SWITCH_COUNT` times.
"""

def __init__(self, seed: int, max_random_term: int, add_change_count: int):
def __init__(self, seed: int, max_random_term: int, add_change_count: int) -> None:
"""
Constructor seeds the RNG and sets the max add and
number of adds before a new random number is chosen.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def add_random_worker(
input_queue: queue_proxy_wrapper.QueueProxyWrapper,
output_queue: queue_proxy_wrapper.QueueProxyWrapper,
controller: worker_controller.WorkerController,
):
) -> None:
"""
Worker process.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Concatenator:
Concatenates a prefix and suffix to the object.
"""

def __init__(self, prefix: str, suffix: str):
def __init__(self, prefix: str, suffix: str) -> None:
"""
Constructor sets the prefix and suffix.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def concatenator_worker(
suffix: str,
input_queue: queue_proxy_wrapper.QueueProxyWrapper,
controller: worker_controller.WorkerController,
):
) -> None:
"""
Worker process.
Expand Down
2 changes: 1 addition & 1 deletion documentation/multiprocess_example/countup/countup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Countup:
Increments its internal counter and outputs current counter.
"""

def __init__(self, start_thousands: int, max_iterations: int):
def __init__(self, start_thousands: int, max_iterations: int) -> None:
"""
Constructor initializes the start and max points.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def countup_worker(
max_iterations: int,
output_queue: queue_proxy_wrapper.QueueProxyWrapper,
controller: worker_controller.WorkerController,
):
) -> None:
"""
Worker process.
Expand Down
2 changes: 1 addition & 1 deletion documentation/multiprocess_example/intermediate_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class IntermediateStruct:
Example of a simple struct.
"""

def __init__(self, number: int, sentence: str):
def __init__(self, number: int, sentence: str) -> None:
"""
Constructor.
"""
Expand Down
2 changes: 1 addition & 1 deletion documentation/tests/add_or_multiply.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def add_or_multiply(self, num1: float, num2: float) -> float:

raise NotImplementedError

def swap_state(self):
def swap_state(self) -> None:
"""
Swaps internal state.
"""
Expand Down
2 changes: 1 addition & 1 deletion modules/cluster_estimation/cluster_estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def __init__(
min_activation_threshold: int,
min_new_points_to_run: int,
random_state: int,
):
) -> None:
"""
Private constructor, use create() method.
"""
Expand Down
2 changes: 1 addition & 1 deletion modules/cluster_estimation/cluster_estimation_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def cluster_estimation_worker(
input_queue: queue_proxy_wrapper.QueueProxyWrapper,
output_queue: queue_proxy_wrapper.QueueProxyWrapper,
controller: worker_controller.WorkerController,
):
) -> None:
"""
Estimation worker process.
Expand Down
2 changes: 1 addition & 1 deletion modules/data_merge/data_merge_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def data_merge_worker(
odometry_input_queue: queue_proxy_wrapper.QueueProxyWrapper,
output_queue: queue_proxy_wrapper.QueueProxyWrapper,
controller: worker_controller.WorkerController,
):
) -> None:
"""
Worker process. Expects telemetry to be more frequent than detections.
Queue is monotonic (i.e. timestamps never decrease).
Expand Down
4 changes: 2 additions & 2 deletions modules/decision/decision.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ScoredLandingPad:
Landing pad with score for decision.
"""

def __init__(self, landing_pad: object_in_world.ObjectInWorld, score: float):
def __init__(self, landing_pad: object_in_world.ObjectInWorld, score: float) -> None:
self.landing_pad = landing_pad
self.score = score

Expand All @@ -22,7 +22,7 @@ class Decision:
Chooses next action to take based on known landing pad information.
"""

def __init__(self, tolerance: float):
def __init__(self, tolerance: float) -> None:
self.__best_landing_pad: "object_in_world.ObjectInWorld | None" = None
self.__weighted_pads = []
self.__distance_tolerance = tolerance
Expand Down
16 changes: 9 additions & 7 deletions modules/decision/landing_pad_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ class LandingPadTracking:
positive, unconfirmed positive, or false positive.
"""

def __init__(self, distance_squared_threshold: float):
self.__unconfirmed_positives = []
self.__false_positives = []
self.__confirmed_positives = []
def __init__(self, distance_squared_threshold: float) -> None:
self.__unconfirmed_positives: "list[object_in_world.ObjectInWorld]" = []
self.__false_positives: "list[object_in_world.ObjectInWorld]" = []
self.__confirmed_positives: "list[object_in_world.ObjectInWorld]" = []

# Landing pads within the square root of this distance are considered the same landing pad
self.__distance_squared_threshold = distance_squared_threshold
Expand All @@ -34,7 +34,7 @@ def __is_similar(
) ** 2
return distance_squared < distance_squared_threshold

def mark_false_positive(self, detection: object_in_world.ObjectInWorld):
def mark_false_positive(self, detection: object_in_world.ObjectInWorld) -> None:
"""
Marks a detection as false positive and removes similar landing pads from the list of
unconfirmed positives.
Expand All @@ -46,13 +46,15 @@ def mark_false_positive(self, detection: object_in_world.ObjectInWorld):
if not self.__is_similar(landing_pad, detection, self.__distance_squared_threshold)
]

def mark_confirmed_positive(self, detection: object_in_world.ObjectInWorld):
def mark_confirmed_positive(self, detection: object_in_world.ObjectInWorld) -> None:
"""
Marks a detection as a confimred positive for future use.
"""
self.__confirmed_positives.append(detection)

def run(self, detections: "list[object_in_world.ObjectInWorld]"):
def run(
self, detections: "list[object_in_world.ObjectInWorld]"
) -> "tuple[bool, object_in_world.ObjectInWorld | None]":
"""
Updates the list of unconfirmed positives and returns the a first confirmed positive if
one exists, else the unconfirmed positive with the lowest variance.
Expand Down
4 changes: 2 additions & 2 deletions modules/decision_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ def create_land_at_absolute_position_command(

def __init__(
self,
class_private_create_key,
class_private_create_key: object,
command_type: CommandType,
command_x: float,
command_y: float,
command_z: float,
):
) -> None:
"""
Private constructor, use create() method.
"""
Expand Down
2 changes: 1 addition & 1 deletion modules/detect_target/detect_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(
override_full: bool,
show_annotations: bool = False,
save_name: str = "",
):
) -> None:
"""
device: name of target device to run inference on (i.e. "cpu" or cuda device 0, 1, 2, 3).
model_path: path to the YOLOv8 model.
Expand Down
2 changes: 1 addition & 1 deletion modules/detect_target/detect_target_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def detect_target_worker(
input_queue: queue_proxy_wrapper.QueueProxyWrapper,
output_queue: queue_proxy_wrapper.QueueProxyWrapper,
controller: worker_controller.WorkerController,
):
) -> None:
"""
Worker process.
Expand Down
4 changes: 2 additions & 2 deletions modules/detection_in_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ def create(

def __init__(
self,
class_private_create_key,
class_private_create_key: object,
vertices: np.ndarray,
centre: np.ndarray,
label: int,
confidence: float,
):
) -> None:
"""
Private constructor, use create() method.
"""
Expand Down
11 changes: 8 additions & 3 deletions modules/detections_and_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ def create(

return True, Detection(cls.__create_key, bounds, label, confidence)

def __init__(self, class_private_create_key, bounds: np.ndarray, label: int, confidence: float):
def __init__(
self, class_private_create_key: object, bounds: np.ndarray, label: int, confidence: float
) -> None:
"""
Private constructor, use create() method.
"""
Expand All @@ -50,6 +52,9 @@ def __init__(self, class_private_create_key, bounds: np.ndarray, label: int, con
self.confidence = confidence

def __repr__(self) -> str:
"""
String representation.
"""
representation = (
"cls: "
+ str(self.label)
Expand Down Expand Up @@ -104,7 +109,7 @@ def create(cls, timestamp: float) -> "tuple[bool, DetectionsAndTime | None]":

return True, DetectionsAndTime(cls.__create_key, timestamp)

def __init__(self, class_private_create_key, timestamp: float):
def __init__(self, class_private_create_key: object, timestamp: float) -> None:
"""
Private constructor, use create() method.
"""
Expand Down Expand Up @@ -134,7 +139,7 @@ def __len__(self) -> int:
"""
return len(self.detections)

def append(self, detection: Detection):
def append(self, detection: Detection) -> None:
"""
Appends a detected object.
"""
Expand Down
16 changes: 11 additions & 5 deletions modules/drone_odometry_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ def create(
"""
return True, DronePositionLocal(cls.__create_key, north, east, down)

def __init__(self, class_private_create_key, north: float, east: float, down: float):
def __init__(
self, class_private_create_key: object, north: float, east: float, down: float
) -> None:
"""
Private constructor, use create() method.
"""
Expand Down Expand Up @@ -69,13 +71,17 @@ def create_new(
return True, DroneOrientationLocal(cls.__create_key, orientation)

@classmethod
def create_wrap(cls, orientation: drone_odometry.DroneOrientation):
def create_wrap(
cls, orientation: drone_odometry.DroneOrientation
) -> "tuple[bool, DroneOrientationLocal | None]":
"""
Wrap existing orientation.
"""
return True, DroneOrientationLocal(cls.__create_key, orientation)

def __init__(self, class_private_create_key, orientation: drone_odometry.DroneOrientation):
def __init__(
self, class_private_create_key: object, orientation: drone_odometry.DroneOrientation
) -> None:
"""
Private constructor, use create() method.
"""
Expand Down Expand Up @@ -122,10 +128,10 @@ def create(

def __init__(
self,
class_private_create_key,
class_private_create_key: object,
position: DronePositionLocal,
orientation: DroneOrientationLocal,
):
) -> None:
"""
Private constructor, use create() method.
"""
Expand Down
4 changes: 2 additions & 2 deletions modules/flight_interface/flight_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ def create(cls, address: str, timeout_home: float) -> "tuple[bool, FlightInterfa

def __init__(
self,
class_private_create_key,
class_private_create_key: object,
controller: flight_controller.FlightController,
home_location: drone_odometry.DronePosition,
):
) -> None:
"""
Private constructor, use create() method.
"""
Expand Down
2 changes: 1 addition & 1 deletion modules/flight_interface/flight_interface_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def flight_interface_worker(
period: float,
output_queue: queue_proxy_wrapper.QueueProxyWrapper,
controller: worker_controller.WorkerController,
):
) -> None:
"""
Worker process.
Expand Down
8 changes: 4 additions & 4 deletions modules/geolocation/camera_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ def create(

def __init__(
self,
class_private_create_key,
class_private_create_key: object,
resolution_x: int,
resolution_y: int,
u_scalar: float,
v_scalar: float,
):
) -> None:
"""
Private constructor, use create() method.
"""
Expand Down Expand Up @@ -248,10 +248,10 @@ def create(

def __init__(
self,
class_private_create_key,
class_private_create_key: object,
vec_camera_on_drone_position: np.ndarray,
camera_to_drone_rotation_matrix: np.ndarray,
):
) -> None:
"""
Private constructor, use create() method.
"""
Expand Down
4 changes: 2 additions & 2 deletions modules/geolocation/geolocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ def create(

def __init__(
self,
class_private_create_key,
class_private_create_key: object,
camera_drone_extrinsics: camera_properties.CameraDroneExtrinsics,
perspective_transform_sources: "list[list[float]]",
rotated_source_vectors: "list[np.ndarray]",
):
) -> None:
"""
Private constructor, use create() method.
"""
Expand Down
2 changes: 1 addition & 1 deletion modules/geolocation/geolocation_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def geolocation_worker(
input_queue: queue_proxy_wrapper.QueueProxyWrapper,
output_queue: queue_proxy_wrapper.QueueProxyWrapper,
controller: worker_controller.WorkerController,
):
) -> None:
"""
Worker process.
Expand Down
4 changes: 3 additions & 1 deletion modules/image_and_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ def create(cls, image: np.ndarray) -> "tuple[bool, ImageAndTime | None]":

return True, ImageAndTime(cls.__create_key, image, current_time)

def __init__(self, class_private_create_key, image: np.ndarray, timestamp: float):
def __init__(
self, class_private_create_key: object, image: np.ndarray, timestamp: float
) -> None:
"""
Private constructor, use create() method.
"""
Expand Down
4 changes: 2 additions & 2 deletions modules/merged_odometry_detections.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ def create(

def __init__(
self,
class_private_create_key,
class_private_create_key: object,
odometry_local: drone_odometry_local.DroneOdometryLocal,
detections: "list[detections_and_time.Detection]",
):
) -> None:
"""
Private constructor, use create() method.
"""
Expand Down
Loading

0 comments on commit e1e68f9

Please sign in to comment.