trulens.core.utils.deprecation¶
trulens.core.utils.deprecation
¶
Utilities for handling deprecation.
Functions¶
module_getattr_override
¶
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.
Example
# issue module import warning:
package_dep_warn()
# define temporary implementations of to-be-deprecated attributes:
something = ... actual working implementation or alias
# 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.
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.
handle_deprecated_kwarg
¶
handle_deprecated_kwarg(
kwargs: Dict[str, Any],
old_name: str,
new_name: str,
new_value: Optional[str],
stacklevel: int = 3,
) -> Optional[str]
Handle deprecated keyword argument that has been renamed.
This helper checks if an old parameter name is in kwargs, emits a deprecation warning, and returns the appropriate value to use.
| PARAMETER | DESCRIPTION |
|---|---|
kwargs
|
The kwargs dictionary to check and modify. The old key will be removed from this dictionary if present. |
old_name
|
The deprecated parameter name.
TYPE:
|
new_name
|
The new parameter name.
TYPE:
|
new_value
|
The current value of the new parameter. |
stacklevel
|
Stack level for the warning. Defaults to 3 (caller's caller).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[str]
|
The value to use for the new parameter. If new_value is None and the |
Optional[str]
|
old parameter was provided, returns the old parameter's value. |
Optional[str]
|
Otherwise returns new_value unchanged. |
Example
def my_function(new_param: Optional[str] = None, **kwargs):
new_param = handle_deprecated_kwarg(
kwargs, "old_param", "new_param", new_param
)
packages_dep_warn
¶
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
¶
Check if a function or class has been deprecated.
has_moved
¶
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
¶
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
¶
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. |
old
|
The old location of the classes. |
new
|
The new location of the classes. |
names
|
The names of the classes or functions to update. If None, all classes and functions are updated. |