chore: import upstream snapshot with attribution
Sync docs with Docusaurus / sync (push) Waiting to run
Tests / Check if changed (push) Waiting to run
Tests / format (push) Blocked by required conditions
Tests / check-imports (push) Blocked by required conditions
Tests / Unit / macos-latest (push) Blocked by required conditions
Tests / Unit / ubuntu-latest (push) Blocked by required conditions
Tests / Unit / windows-latest (push) Blocked by required conditions
Tests / mypy (push) Blocked by required conditions
Tests / Integration / ubuntu-latest (push) Blocked by required conditions
Tests / Integration / macos-latest (push) Blocked by required conditions
Tests / Integration / windows-latest (push) Blocked by required conditions
Tests / notify-slack-on-failure (push) Blocked by required conditions
Tests / Mark tests as completed (push) Blocked by required conditions
Docker image release / Build base image (push) Waiting to run
CodeQL / Analyze (python) (push) Has been cancelled
Update Platform Components Table / update (push) Has been cancelled
Sync docs with Docusaurus / sync (push) Waiting to run
Tests / Check if changed (push) Waiting to run
Tests / format (push) Blocked by required conditions
Tests / check-imports (push) Blocked by required conditions
Tests / Unit / macos-latest (push) Blocked by required conditions
Tests / Unit / ubuntu-latest (push) Blocked by required conditions
Tests / Unit / windows-latest (push) Blocked by required conditions
Tests / mypy (push) Blocked by required conditions
Tests / Integration / ubuntu-latest (push) Blocked by required conditions
Tests / Integration / macos-latest (push) Blocked by required conditions
Tests / Integration / windows-latest (push) Blocked by required conditions
Tests / notify-slack-on-failure (push) Blocked by required conditions
Tests / Mark tests as completed (push) Blocked by required conditions
Docker image release / Build base image (push) Waiting to run
CodeQL / Analyze (python) (push) Has been cancelled
Update Platform Components Table / update (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
# SPDX-FileCopyrightText: 2022-present deepset GmbH <info@deepset.ai>
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import functools
|
||||
import warnings
|
||||
from typing import Any, TypeVar
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
|
||||
def _experimental(cls: type[T]) -> type[T]:
|
||||
"""
|
||||
Class decorator that marks a Haystack component as experimental.
|
||||
|
||||
Components decorated with @experimental are subject to breaking changes
|
||||
or removal in future releases without prior deprecation notice.
|
||||
|
||||
## Usage example
|
||||
|
||||
@_experimental
|
||||
@component
|
||||
class MyComponent:
|
||||
...
|
||||
"""
|
||||
# getattr/setattr are intentional here: direct attribute access (cls.__init__, cls.__init__ = ...)
|
||||
# triggers mypy [misc] and [attr-defined] errors because T is an unbound TypeVar.
|
||||
# noqa comments suppress ruff B009/B010 which would auto-revert these back to direct access.
|
||||
original_init: Any = getattr(cls, "__init__") # noqa: B009
|
||||
|
||||
@functools.wraps(original_init)
|
||||
def new_init(self: Any, *args: Any, **kwargs: Any) -> None:
|
||||
warnings.warn(
|
||||
f"'{cls.__name__}' is an experimental component and may change or be removed "
|
||||
"in future releases without prior deprecation notice. ",
|
||||
ExperimentalWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
original_init(self, *args, **kwargs)
|
||||
|
||||
setattr(cls, "__init__", new_init) # noqa: B010
|
||||
setattr(cls, "__experimental__", True) # noqa: B010
|
||||
return cls
|
||||
|
||||
|
||||
class ExperimentalWarning(UserWarning):
|
||||
"""Warning emitted when an experimental Haystack component is instantiated."""
|
||||
Reference in New Issue
Block a user