Technically, you don't have to worry about refcounts here. evaluating 'AClass().method' results in a 'bound' method.
The method binding contains a reference to the instance, so internally, a reference is always held. It does mean however that the AClass instance is anonymous, there is no simple way to directly access it from other python code On Wed, Apr 3, 2013 at 12:45 PM, <a.cava...@cavallinux.eu> wrote: > > 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<http://mail.python.org/mailman/listinfo/python-uk> >> > > ______________________________**_________________ > python-uk mailing list > python-uk@python.org > http://mail.python.org/**mailman/listinfo/python-uk<http://mail.python.org/mailman/listinfo/python-uk> >
_______________________________________________ python-uk mailing list python-uk@python.org http://mail.python.org/mailman/listinfo/python-uk