[Python-ideas] Assignment decorators (Re: The Descriptor Protocol...)

Greg Ewing greg.ewing at canterbury.ac.nz
Thu Mar 3 23:54:26 CET 2011


Andrew Svetlov wrote:
> Is there any idea how to extend decorator notation up to accepting
> right-hand argument?

Well, I just showed one. It's a little different from the
way function and class decorators work, but it has to be --
otherwise it wouldn't provide any advantage over just
writing a function call and assignment.

I've also had another idea on how to approach the problem
without involving the decorator concept:

   def name as something(arg, ...)

would be equivalent to

   name = something('name', arg, ...)

The idea here is that we're generalising the way that
'def' defines an object that knows the name it was defined
with.

It's notable that namedtuple could be used as-is with
either of these:

   @namedtuple
   Fred = 'x y z'

or

   def Fred as namedtuple('x y z')

Critiquing my own suggestions, I find that the second one
looks more elegant and less confusing, but then I've never
really liked the decorator syntax much in the first place.

-- 
Greg



More information about the Python-ideas mailing list