unitxt.deprecation_utils moduleΒΆ

exception unitxt.deprecation_utils.DeprecationErrorΒΆ

Bases: Exception

Custom exception for deprecated versions.

unitxt.deprecation_utils.compare_versions(version1, version2)ΒΆ

Compare two semantic versioning strings and determine their relationship.

Parameters: - version1 (str): The first version string to compare. - version2 (str): The second version string to compare.

Returns: - int: -1 if version1 < version2, 1 if version1 > version2, 0 if equal.

Example: >>> compare_versions(β€œ1.2.0”, β€œ1.2.3”) -1 >>> compare_versions(β€œ1.3.0”, β€œ1.2.8”) 1 >>> compare_versions(β€œ1.0.0”, β€œ1.0.0”) 0

unitxt.deprecation_utils.depraction_wrapper(obj, version, alt_text)ΒΆ

A wrapper function for deprecation handling, issuing warnings or errors based on version comparison.

Parameters:
  • obj (callable) – The object to be wrapped, typically a function or class method.

  • version (str) – The version at which the object becomes deprecated.

  • alt_text (str) – Additional text to display, usually suggests an alternative.

Returns:

A wrapped version of the original object that checks for deprecation.

Return type:

callable

unitxt.deprecation_utils.deprecation(version, alternative=None, msg=None)ΒΆ

Decorator for marking functions or class methods as deprecated.

Parameters:
  • version (str) – The version at which the function or method becomes deprecated.

  • alternative (str, optional) – Suggested alternative to the deprecated functionality.

  • msg (str, optional) – Additional message regarding the deprecation reason or alternatives.

Returns:

A decorator that can be applied to functions or class methods.

Return type:

callable