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

Module decorators

source code

This module contains various Python decorators.
Functions [hide private]
 
deprecated(since=None, message=None)
Decorator for marking a function deprecated.
source code
 
abstract(func)
Decorator for marking a method abstract.
source code
 
unimplemented(func)
Decorator for marking a function or method unimplemented.
source code
Variables [hide private]
  __package__ = None
hash(x)
Function Details [hide private]

deprecated(since=None, message=None)

source code 

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)

source code 

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()

unimplemented(func)

source code 

Decorator for marking a function or method unimplemented. Throws a NotImplementedError if called. Note that this decorator is conceptually different from @abstract. With @abstract, the method is intended to be implemented by a subclass. With @unimplemented, the method should never be implemented.

Usage:

from grizzled.decorators import unimplemented

class ReadOnlyDict(dict):

    @unimplemented
    def __setitem__(self, key, value):
        pass