Skip to content

Commit

Permalink
Adapt to new mypy rules
Browse files Browse the repository at this point in the history
 - add optional types to function parameters
 - improve typing
  • Loading branch information
ch-sa committed Nov 13, 2022
1 parent c7de071 commit e21ba7e
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 21 deletions.
29 changes: 22 additions & 7 deletions labelCloud/control/bbox_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ def update_rotation(self, axis: str, value: float) -> None:

@only_zrotation_decorator
@has_active_bbox_decorator
def rotate_around_x(self, dangle: float = None, clockwise: bool = False) -> None:
def rotate_around_x(
self, dangle: Optional[float] = None, clockwise: bool = False
) -> None:
dangle = dangle or config.getfloat("LABEL", "std_rotation")
if clockwise:
dangle *= -1
Expand All @@ -184,7 +186,9 @@ def rotate_around_x(self, dangle: float = None, clockwise: bool = False) -> None

@only_zrotation_decorator
@has_active_bbox_decorator
def rotate_around_y(self, dangle: float = None, clockwise: bool = False) -> None:
def rotate_around_y(
self, dangle: Optional[float] = None, clockwise: bool = False
) -> None:
dangle = dangle or config.getfloat("LABEL", "std_rotation")
if clockwise:
dangle *= -1
Expand All @@ -194,7 +198,10 @@ def rotate_around_y(self, dangle: float = None, clockwise: bool = False) -> None

