Skip to content

Commit 3401c4a

Browse files
committed
Fix various static typing issues.
1 parent 27b9e16 commit 3401c4a

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

colour_checker_detection/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
] = _version
7878
colour.utilities.ANCILLARY_RUNTIME_PACKAGES[ # pyright: ignore
7979
"opencv"
80-
] = cv2.__version__
80+
] = cv2.__version__ # pyright: ignore
8181

8282
del _version
8383

colour_checker_detection/detection/segmentation.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@
4141
MixinDataclassIterable,
4242
Structure,
4343
as_float_array,
44-
as_int_array,
4544
as_int,
45+
as_int_array,
46+
as_int_scalar,
4647
orient,
4748
usage_warning,
4849
)
@@ -210,7 +211,7 @@ def swatch_masks(
210211
return tuple(masks)
211212

212213

213-
def as_8_bit_BGR_image(image: ArrayLike) -> NDArrayFloat:
214+
def as_8_bit_BGR_image(image: ArrayLike) -> NDArrayInt:
214215
"""
215216
Convert and encodes given linear float *RGB* image to 8-bit *BGR* with
216217
*sRGB* reverse OETF.
@@ -280,7 +281,7 @@ def as_8_bit_BGR_image(image: ArrayLike) -> NDArrayFloat:
280281
if image.dtype == np.uint8:
281282
return image
282283

283-
return cv2.cvtColor(
284+
return cv2.cvtColor( # pyright: ignore
284285
cast(NDArrayFloat, cctf_encoding(image) * 255).astype(np.uint8),
285286
cv2.COLOR_RGB2BGR,
286287
)
@@ -346,11 +347,11 @@ def adjust_image(
346347
ratio = width / target_width
347348

348349
if np.allclose(ratio, 1):
349-
return cast(NDArrayFloat, image)
350+
return image
350351
else:
351-
return cv2.resize(
352+
return cv2.resize( # pyright: ignore
352353
image,
353-
(as_int(target_width), as_int(height / ratio)),
354+
(as_int_scalar(target_width), as_int_scalar(height / ratio)),
354355
interpolation=interpolation_method,
355356
)
356357

@@ -383,7 +384,7 @@ def is_square(contour: ArrayLike, tolerance: float = 0.015) -> bool:
383384

384385
return (
385386
cv2.matchShapes(
386-
contour,
387+
contour, # pyright: ignore
387388
np.array([[0, 0], [1, 0], [1, 1], [0, 1]]),
388389
cv2.CONTOURS_MATCH_I2,
389390
0.0,
@@ -418,7 +419,7 @@ def contour_centroid(contour: ArrayLike) -> Tuple[float, float]:
418419
(0.5, 0.5)
419420
"""
420421

421-
moments = cv2.moments(contour)
422+
moments = cv2.moments(contour) # pyright: ignore
422423
centroid = (
423424
moments["m10"] / moments["m00"],
424425
moments["m01"] / moments["m00"],
@@ -535,7 +536,7 @@ def crop_and_level_image_with_rectangle(
535536
if image_c.shape[0] > image_c.shape[1]:
536537
image_c = orient(image_c, "90 CW")
537538

538-
return image_c
539+
return image_c # pyright: ignore
539540

540541

541542
@dataclass
@@ -786,7 +787,10 @@ def colour_checkers_coordinates_segmentation(
786787

787788
if additional_data:
788789
return DataColourCheckersCoordinatesSegmentation(
789-
tuple(colour_checkers), tuple(clusters), tuple(swatches), image_c
790+
tuple(colour_checkers),
791+
tuple(clusters),
792+
tuple(swatches),
793+
image_c, # pyright: ignore
790794
)
791795
else:
792796
return colour_checkers
@@ -934,7 +938,9 @@ def extract_colour_checkers_segmentation(
934938
colour_checkers_coordinates_segmentation(image, **settings),
935939
):
936940
colour_checker = crop_and_level_image_with_rectangle(
937-
image, cv2.minAreaRect(rectangle), settings.interpolation_method
941+
image,
942+
cv2.minAreaRect(rectangle), # pyright: ignore
943+
settings.interpolation_method,
938944
)
939945
width, height = (colour_checker.shape[1], colour_checker.shape[0])
940946

@@ -974,9 +980,9 @@ def detect_colour_checkers_segmentation(
974980
samples: int = 16,
975981
additional_data: bool = False,
976982
**kwargs: Any,
977-
) -> Tuple[DataDetectColourCheckersSegmentation, ...] | Tuple[
978-
NDArrayFloat, ...
979-
]:
983+
) -> (
984+
Tuple[DataDetectColourCheckersSegmentation, ...] | Tuple[NDArrayFloat, ...]
985+
):
980986
"""
981987
Detect the colour checkers swatches in given image using segmentation.
982988

tasks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ def tag(ctx: Context):
376376
message_box("Tagging...")
377377
result = ctx.run("git rev-parse --abbrev-ref HEAD", hide="both")
378378

379-
if result.stdout.strip() == "develop":
379+
if result.stdout.strip() != "develop": # pyright: ignore
380380
raise RuntimeError("Are you still on a feature or master branch?")
381381

382382
with open(os.path.join(PYTHON_PACKAGE_NAME, "__init__.py")) as file_handle:
@@ -400,7 +400,7 @@ def tag(ctx: Context):
400400
version = ".".join((major_version, minor_version, change_version))
401401

402402
result = ctx.run("git ls-remote --tags upstream", hide="both")
403-
remote_tags = result.stdout.strip().split("\n")
403+
remote_tags = result.stdout.strip().split("\n") # pyright: ignore
404404
tags = set()
405405
for remote_tag in remote_tags:
406406
tags.add(

0 commit comments

Comments
 (0)