Skip to content

Commit

Permalink
Fix mypy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
srwi committed Jan 28, 2024
1 parent 26429c1 commit 8762cbc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 25 deletions.
14 changes: 7 additions & 7 deletions falsisignpy/falsisignpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class Mode(Enum):
class FalsiSignPy:
def __init__(self) -> None:
self._running: bool = False
self._window: Optional[sg.Window] = None
self._graph: Optional[sg.Graph] = None
self._window: sg.Window = None # type: ignore
self._graph: sg.Graph = None # type: ignore
self._event_handlers: Dict[str, Callable[[Dict[str, Any]], None]] = {}

self._current_page_figure_id: Optional[int] = None
Expand All @@ -32,7 +32,7 @@ def __init__(self) -> None:
self._loaded_signatures: Dict[str, Image.Image] = {}
self._signature_zoom_level: float = 1.0
self._scaling_factor: float = 1.0
self._pdf: Optional[PDF] = None
self._pdf: PDF = None # type: ignore
self._mode: Mode = Mode.EDIT

self._filters = [
Expand Down Expand Up @@ -421,10 +421,10 @@ def _on_windown_closed(self, _: Dict[str, Any]) -> None:
def start(self) -> None:
self._running = True

self._window: sg.Window = self._create_window()
self._window = self._create_window()
self._window.bind("<Configure>", "-CONFIGURE-")

self._graph: sg.Graph = self._window["-GRAPH-"]
self._graph = self._window["-GRAPH-"]
self._graph.bind("<Leave>", "+LEAVE")
self._graph.bind("<MouseWheel>", "+WHEEL")

Expand All @@ -447,9 +447,9 @@ def start(self) -> None:

for filter_ in self._filters:
key = filter_.__class__.__name__.upper()
self._event_handlers[f"-{key}-"] = lambda e, f=filter_, k=key: self._set_filter_enabled(f, e[f"-{k}-"])
self._event_handlers[f"-{key}-"] = lambda e, f=filter_, k=key: self._set_filter_enabled(f, e[f"-{k}-"]) # type: ignore
if filter_.strength_range is not None:
self._event_handlers[f"-{key}-STRENGTH-"] = lambda e, f=filter_, k=key: self._set_filter_strength(
self._event_handlers[f"-{key}-STRENGTH-"] = lambda e, f=filter_, k=key: self._set_filter_strength( # type: ignore
f, e[f"-{k}-STRENGTH-"]
)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ exclude = [
]
line-length = 120
indent-width = 4
target-version = "py311"
target-version = "py310"

[tool.ruff.lint]
select = ["ANN", "E", "F", "I"]
Expand Down
31 changes: 14 additions & 17 deletions test/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,41 @@
from typing import Tuple

import pytest
from PIL import Image

from falsisignpy import utils


@pytest.mark.parametrize(
"image_size,target_size,expected",
"image_size,target_size,expected_padded_image_coords",
[
(
(80, 160),
(40, 40),
(10, 0, 20, 40),
utils.PaddedImageInfo(left_offset=10, top_offset=0, width=20, height=40, scale=4.0),
),
(
(160, 80),
(40, 40),
(0, 10, 40, 20),
utils.PaddedImageInfo(left_offset=0, top_offset=10, width=40, height=20, scale=4.0),
),
(
(40, 40),
(80, 160),
(0, 40, 80, 80),
),
(
(270, 440),
(500, 600),
(66, 0, 368, 600),
utils.PaddedImageInfo(left_offset=0, top_offset=40, width=80, height=80, scale=0.5),
),
],
)
def test_calculate_padded_image_coordinates(image_size, target_size, expected):
left, top, width, height, _ = utils.calculate_padded_image_coordinates(image_size, target_size)
expected_left, expected_top, expected_width, expected_height = expected
assert expected_left == left
assert expected_top == top
assert expected_width == width
assert expected_height == height
def test_calculate_padded_image_coordinates(
image_size: Tuple[int, int],
target_size: Tuple[int, int],
expected_padded_image_coords: utils.PaddedImageInfo,
) -> None:
padded_image_coords = utils.calculate_padded_image_coordinates(image_size, target_size)
assert padded_image_coords == expected_padded_image_coords


def test_resize_and_pad_image():
def test_resize_and_pad_image() -> None:
image = Image.new("RGB", (270, 440), "red")
target_image = utils.resize_and_pad_image(image, (500, 600))
expected_image = Image.new("RGB", (500, 600), "gray")
Expand Down

0 comments on commit 8762cbc

Please sign in to comment.