@has_active_bbox_decorator
def rotate_around_z(
self, dangle: float = None, clockwise: bool = False, absolute: bool = False
self,
dangle: Optional[float] = None,
clockwise: bool = False,
absolute: bool = False,
) -> None:
dangle = dangle or config.getfloat("LABEL", "std_rotation")
if clockwise:
Expand Down Expand Up @@ -225,7 +232,9 @@ def rotate_with_mouse(
self.rotate_around_z(x_angle)

@has_active_bbox_decorator
def translate_along_x(self, distance: float = None, left: bool = False) -> None:
def translate_along_x(
self, distance: Optional[float] = None, left: bool = False
) -> None:
distance = distance or config.getfloat("LABEL", "std_translation")
if left:
distance *= -1
Expand All @@ -237,7 +246,9 @@ def translate_along_x(self, distance: float = None, left: bool = False) -> None:
active_bbox.set_y_translation(active_bbox.center[1] + distance * sinz)

@has_active_bbox_decorator
def translate_along_y(self, distance: float = None, forward: bool = False) -> None:
def translate_along_y(
self, distance: Optional[float] = None, forward: bool = False
) -> None:
distance = distance or config.getfloat("LABEL", "std_translation")
if forward:
distance *= -1
Expand All @@ -249,7 +260,9 @@ def translate_along_y(self, distance: float = None, forward: bool = False) -> No
active_bbox.set_y_translation(active_bbox.center[1] + distance * bu * cosz)

@has_active_bbox_decorator
def translate_along_z(self, distance: float = None, down: bool = False) -> None:
def translate_along_z(
self, distance: Optional[float] = None, down: bool = False
) -> None:
distance = distance or config.getfloat("LABEL", "std_translation")
if down:
distance *= -1
Expand All @@ -258,7 +271,9 @@ def translate_along_z(self, distance: float = None, down: bool = False) -> None:
active_bbox.set_z_translation(active_bbox.center[2] + distance)

@has_active_bbox_decorator
def scale(self, length_increase: float = None, decrease: bool = False) -> None:
def scale(
self, length_increase: Optional[float] = None, decrease: bool = False
) -> None:
"""Scales a bounding box while keeping the previous aspect ratio.
:param length_increase: factor by which the length should be increased
Expand Down
6 changes: 4 additions & 2 deletions labelCloud/control/label_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from pathlib import Path
from typing import List
from typing import List, Optional

from ..io.labels import BaseLabelFormat, CentroidFormat, KittiFormat, VerticesFormat
from ..model import BBox
Expand Down Expand Up @@ -45,7 +45,9 @@ class LabelManager(object):
EXPORT_PRECISION = config.getint("LABEL", "export_precision")

def __init__(
self, strategy: str = STD_LABEL_FORMAT, path_to_label_folder: Path = None
self,
strategy: str = STD_LABEL_FORMAT,
path_to_label_folder: Optional[Path] = None,
) -> None:
self.label_folder = path_to_label_folder or config.getpath(
"FILE", "label_folder"
Expand Down
5 changes: 2 additions & 3 deletions labelCloud/control/pcd_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
from shutil import copyfile
from typing import TYPE_CHECKING, List, Optional, Set, Tuple

import pkg_resources

import numpy as np
import open3d as o3d
import pkg_resources

from ..definitions.types import Point3D
from ..io.pointclouds import BasePointCloudHandler, Open3DHandler
Expand Down Expand Up @@ -263,7 +262,7 @@ def get_perspective(self) -> Tuple[float, float, float]:

# UPDATE GUI

def update_pcd_infos(self, pointcloud_label: str = None) -> None:
def update_pcd_infos(self, pointcloud_label: Optional[str] = None) -> None:
self.view.set_pcd_label(pointcloud_label or self.pcd_name or "")
self.view.update_progress(self.current_id)

Expand Down
8 changes: 4 additions & 4 deletions labelCloud/model/bbox.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from typing import List
from typing import List, Optional

import numpy as np
import numpy.typing as npt
Expand All @@ -19,9 +19,9 @@ def __init__(
cx: float,
cy: float,
cz: float,
length: float = None,
width: float = None,
height: float = None,
length: Optional[float] = None,
width: Optional[float] = None,
height: Optional[float] = None,
) -> None:
self.center: Point3D = (cx, cy, cz)
self.length: float = length or config.getfloat(
Expand Down
2 changes: 1 addition & 1 deletion labelCloud/model/point_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def __init__(
self.init_translation: Point3D = init_translation or calculate_init_translation(
self.center, self.pcd_mins, self.pcd_maxs
)
self.init_rotation: Rotations3D = init_rotation or (0, 0, 0)
self.init_rotation: Rotations3D = init_rotation or tuple([0, 0, 0]) # type: ignore

# Point cloud transformations
self.trans_x, self.trans_y, self.trans_z = self.init_translation
Expand Down
2 changes: 2 additions & 0 deletions labelCloud/tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os

import pytest

from labelCloud.control.controller import Controller
from labelCloud.model.bbox import BBox
from labelCloud.view.gui import GUI
Expand All @@ -17,6 +18,7 @@ def startup_pyqt(qtbot, qapp):

# Setup Model-View-Control structure
control = Controller()

view = GUI(control)
qtbot.addWidget(view)
qtbot.addWidget(view.gl_widget)
Expand Down
8 changes: 5 additions & 3 deletions labelCloud/view/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import re
from pathlib import Path
from typing import TYPE_CHECKING, Set
from typing import TYPE_CHECKING, Optional, Set

import pkg_resources
from PyQt5 import QtCore, QtGui, QtWidgets, uic
Expand Down Expand Up @@ -447,7 +447,7 @@ def init_progress(self, min_value, max_value):
def update_progress(self, value) -> None:
self.progressbar_pcds.setValue(value)

def update_curr_class_edit(self, force: str = None) -> None:
def update_curr_class_edit(self, force: Optional[str] = None) -> None:
if force is not None:
self.edit_current_class.setText(force)
else:
Expand Down Expand Up @@ -564,7 +564,9 @@ def change_label_folder(self) -> None:
)
logging.info("Changed label folder to %s!" % path_to_folder)

def update_default_object_class_menu(self, new_classes: Set[str] = None) -> None:
def update_default_object_class_menu(
self, new_classes: Optional[Set[str]] = None
) -> None:
object_classes = {
str(class_name) for class_name in config.getlist("LABEL", "object_classes")
}
Expand Down
2 changes: 1 addition & 1 deletion labelCloud/view/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def paintGL(self) -> None:

# Translates the 2D cursor position from screen plane into 3D world space coordinates
def get_world_coords(
self, x: float, y: float, z: float = None, correction: bool = False
self, x: float, y: float, z: Optional[float] = None, correction: bool = False
) -> Tuple[float, float, float]:
x *= self.DEVICE_PIXEL_RATIO # For fixing mac retina bug
y *= self.DEVICE_PIXEL_RATIO
Expand Down

0 comments on commit e21ba7e

Please sign in to comment.