Decorators

Decorators for DIRAC.

DIRAC.Core.Utilities.Decorators.deprecated(reason, onlyOnce=False)

A decorator to mark a class or function as deprecated.

This will cause a warnings to be generated in the usual log if the item is used (instantiated or called).

If the environment variable DIRAC_DEPRECATED_FAIL is set to a non-empty value, an exception will be raised when the function or class is used.

The decorator can be used before as class or function, giving a reason, for example:

@deprecated("Use functionTwo instead")
def functionOne(...):

If onlyOnce is set to true then the warning will only be generated on the first call or creation of the item. This is useful for things that are likely to get called repeatedly (to prevent generating massive log files); for example:

@deprecated("Use otherClass instead", onlyOnce=True)
class MyOldClass:
Parameters:
  • reason (str) – Message to display to the user when the deprecated item is used. This should specify what should be used instead.
  • onlyOnce (bool) – If set, the deprecation warning will only be displayed on the first use.
Returns:

A double-function wrapper around the decorated object as required by the python interpreter.

Return type:

function