From 7912e7e5bb3e40ea668e390630b31845cd58cc39 Mon Sep 17 00:00:00 2001 From: Omkar Kabde Date: Fri, 13 Mar 2026 14:36:59 +0530 Subject: [PATCH] Fix typing - last mypy ignored modules (#2172) * fix mypy errors * remove modules from pyproject * Apply suggestions from code review --------- Co-authored-by: Jirka Borovec <6035284+Borda@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- pyproject.toml | 27 +++++++++------------ src/supervision/detection/tools/smoother.py | 20 +++++++++------ src/supervision/key_points/skeletons.py | 8 +++--- 3 files changed, 27 insertions(+), 28 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index cf291408..58c657d2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -192,23 +192,18 @@ ignore_missing_imports = false explicit_package_bases = true strict = true mypy_path = "src" -# exclude = [ -# "docs", -# "test", -# "examples", -# "setup.py", -# ] - -[[tool.mypy.overrides]] -module = [ - "tests.*", - "examples.*", - # TODO: fix type errors in the following modules - "supervision.detection.tools.smoother", - "supervision.key_points.skeletons", - "supervision.metrics.utils.utils", +overrides = [ + # exclude = [ + # "docs", + # "test", + # "examples", + # "setup.py", + # ] + { module = [ + "tests.*", + "examples.*", + ], ignore_errors = true }, ] -ignore_errors = true [tool.autoflake] check = true diff --git a/src/supervision/detection/tools/smoother.py b/src/supervision/detection/tools/smoother.py index 32d80e59..52282f2d 100644 --- a/src/supervision/detection/tools/smoother.py +++ b/src/supervision/detection/tools/smoother.py @@ -3,6 +3,7 @@ from __future__ import annotations import warnings from collections import defaultdict, deque from copy import deepcopy +from typing import cast import numpy as np @@ -89,7 +90,9 @@ class DetectionsSmoother: length: The maximum number of frames to consider for smoothing detections. Defaults to 5. """ - self.tracks = defaultdict(lambda: deque(maxlen=length)) + self.tracks: defaultdict[int, deque[Detections | None]] = defaultdict( + lambda: deque(maxlen=length) + ) def update_with_detections(self, detections: Detections) -> Detections: """ @@ -109,9 +112,10 @@ class DetectionsSmoother: return detections for detection_idx in range(len(detections)): - tracker_id = detections.tracker_id[detection_idx] + tracker_id_value = detections.tracker_id[detection_idx] + tracker_id = int(tracker_id_value) - self.tracks[tracker_id].append(detections[detection_idx]) + self.tracks[tracker_id].append(cast(Detections, detections[detection_idx])) for track_id in self.tracks.keys(): if track_id not in detections.tracker_id: @@ -128,13 +132,13 @@ class DetectionsSmoother: if track is None: return None - track = [d for d in track if d is not None] - if len(track) == 0: + valid: list[Detections] = [d for d in track if d is not None] + if len(valid) == 0: return None - ret = deepcopy(track[0]) - ret.xyxy = np.mean([d.xyxy for d in track], axis=0) - ret.confidence = np.mean([d.confidence for d in track], axis=0) + ret = deepcopy(valid[0]) + ret.xyxy = np.mean([d.xyxy for d in valid], axis=0) + ret.confidence = np.mean([d.confidence for d in valid], axis=0) return ret diff --git a/src/supervision/key_points/skeletons.py b/src/supervision/key_points/skeletons.py index 64a22aef..71edfd65 100644 --- a/src/supervision/key_points/skeletons.py +++ b/src/supervision/key_points/skeletons.py @@ -4,7 +4,7 @@ Edges = tuple[tuple[int, int], ...] class Skeleton(Enum): - COCO: Edges = ( + COCO = ( (1, 2), (1, 3), (2, 3), @@ -24,7 +24,7 @@ class Skeleton(Enum): (17, 15), ) - GHUM: Edges = ( + GHUM = ( (1, 2), (1, 5), (2, 3), @@ -62,7 +62,7 @@ class Skeleton(Enum): (31, 33), ) - FACEMESH_TESSELATION_NO_IRIS: Edges = ( + FACEMESH_TESSELATION_NO_IRIS = ( (128, 35), (35, 140), (140, 128), @@ -2621,7 +2621,7 @@ class Skeleton(Enum): (256, 340), ) - FACEMESH_TESSELATION: Edges = ( + FACEMESH_TESSELATION = ( (474, 474), (475, 476), (476, 477),