Package grizzled :: Module decorators
[frames] | no frames]

Module decorators

This module contains various Python decorators.
Functions
 
deprecated(since=None, message=None)
Decorator for marking a function deprecated.
 
abstract(func)
Decorator for marking a method abstract.
Function Details

deprecated(since=None, message=None)

 

Decorator for marking a function deprecated. Generates a warning on standard output if the function is called.

Usage:

from grizzled.decorators import deprecated

class MyClass(object):

    @deprecated()
    def oldMethod(self):
        pass

Given the above declaration, the following code will cause a warning to be printed (though the method call will otherwise succeed):

obj = MyClass()
obj.oldMethod()

You may also specify a since argument, used to display a deprecation message with a version stamp (e.g., 'deprecated since ...'):

from grizzled.decorators import deprecated

class MyClass(object):

    @deprecated(since='1.2')
    def oldMethod(self):
        pass
Parameters:
  • since (str) - version stamp, or None for none
  • message (str) - optional additional message to print

abstract(func)

 

Decorator for marking a method abstract. Throws a NotImplementedError if an abstract method is called.

Usage:

from grizzled.decorators import abstract

class MyAbstractClass(object):

    @abstract
    def abstractMethod(self):
        pass

class NotReallyConcrete(MyAbstractClass):
    # Class doesn't define abstractMethod().

Given the above declaration, the following code will cause an NotImplementedError:

obj = NotReallyConcrete()
obj.abstractMethod()