Skip to content

Commit b3c1fe8

Browse files
author
NIK-TIGER-BILL
committed
refactor: move docstring_deprecated to weaviate/util.py, apply to all 6 files
Per maintainer feedback (@dirkkul), consolidate the stdlib deprecation helper into weaviate/util.py so all modules share a single implementation. Changes: - weaviate/util.py: add docstring_deprecated() function - weaviate/collections/batch/client.py: remove inline definition, import from util - weaviate/collections/batch/collection.py: replace 'from deprecation import...' - weaviate/connect/helpers.py: replace 'from deprecation import...' - weaviate/collections/classes/config.py: replace 'from deprecation import...' - weaviate/collections/classes/config_vectorizers.py: replace 'from deprecation import...' - weaviate/collections/classes/config_named_vectors.py: replace 'from deprecation import...' The 'deprecation' package is now fully removed from the codebase. Signed-off-by: NIK-TIGER-BILL <nik.tiger.bill@github.com>
1 parent 62f3156 commit b3c1fe8

7 files changed

Lines changed: 39 additions & 40 deletions

File tree

weaviate/collections/batch/client.py

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,9 @@
11
from concurrent.futures import ThreadPoolExecutor
22
from typing import TYPE_CHECKING, Optional, Type, Union
33

4-
import functools
5-
import warnings as _warnings
6-
from typing import Callable
7-
84
from typing_extensions import deprecated as typing_deprecated
95

10-
11-
def docstring_deprecated(details: str = "", deprecated_in: str = "", **_kwargs: object) -> Callable:
12-
"""Replacement for ``deprecation.deprecated`` that uses only stdlib.
13-
14-
The ``deprecation`` package has not been maintained since 2019 and is
15-
flagged as a security risk by several dependency scanners. This
16-
in-module helper replicates the behaviour we need:
17-
18-
1. Prepend a ``.. deprecated::`` note to the docstring.
19-
2. Emit a :class:`DeprecationWarning` at call time.
20-
"""
21-
22-
def decorator(func: Callable) -> Callable:
23-
docstring = func.__doc__ or ""
24-
note = f".. deprecated:: {deprecated_in}\n {details}\n\n" if deprecated_in else ""
25-
func.__doc__ = note + docstring
26-
27-
@functools.wraps(func)
28-
def wrapper(*args: object, **kwargs: object) -> object:
29-
_warnings.warn(
30-
f"{func.__qualname__} is deprecated since {deprecated_in}. {details}",
31-
DeprecationWarning,
32-
stacklevel=2,
33-
)
34-
return func(*args, **kwargs)
35-
36-
wrapper.__doc__ = func.__doc__
37-
return wrapper
38-
39-
return decorator
6+
from weaviate.util import docstring_deprecated
407

418
from weaviate.collections.batch.async_ import _BatchBaseAsync
429
from weaviate.collections.batch.base import (

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 = "", **_kwargs: object) -> 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+
docstring = func.__doc__ or ""
50+
note = f".. deprecated:: {deprecated_in}\n {details}\n\n" if deprecated_in else ""
51+
func.__doc__ = note + docstring
52+
53+
@functools.wraps(func)
54+
def wrapper(*args: object, **kwargs: object) -> object:
55+
_warnings.warn(
56+
f"{func.__qualname__} is deprecated since {deprecated_in}. {details}",
57+
DeprecationWarning,
58+
stacklevel=2,
59+
)
60+
return func(*args, **kwargs)
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)