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>
This commit is contained in:
Omkar Kabde 2026-03-13 14:36:59 +05:30 committed by GitHub
parent 2dee466abc
commit 7912e7e5bb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 27 additions and 28 deletions

View File

@ -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

View File

@ -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

View File

@ -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),