My first tought would be the mydecorator = MyDecorator() will hold the object instance reference and the ref count won't go to zero..




So..

Decorator grammar is this:

decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE

The grammar prevents this:

class MyDecorator:
...     def decorator_method():
...             pass
...
@MyDecorator().decorator_method()
  File "<stdin>", line 1
    @MyDecorator().decorator_method()
                  ^
SyntaxError: invalid syntax

But is possible to achieve the desired effect by assigning the class
instance to variable:

mydecorator = MyDecorator()
... @mydecorator.decorator_method
... def f():


My initial thoughts were that the syntax provided a neat way to
provide a configurable decorator class instance with a number of
alternative decorator-function generating methods, rather than just
the usual __call__.

S
_______________________________________________
python-uk mailing list
python-uk@python.org
http://mail.python.org/mailman/listinfo/python-uk

_______________________________________________
python-uk mailing list
python-uk@python.org
http://mail.python.org/mailman/listinfo/python-uk

Reply via email to