[Python-Dev] PEP 318 - posting draft (original) (raw)
Phillip J. Eby pje at telecommunity.com
Tue Mar 23 14:38:29 EST 2004
- Previous message: [Python-Dev] PEP 318 - posting draft
- Next message: [Python-Dev] PEP 318 - posting draft
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
At 11:12 AM 3/23/04 -0800, Guido van Rossum wrote:
> def func [dec1, dec2, ...] (arg1, arg2, ...): > pass > > Quixote's Page Template Language uses this form, but only supports a > single decorator chosen from a restricted set. For short lists it > works okay, but for long list it separates the argument list from the > function name.
OTOH, for long argument lists, the "preferred" form has the reverse problem: the decorators are separated from the function name by the long argument list. The question then becomes, what is more likely: long argument lists or long lists of decorators? I know that (at least in certain code bases :) long argument lists are common. Will long lists of decorators ever become popular?
That depends on how many chainable decorators people come up with. Most of the built-in decorators (classmethod, staticmethod, property) are not chainable in any reasonable sense, as their output is a descriptor.
In PEAK I have a couple of other function->descriptor decorators, one descriptor->descriptor decorator, and a handful of function->function decorators. Looking at the ones I have now, the longest chain I could make would probably be something like:
def something(self) [
events.taskFactory, storage.autocommit, binding.Make,
binding.classAttr ]: pass
But that's rather silly, because I've basically said I want an asynchronous pseudothread to be started inside a transaction that will immediately commmit (before the pseudothread has even done anything), and oh yeah, it should happen only once per subclass of this class, when you first access the 'something' attribute on the class (as distinct from its instances). Whew! Anyway, I think it shows that a long decorator chain is no worse on the eyes than a long argument list.
I think that initially, the most common decorator chains will be of length 1, with occasional "gusts" of 2 to 3. The most likely cause of longer chains will be people using contract decorators, since those are probably the most-chainable of decorator types. As time goes on and people come up with more ways to use them, the overall average length will probably creep upward, but I think the median will tend to stay hovering somewhere between 1 and 3.
- Previous message: [Python-Dev] PEP 318 - posting draft
- Next message: [Python-Dev] PEP 318 - posting draft
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]