Skip to content

Commit

Permalink
Added generic annotation for mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
omar-abdelgawad committed Jul 10, 2024
1 parent 1e1d319 commit 3b227d3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions invesalius/gui/widgets/clut_raycasting.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ def __init__(self, parent: wx.Window, id: int):
parent -- parent of this frame
"""
super().__init__(parent, id)
self.points: List[List[Dict]] = []
self.colours: List[List[Dict]] = []
self.points: List[List[Dict[str, float]]] = []
self.colours: List[List[Dict[str, float]]] = []
self.curves: List[Curve] = []
self.init: float = -1024
self.end: float = 2000
Expand Down Expand Up @@ -653,7 +653,7 @@ def __sort_pixel_points(self) -> None:
width when the user interacts with this widgets.
"""
for n, (point, colour) in enumerate(zip(self.points, self.colours)):
point_colour: Iterable[Tuple[Dict, Dict]] = zip(point, colour)
point_colour: Iterable[Tuple[Dict[str, float], Dict[str, float]]] = zip(point, colour)
point_colour = sorted(point_colour, key=lambda x: x[0]["x"])
self.points[n] = [i[0] for i in point_colour]
self.colours[n] = [i[1] for i in point_colour]
Expand Down Expand Up @@ -687,7 +687,7 @@ def CalculatePixelPoints(self) -> None:
self.curves.append(curve)
self._build_histogram()

def HounsfieldToPixel(self, graylevel: float) -> float:
def HounsfieldToPixel(self, graylevel: float) -> int:
"""
Given a Hounsfield point returns a pixel point in the canvas.
"""
Expand All @@ -697,7 +697,7 @@ def HounsfieldToPixel(self, graylevel: float) -> float:
x = (graylevel - self.init) * proportion + TOOLBAR_SIZE
return x

def OpacityToPixel(self, opacity: int) -> int:
def OpacityToPixel(self, opacity: float) -> int:
"""
Given a Opacity point returns a pixel point in the canvas.
"""
Expand Down Expand Up @@ -725,7 +725,7 @@ def PixelToOpacity(self, y: int) -> float:
opacity = (height - y + self.padding) * 1.0 / height
return opacity

def SetRaycastPreset(self, preset: Dict) -> None:
def SetRaycastPreset(self, preset: Dict[str, List[List[Dict[str, float]]]]) -> None:
if not preset:
self.to_draw_points = 0
elif preset["advancedCLUT"]:
Expand Down
4 changes: 2 additions & 2 deletions invesalius/gui/widgets/slice_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# --------------------------------------------------------------------------
import sys
from collections import OrderedDict
from typing import Dict, Union
from typing import Dict, Optional, Union

import wx

Expand Down Expand Up @@ -48,7 +48,7 @@ class SliceMenu(wx.Menu):
def __init__(self) -> None:
wx.Menu.__init__(self)
self.ID_TO_TOOL_ITEM: Dict[Union[wx.WindowIDRef, int], wx.MenuItem] = {}
self.cdialog = None
self.cdialog: Optional[ClutImagedataDialog] = None

# ------------ Sub menu of the window and level ----------
submenu_wl = wx.Menu()
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ follow_imports = "normal"
explicit_package_bases = true
disable_error_code = ["attr-defined", "no-redef"]

[mypy-invesalius.gui.widgets.listctrl]
[[tool.mypy.overrides]]
module = 'invesalius.gui.widgets.listctrl'
ignore_errors = true

[[tool.mypy.overrides]]
module = 'wx.*'
disable_error_code = ["no-redef"] # because some classes are redefined in the stubs
Expand Down

0 comments on commit 3b227d3

Please sign in to comment.