[Python-ideas] Decorator syntax restriction

Paul Moore p.f.moore at gmail.com
Wed Oct 7 10:19:47 CEST 2009

2009/10/3 Greg Ewing <greg.ewing at canterbury.ac.nz>:
> Paul Moore wrote:
>> @(a['b'].fns[1])(1,2,{3,4})
>> def something():
>> I contend that's clearly "line noise".
> But there's nothing to stop you from writing
>  f = (a['b'].fns[1])(1,2,{3,4})
>  @f
>  def something():
> If the first version is unreadable, the second one isn't going
> to be significantly better.

Absolutely. Unless you give f a meaningful name...

I'm not trying to say that you can't write unreadable line noise in
Python (look at any of my code for examples :-)) just that the design
principle is to avoid actively encouraging it.

There's no doubt that this is a grey area.

And I'm not against allowing subscripts in decorators (I've no
personal need for it but I see how it might help, so +0) so it may be
that I already support allowing the monstrosity above :-) (I refuse to
go and check if it violates any other syntax rules, as my point is
basically that if I need to check, I don't think it should be used,
whether or not it's allowed).


More information about the Python-ideas mailing list