From edfe0a944acefc9bb0e20168c559531dd7fe04d9 Mon Sep 17 00:00:00 2001 From: Onuralp SEZER Date: Tue, 15 Jul 2025 00:16:40 +0300 Subject: [PATCH] =?UTF-8?q?refactor:=20=F0=9F=9B=A0=EF=B8=8F=20update=20ty?= =?UTF-8?q?pe=20hints=20to=20use=20built-in=20types=20in=20VLM=20and=20val?= =?UTF-8?q?idation=20functions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .pre-commit-config.yaml | 8 ++++++++ supervision/detection/vlm.py | 8 ++++---- supervision/validators/__init__.py | 3 ++- test/detection/test_vlm.py | 6 +++--- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 98d8d364..85b49dfb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -53,3 +53,11 @@ repos: - id: codespell additional_dependencies: - tomli + + - repo: https://github.com/asottile/pyupgrade + rev: v3.20.0 + hooks: + - id: pyupgrade + args: ["--py39-plus"] + additional_dependencies: + - tomli diff --git a/supervision/detection/vlm.py b/supervision/detection/vlm.py index c07f4170..d98405e3 100644 --- a/supervision/detection/vlm.py +++ b/supervision/detection/vlm.py @@ -118,7 +118,7 @@ def from_paligemma( Args: result: String containing paligemma-formatted locations and labels. - resolution_wh: Tuple (width, height) to which we scale the box coordinates. + resolution_wh: tuple (width, height) to which we scale the box coordinates. classes: Optional list of valid class names. If provided, boxes and labels not in this list are filtered out. @@ -423,9 +423,9 @@ def from_google_gemini_2_0( def from_google_gemini_2_5( result: str, - resolution_wh: Tuple[int, int], - classes: Optional[List[str]] = None, -) -> Tuple[ + resolution_wh: tuple[int, int], + classes: Optional[list[str]] = None, +) -> tuple[ np.ndarray, Optional[np.ndarray], np.ndarray, diff --git a/supervision/validators/__init__.py b/supervision/validators/__init__.py index 5a2ffc98..97fedabd 100644 --- a/supervision/validators/__init__.py +++ b/supervision/validators/__init__.py @@ -1,4 +1,5 @@ from typing import Any + import numpy as np @@ -139,7 +140,7 @@ def validate_keypoints_fields( validate_data(data, n) -def validate_resolution(resolution: Any) -> Tuple[int, int]: +def validate_resolution(resolution: Any) -> tuple[int, int]: if not (isinstance(resolution, tuple) and len(resolution) == 2): raise ValueError( f""" diff --git a/test/detection/test_vlm.py b/test/detection/test_vlm.py index 54a7cf47..93e030a6 100644 --- a/test/detection/test_vlm.py +++ b/test/detection/test_vlm.py @@ -1080,10 +1080,10 @@ def test_florence_2( def test_from_google_gemini_2_5( exception, result: str, - resolution_wh: Tuple[int, int], - classes: Optional[List[str]], + resolution_wh: tuple[int, int], + classes: Optional[list[str]], expected_results: Optional[ - Tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray, np.ndarray] + tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray, np.ndarray] ], ): with exception: