Top "Decorator" questions

Decorator is an object-oriented design pattern that allows adding behavior to existing classes in a dynamic fashion.

Preserving signatures of decorated functions

Suppose I have written a decorator that does something very generic. For example, it might convert all arguments to a …

python decorator
Python decorator handling docstrings

I have a problem using docstrings with decorators. Given the following example: def decorator(f): def _decorator(): print 'decorator active' …

python decorator docstring
Redefinition of class method in python

Context I'm trying to have some "plugins" (I'm not sure this is the correct definition for this) to my code. …

python function plugins decorator redefinition
Is it possible to replace a function/method decorator at runtime? [ python ]

If I have a function : @aDecorator def myfunc1(): # do something here if __name__ = "__main__": # this will call the function and …

python runtime language-features decorator
What is the right way to put a docstring on Python property?

Should I make several docstrings, or just one (and where should I put it)? @property def x(self): return 0 @x.…

python properties decorator
How can I get a Python decorator to run after the decorated function has completed?

I want to use a decorator to handle auditing of various functions (mainly Django view functions, but not exclusively). In …

python decorator python-decorators
How do __enter__ and __exit__ work in Python decorator classes?

I'm trying to create a decorator class that counts how many times a function is called, but I'm getting an …

python class count decorator exit
How do I write a decorator that restores the cwd?

How do I write a decorator that restores the current working directory to what it was before the decorated function …

python decorator cwd
Decorating a JTextField with an image and hint

I'm trying to create some nicer looking JTextFields with an image and a hint. To do this I made a …

java swing user-interface decorator jtextfield
Testing Python Decorators?

I'm writing some unit tests for a Django project, and I was wondering if its possible (or necessary?) to test …

python django unit-testing decorator python-unittest