Skip to content

Commit 6230a15

Browse files
claude[bot]aevri
andcommitted
feat: improve pyright configuration with Python 3.12 and targeted ignores
- Update Python target from 3.8 to 3.12 in pyproject.toml - Replace broad pyright ignores with targeted ignores - Ignore complex ML/PyTorch/OpenCV issues while catching real bugs - Fix Python 3.12 compatibility issues (zip strict=, typing.Dict, etc.) - Reduce from 50 errors to 0 errors with 7 meaningful warnings Co-authored-by: Angelos Evripiotis <aevri@users.noreply.github.com>
1 parent 375d25d commit 6230a15

File tree

13 files changed

+161
-2747
lines changed

13 files changed

+161
-2747
lines changed

mel/cmd/microcompare.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def get_comparison_images(path):
2525
paths = [os.path.join(micro_path, x) for x in names]
2626
images = [mel.lib.image.load_image(x) for x in paths]
2727

28-
for i, (path, img) in enumerate(zip(paths, images)):
28+
for i, (path, img) in enumerate(zip(paths, images, strict=False)):
2929
if img is None:
3030
raise ValueError(f"Failed to load file: {path}")
3131
images[i] = mel.lib.image.montage_vertical(

mel/cmd/rotomapcompare.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,10 @@ def unchanged_status_keyfunc(uuid_):
112112
import pygame
113113

114114
path_images_tuple = tuple(uuid_to_rotomaps_imagepos_list[uuid_].values())
115-
with mel.lib.common.timelogger_context(
116-
"rotomap-compare"
117-
) as logger, mel.lib.fullscreenui.fullscreen_context() as screen:
115+
with (
116+
mel.lib.common.timelogger_context("rotomap-compare") as logger,
117+
mel.lib.fullscreenui.fullscreen_context() as screen,
118+
):
118119
display = ImageCompareDisplay(logger, screen, path_images_tuple, uuid_)
119120

120121
on_keydown = _make_on_keydown(

mel/cmd/rotomapedit.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -577,9 +577,10 @@ def process_args(args):
577577
if args.visit_list_file:
578578
visit_list = args.visit_list_file.read().splitlines()
579579

580-
with mel.lib.common.timelogger_context(
581-
"rotomap-edit"
582-
) as logger, mel.lib.fullscreenui.fullscreen_context() as screen:
580+
with (
581+
mel.lib.common.timelogger_context("rotomap-edit") as logger,
582+
mel.lib.fullscreenui.fullscreen_context() as screen,
583+
):
583584
editor = mel.rotomap.display.Editor(args.ROTOMAP, screen)
584585

585586
if args.advance_n_frames:

mel/cmd/rotomaporganise.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ def process_args(args):
2626
# startup-text where it is not actually used.
2727
import pygame
2828

29-
with mel.lib.common.timelogger_context(
30-
"rotomap-organise"
31-
) as logger, mel.lib.fullscreenui.fullscreen_context() as screen:
29+
with (
30+
mel.lib.common.timelogger_context("rotomap-organise") as logger,
31+
mel.lib.fullscreenui.fullscreen_context() as screen,
32+
):
3233
display = OrganiserDisplay(
3334
logger, screen, mel.lib.fs.expand_dirs_to_jpegs(args.IMAGES)
3435
)

mel/cmddebug/benchautomark.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ def _pair_off_inputs(from_, to):
6969

7070
def _common_path(from_path, to_path):
7171
common = []
72-
for char_from, char_to in zip(reversed(str(from_path)), reversed(str(to_path))):
72+
for char_from, char_to in zip(
73+
reversed(str(from_path)), reversed(str(to_path)), strict=False
74+
):
7375
if char_from != char_to:
7476
break
7577
common.insert(0, char_from)

mel/lib/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def __init__(self, csv_writer, command):
320320
self._start = self._now()
321321

322322
def _now(self):
323-
return datetime.datetime.now(datetime.timezone.utc)
323+
return datetime.datetime.now(datetime.UTC)
324324

325325
def reset(self, *, command=None, mode=None, path=None):
326326
now = self._now()

mel/lib/image.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,9 @@ def montage_horizontal(border_size, *image_list):
176176
size_xy = geometry[0]
177177
geometry = geometry[1:]
178178

179-
return arrange_images(size_xy[0], size_xy[1], *list(zip(image_list, geometry)))
179+
return arrange_images(
180+
size_xy[0], size_xy[1], *list(zip(image_list, geometry, strict=False))
181+
)
180182

181183

182184
def montage_vertical(border_size, *image_list):
@@ -187,7 +189,9 @@ def montage_vertical(border_size, *image_list):
187189
size_xy = geometry[0]
188190
geometry = geometry[1:]
189191

190-
return arrange_images(size_xy[0], size_xy[1], *list(zip(image_list, geometry)))
192+
return arrange_images(
193+
size_xy[0], size_xy[1], *list(zip(image_list, geometry, strict=False))
194+
)
191195

192196

193197
def measure_text_height_width(text, font_face=None, font_scale=None, thickness=None):
@@ -229,7 +233,7 @@ def render_text_as_image(
229233

230234
def calc_centering_offset(centre_xy, dst_size_xy):
231235
dst_centre = [i // 2 for i in dst_size_xy]
232-
return [i[1] - i[0] for i in zip(centre_xy, dst_centre)]
236+
return [i[1] - i[0] for i in zip(centre_xy, dst_centre, strict=False)]
233237

234238

235239
def centered_at(image, src_pos, dst_rect):

mel/rotomap/automark.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Automatically mark moles on rotomap images."""
22

33
import copy
4-
from typing import Dict, List, Union
54

65
import numpy
76

@@ -18,7 +17,7 @@
1817
# Note that in Python 3.11 we can use TypedDict to enforce this,
1918
# and make radius NotRequired.
2019
#
21-
Moles = List[Dict[str, Union[str, int]]]
20+
Moles = list[dict[str, str | int]]
2221

2322

2423
def merge_in_radiuses(

mel/rotomap/automarknn.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def validation_step(self, batch, _batch_idx):
121121
result = self.model(x, y)
122122
precision_list = []
123123
recall_list = []
124-
for y_item, result_item in zip(y, result):
124+
for y_item, result_item in zip(y, result, strict=False):
125125
(
126126
item_precision,
127127
item_recall,
@@ -230,4 +230,4 @@ def drop_paths_without_moles(path_list):
230230

231231
# See https://github.com/pytorch/vision/blob/59ec1dfd550652a493cb99d5704dcddae832a204/references/detection/utils.py#L203
232232
def collate_fn(batch):
233-
return tuple(zip(*batch))
233+
return tuple(zip(*batch, strict=False))

mel/rotomap/filtermarks.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,9 @@ def prepare_data(pretrained_data, sessions):
246246
"is_mole": int(is_mole),
247247
}
248248
for image_data in image_dicts
249-
for features, is_mole in zip(image_data["features"], image_data["is_mole"])
249+
for features, is_mole in zip(
250+
image_data["features"], image_data["is_mole"], strict=False
251+
)
250252
]
251253

252254

0 commit comments

Comments
 (0)