Skip to content

Commit 27e5fa3

Browse files
committed
Refactor deprecation handling for LMM and from_lmm, replacing @deprecated with warnings.warn
1 parent eba1d64 commit 27e5fa3

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

supervision/detection/core.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
from collections.abc import Iterator
44
from dataclasses import dataclass, field
5-
from enum import Enum
5+
import warnings
66
from functools import reduce
77
from typing import Any
88

99
import numpy as np
10-
from deprecate import deprecated
1110

1211
from supervision.config import (
1312
CLASS_NAME_DATA_FIELD,
@@ -818,11 +817,6 @@ def from_paddledet(cls, paddledet_result) -> Detections:
818817
)
819818

820819
@classmethod
821-
@deprecated(
822-
target=None,
823-
deprecated_in="0.26.0",
824-
remove_in="0.30.0",
825-
)
826820
def from_lmm(cls, lmm: LMM | str, result: str | dict, **kwargs: Any) -> Detections:
827821
"""
828822
!!! deprecated "Deprecated"
@@ -1201,6 +1195,14 @@ def from_lmm(cls, lmm: LMM | str, result: str | dict, **kwargs: Any) -> Detectio
12011195
```
12021196
""" # noqa: E501
12031197

1198+
warnings.warn(
1199+
"`Detections.from_lmm` is deprecated since `supervision-0.26.0` "
1200+
"and will be removed in `supervision-0.30.0`. "
1201+
"Use `Detections.from_vlm` instead.",
1202+
FutureWarning,
1203+
stacklevel=2,
1204+
)
1205+
12041206
# filler logic mapping old from_lmm to new from_vlm
12051207
lmm_to_vlm = {
12061208
LMM.PALIGEMMA: VLM.PALIGEMMA,
@@ -1211,8 +1213,7 @@ def from_lmm(cls, lmm: LMM | str, result: str | dict, **kwargs: Any) -> Detectio
12111213
LMM.GOOGLE_GEMINI_2_5: VLM.GOOGLE_GEMINI_2_5,
12121214
}
12131215

1214-
# (this works even if the LMM enum is wrapped by @deprecated)
1215-
if isinstance(lmm, Enum) and lmm.__class__.__name__ == "LMM":
1216+
if isinstance(lmm, LMM):
12161217
vlm = lmm_to_vlm[lmm]
12171218

12181219
elif isinstance(lmm, str):

supervision/detection/vlm.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,26 @@
55
import io
66
import json
77
import re
8+
import warnings
89
from enum import Enum
910
from typing import Any
1011

1112
import numpy as np
12-
from deprecate import deprecated
1313
from PIL import Image
1414

1515
from supervision.detection.utils.boxes import denormalize_boxes
1616
from supervision.detection.utils.converters import polygon_to_mask, polygon_to_xyxy
1717
from supervision.validators import validate_resolution
1818

1919

20-
@deprecated(
21-
target=None,
22-
deprecated_in="0.27.0",
23-
remove_in="0.31.0",
24-
)
2520
class LMM(Enum):
2621
"""
2722
Enum specifying supported Large Multimodal Models (LMMs).
2823
24+
.. deprecated:: 0.27.0
25+
`LMM` is deprecated and will be removed in `supervision-0.31.0`.
26+
Use `VLM` instead.
27+
2928
Attributes:
3029
PALIGEMMA: Google's PaliGemma vision-language model.
3130
FLORENCE_2: Microsoft's Florence-2 vision-language model.
@@ -51,6 +50,12 @@ def list(cls):
5150

5251
@classmethod
5352
def from_value(cls, value: LMM | str) -> LMM:
53+
warnings.warn(
54+
"`LMM` is deprecated since `supervision-0.27.0` and will be removed in "
55+
"`supervision-0.31.0`. Use `VLM` instead.",
56+
FutureWarning,
57+
stacklevel=2,
58+
)
5459
if isinstance(value, cls):
5560
return value
5661
if isinstance(value, str):

0 commit comments

Comments
 (0)