Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ install_requires =
pydantic>=2.12.0,<3.0.0
grpcio>=1.59.5,<1.80.0
protobuf>=4.21.6,<7.0.0
deprecation>=2.1.0,<3.0.0
python_requires = >=3.10

[options.extras_require]
Expand Down
3 changes: 2 additions & 1 deletion weaviate/collections/batch/client.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from concurrent.futures import ThreadPoolExecutor
from typing import TYPE_CHECKING, Optional, Type, Union

from deprecation import deprecated as docstring_deprecated
from typing_extensions import deprecated as typing_deprecated

from weaviate.util import docstring_deprecated

from weaviate.collections.batch.async_ import _BatchBaseAsync
from weaviate.collections.batch.base import (
_BatchBase,
Expand Down
2 changes: 1 addition & 1 deletion weaviate/collections/batch/collection.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from concurrent.futures import ThreadPoolExecutor
from typing import TYPE_CHECKING, Generic, List, Optional, Type, Union

from deprecation import deprecated as docstring_deprecated
from weaviate.util import docstring_deprecated
from typing_extensions import deprecated as typing_deprecated

from weaviate.collections.batch.async_ import _BatchBaseAsync
Expand Down
2 changes: 1 addition & 1 deletion weaviate/collections/classes/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
cast,
)

from deprecation import deprecated as docstring_deprecated
from weaviate.util import docstring_deprecated
from pydantic import AnyHttpUrl, Field, TypeAdapter, ValidationInfo, field_validator
from typing_extensions import TypeAlias
from typing_extensions import deprecated as typing_deprecated
Expand Down
2 changes: 1 addition & 1 deletion weaviate/collections/classes/config_named_vectors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any, Dict, List, Literal, Optional, Union

from deprecation import deprecated as docstring_deprecated
from weaviate.util import docstring_deprecated
from pydantic import AnyHttpUrl, Field
from typing_extensions import deprecated as typing_deprecated

Expand Down
2 changes: 1 addition & 1 deletion weaviate/collections/classes/config_vectorizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from enum import Enum
from typing import Any, Dict, List, Literal, Optional, Union, cast

from deprecation import deprecated as docstring_deprecated
from weaviate.util import docstring_deprecated
from pydantic import AnyHttpUrl, BaseModel, Field, field_validator
from typing_extensions import TypeAlias
from typing_extensions import deprecated as typing_deprecated
Expand Down
2 changes: 1 addition & 1 deletion weaviate/connect/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Dict, Optional, Tuple, Union
from urllib.parse import urlparse

from deprecation import deprecated as docstring_deprecated
from weaviate.util import docstring_deprecated
from typing_extensions import deprecated as typing_deprecated

from weaviate.auth import (
Expand Down
34 changes: 33 additions & 1 deletion weaviate/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import base64
import datetime
import functools
import io
import json
import os
import re
import uuid as uuid_lib
import warnings as _warnings
from pathlib import Path
from typing import Any, Dict, Generator, List, Optional, Sequence, Tuple, Union, cast
from typing import Any, Callable, Dict, Generator, List, Optional, Sequence, Tuple, Union, cast
from urllib.parse import quote

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


def docstring_deprecated(details: str = "", deprecated_in: str = "", **_kwargs: object) -> Callable:
"""Stdlib replacement for ``deprecation.deprecated``.

The ``deprecation`` package has not been maintained since 2019 and is
flagged as a security risk by several dependency scanners. This helper
replicates the behaviour we need:

1. Prepend a ``.. deprecated::`` note to the function docstring.
2. Emit a :class:`DeprecationWarning` at call time.
"""

def decorator(func: Callable) -> Callable:
docstring = func.__doc__ or ""
note = f".. deprecated:: {deprecated_in}\n {details}\n\n" if deprecated_in else ""
func.__doc__ = note + docstring

@functools.wraps(func)
def wrapper(*args: object, **kwargs: object) -> object:
_warnings.warn(
f"{func.__qualname__} is deprecated since {deprecated_in}. {details}",
DeprecationWarning,
stacklevel=2,
)
return func(*args, **kwargs)

return wrapper # type: ignore[return-value]

return decorator


def image_encoder_b64(image_or_image_path: Union[str, io.BufferedReader]) -> str:
"""Encode a image in a Weaviate understandable format from a binary read file or by providing the image path.

Expand Down