Files
qdrant-client/qdrant_client/common/client_warnings.py
Hossam Hagag 47ff758c56 refactor: Refactored the way of warnings (#864)
* refactor: Refactored the way of warnings

* remove unused imports

* fix: Fix stacklevel in warnings

* regenerated async

* nit

* Updated some warnings with show once

* fix: Fix stack levels

* Updated async

* Update qdrant_client/qdrant_remote.py

Co-authored-by: George <george.panchuk@qdrant.tech>

* Update async client

* Updated warnings

* Updated warnings

* Updated warnings

* fix: fix warning level

* fix: fix warning level in async

* fix: revert append payload condition

---------

Co-authored-by: George <george.panchuk@qdrant.tech>
2025-01-06 16:44:06 +01:00

25 lines
633 B
Python

import warnings
from typing import Optional
SEEN_MESSAGES = set()
def show_warning(message: str, category: type[Warning] = UserWarning, stacklevel: int = 2) -> None:
warnings.warn(message, category, stacklevel=stacklevel)
def show_warning_once(
message: str,
category: type[Warning] = UserWarning,
idx: Optional[str] = None,
stacklevel: int = 1,
) -> None:
"""
Show a warning of the specified category only once per program run.
"""
key = idx if idx is not None else message
if key not in SEEN_MESSAGES:
SEEN_MESSAGES.add(key)
show_warning(message, category, stacklevel)