[issue11788] Decorator class with optional arguments and a __call__ method gets not called when there are no arguments

2011-04-06 Thread Carsten Klein
New submission from Carsten Klein carsten.kl...@axn-software.de: Scenario: class deco(object): def __init__(self, optional = False): self._optional = optional def __call__(self, decorated): decorated.optional = self._optional return decorated @deco class y(object): pass

[issue11788] Decorator class with optional arguments and a __call__ method gets not called when there are no arguments

2011-04-06 Thread Carsten Klein
Carsten Klein carsten.kl...@axn-software.de added the comment: will fail decorating the class since y... actually means that instead of an instance of class y, an instance of the decorator class will be returned, with y being lost along the way... --

[issue11788] Decorator class with optional arguments and a __call__ method gets not called when there are no arguments

2011-04-06 Thread Santoso Wijaya
Santoso Wijaya santoso.wij...@gmail.com added the comment: I wonder if this is a valid use-case to begin with. The semantic of a decorator, as I understand it, is very straightforward in that this: @foo @bar class A: pass is equivalent to this: class A: pass

[issue11788] Decorator class with optional arguments and a __call__ method gets not called when there are no arguments

2011-04-06 Thread Carsten Klein
Carsten Klein carsten.kl...@axn-software.de added the comment: I think it is, actually, considering @foo @bar class A: pass with foo and bar being both decorator classes, the chained call foo(bar(A)) will return and instance of foo instead of A With decorator classes

[issue11788] Decorator class with optional arguments and a __call__ method gets not called when there are no arguments

2011-04-06 Thread Benjamin Peterson
Benjamin Peterson benja...@python.org added the comment: This is expected; it's the same with functions. Just do @deco(). -- nosy: +benjamin.peterson resolution: - invalid status: open - closed ___ Python tracker rep...@bugs.python.org

[issue11788] Decorator class with optional arguments and a __call__ method gets not called when there are no arguments

2011-04-06 Thread Carsten Klein
Carsten Klein carsten.kl...@axn-software.de added the comment: Ok, looks like a valid work around to me. However, IMO it is not the same as with decorator functions. These will be called and will return the correct result, whereas the decorator class will instead return an instance of self

[issue11788] Decorator class with optional arguments and a __call__ method gets not called when there are no arguments

2011-04-06 Thread Raymond Hettinger
Raymond Hettinger raymond.hettin...@gmail.com added the comment: I concur with Benjamin. -- nosy: +rhettinger ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11788 ___

[issue11788] Decorator class with optional arguments and a __call__ method gets not called when there are no arguments

2011-04-06 Thread Benjamin Peterson
Benjamin Peterson benja...@python.org added the comment: 2011/4/6 Carsten Klein rep...@bugs.python.org: Carsten Klein carsten.kl...@axn-software.de added the comment: Ok, looks like a valid work around to me. It's not a workaround. It's the way decorators work. --