Skip to content

Commit a29bbcf

Browse files
authored
Merge pull request #1999 from NIK-TIGER-BILL/fix/remove-deprecation-package
fix(deps): remove unmaintained deprecation package, use stdlib instead
2 parents d409819 + 8d0d835 commit a29bbcf

9 files changed

Lines changed: 40 additions & 9 deletions

File tree

requirements-devel.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ grpcio==1.75.1
55
grpcio-tools==1.75.1
66
grpcio-health-checking==1.75.1
77
pydantic==2.12.0
8-
deprecation==2.1.0
98

109
build
1110
twine

setup.cfg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ install_requires =
4040
pydantic>=2.12.0,<3.0.0
4141
grpcio>=1.59.5,<1.80.0
4242
protobuf>=4.21.6,<7.0.0
43-
deprecation>=2.1.0,<3.0.0
4443
python_requires = >=3.10
4544

4645
[options.extras_require]

weaviate/collections/batch/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from concurrent.futures import ThreadPoolExecutor
22
from typing import TYPE_CHECKING, Optional, Type, Union
33

4-
from deprecation import deprecated as docstring_deprecated
54
from typing_extensions import deprecated as typing_deprecated
65

6+
from weaviate.util import docstring_deprecated
7+
78
from weaviate.collections.batch.async_ import _BatchBaseAsync
89
from weaviate.collections.batch.base import (
910
_BatchBase,

weaviate/collections/batch/collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from concurrent.futures import ThreadPoolExecutor
22
from typing import TYPE_CHECKING, Generic, List, Optional, Type, Union
33

4-
from deprecation import deprecated as docstring_deprecated
4+
from weaviate.util import docstring_deprecated
55
from typing_extensions import deprecated as typing_deprecated
66

77
from weaviate.collections.batch.async_ import _BatchBaseAsync

weaviate/collections/classes/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
cast,
1515
)
1616

17-
from deprecation import deprecated as docstring_deprecated
17+
from weaviate.util import docstring_deprecated
1818
from pydantic import AnyHttpUrl, Field, TypeAdapter, ValidationInfo, field_validator
1919
from typing_extensions import TypeAlias
2020
from typing_extensions import deprecated as typing_deprecated

weaviate/collections/classes/config_named_vectors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Any, Dict, List, Literal, Optional, Union
22

3-
from deprecation import deprecated as docstring_deprecated
3+
from weaviate.util import docstring_deprecated
44
from pydantic import AnyHttpUrl, Field
55
from typing_extensions import deprecated as typing_deprecated
66

weaviate/collections/classes/config_vectorizers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from enum import Enum
33
from typing import Any, Dict, List, Literal, Optional, Union, cast
44

5-
from deprecation import deprecated as docstring_deprecated
5+
from weaviate.util import docstring_deprecated
66
from pydantic import AnyHttpUrl, BaseModel, Field, field_validator
77
from typing_extensions import TypeAlias
88
from typing_extensions import deprecated as typing_deprecated

weaviate/connect/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import Dict, Optional, Tuple, Union
44
from urllib.parse import urlparse
55

6-
from deprecation import deprecated as docstring_deprecated
6+
from weaviate.util import docstring_deprecated
77
from typing_extensions import deprecated as typing_deprecated
88

99
from weaviate.auth import (

weaviate/util.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
import base64
44
import datetime
5+
import functools
56
import io
67
import json
78
import os
89
import re
910
import uuid as uuid_lib
11+
import warnings as _warnings
1012
from pathlib import Path
11-
from typing import Any, Dict, Generator, List, Optional, Sequence, Tuple, Union, cast
13+
from typing import Any, Callable, Dict, Generator, List, Optional, Sequence, Tuple, Union, cast
1214
from urllib.parse import quote
1315

1416
import httpx
@@ -32,6 +34,36 @@
3234
BYTES_PER_CHUNK = 65535 # The number of bytes to read per chunk when encoding files ~ 64kb
3335

3436

37+
def docstring_deprecated(details: str = "", deprecated_in: str = "") -> Callable:
38+
"""Stdlib replacement for ``deprecation.deprecated``.
39+
40+
The ``deprecation`` package has not been maintained since 2019 and is
41+
flagged as a security risk by several dependency scanners. This helper
42+
replicates the behaviour we need:
43+
44+
1. Prepend a ``.. deprecated::`` note to the function docstring.
45+
2. Emit a :class:`DeprecationWarning` at call time.
46+
"""
47+
48+
def decorator(func: Callable) -> Callable:
49+
@functools.wraps(func)
50+
def wrapper(*args: object, **kwargs: object) -> object:
51+
_warnings.warn(
52+
f"{func.__qualname__} is deprecated since {deprecated_in}. {details}",
53+
DeprecationWarning,
54+
stacklevel=2,
55+
)
56+
return func(*args, **kwargs)
57+
58+
docstring = func.__doc__ or ""
59+
note = f".. deprecated:: {deprecated_in}\n {details}\n\n" if deprecated_in else ""
60+
wrapper.__doc__ = note + docstring
61+
62+
return wrapper # type: ignore[return-value]
63+
64+
return decorator
65+
66+
3567
def image_encoder_b64(image_or_image_path: Union[str, io.BufferedReader]) -> str:
3668
"""Encode a image in a Weaviate understandable format from a binary read file or by providing the image path.
3769

0 commit comments

Comments
 (0)