Skip to content

trulens.core.utils.deprecation

trulens.core.utils.deprecation

Utilities for handling deprecation.

Functions

module_getattr_override

module_getattr_override(
    module: Optional[str] = None,
    message: Optional[str] = None,
)

Override module's __getattr__ to issue a deprecation errors when looking up attributes.

This expects deprecated names to be prefixed with DEP_ followed by their original pre-deprecation name. For example:

  • Before deprecation

    # issue module import warning:
    package_dep_warn()
    
    # define temporary implementations of to-be-deprecated attributes:
    something = ... actual working implementation or alias
    

  • After deprecation

    # define deprecated attribute with None/any value but name with "DEP_"
    # prefix:
    DEP_something = None
    
    # issue module deprecation warning and override __getattr__ to issue
    # deprecation errors for the above:
    module_getattr_override()
    

Also issues a deprecation warning for the module itself. This will be used in the next deprecation stage for throwing errors after deprecation errors.

deprecated_str

deprecated_str(s: str, reason: str)

Decorator for deprecated string literals.

is_deprecated

is_deprecated(obj: Any)

Check if object is deprecated.

Presently only supports values created by deprecated_str.

deprecated_property

deprecated_property(message: str)

Decorator for deprecated attributes defined as properties.

packages_dep_warn

packages_dep_warn(
    module: Optional[str] = None,
    message: Optional[str] = None,
)

Issue a deprecation warning for a backwards-compatibility modules.

This is specifically for the trulens_eval -> trulens module renaming and reorganization. If message is given, that is included first in the deprecation warning.

has_deprecated

has_deprecated(obj: Union[Callable, Type]) -> bool

Check if a function or class has been deprecated.

has_moved

has_moved(obj: Union[Callable, Type]) -> bool

Check if a function or class has been moved.

staticmethod_renamed

staticmethod_renamed(new_name: str)

Issue a warning upon static method call that has been renamed or moved.

Issues the warning only once.

method_renamed

method_renamed(new_name: str)

Issue a warning upon method call that has been renamed or moved.

Issues the warning only once.

function_moved

function_moved(func: Callable, old: str, new: str)

Issue a warning upon function call that has been moved to a new location.

Issues the warning only once. The given callable must have a name, so it cannot be a lambda.

class_moved

class_moved(
    cls: Type,
    old_location: Optional[str] = None,
    new_location: Optional[str] = None,
)

Issue a warning upon class instantiation that has been moved to a new location.

Issues the warning only once.

moved

moved(
    globals_dict: Dict[str, Any],
    old: Optional[str] = None,
    new: Optional[str] = None,
    names: Optional[Iterable[str]] = None,
)

Replace all classes or function in the given dictionary with ones that issue a deprecation warning upon initialization or invocation.

You can use this with module globals_dict=globals() and names=__all__ to deprecate all exposed module members.

PARAMETER DESCRIPTION
globals_dict

The dictionary to update. See globals.

TYPE: Dict[str, Any]

old

The old location of the classes.

TYPE: Optional[str] DEFAULT: None

new

The new location of the classes.

TYPE: Optional[str] DEFAULT: None

names

The names of the classes or functions to update. If None, all classes and functions are updated.

TYPE: Optional[Iterable[str]] DEFAULT: None