a taxonomy of decorators

They used not too need the @ decorator.

However from 2.4 - the @ decorator was born.

Simple Use Case

#2.4

def null_it(func):
    ''' Remove a Function Call - but leave the code '''
    return None

class Bob(object):

   @null_it
   def printOut(self,stuff):
       print("Upgraded")

   def print_Out(self,suff):
       print("New fun")

Python 2.6 - Decorator works at a class so far.

@wraps

This copies the name function, docstring, etc

This "emulates" a method in the function .

function
name
module
docstring

Argument changing Decorator

 @patch('glob.global')
 @patch('glob.global')
 def add_vars(a,b)
     return a+b+glob.global+glob.global