[Python-ideas] wild idea : target decorators

Boris Borcic bborcic at gmail.com
Wed Sep 23 15:45:19 CEST 2009

Simply put, augmented assignment of the form

x op= expr

invites pythonistas to a particular intuition of the DRY principle
which feels denied whenever the need is encountered to write code of the

x = f(x,y)

or even, more simply

x = f(x)

on another hand, Python already admits an implied x = f(x) with decorators,
since by definition of decorators

def x(...) : suite

means the same as

def x(...) : suite

the embryonic proposal is to extend decorator syntax to arbitrary assignment 
targets, to permit use of it to formulate x=f(x) DRY-ly, e.g.


together with a further syntax extension allowing to write the above on a single 
line, by postfixing the assignment target with the decorator, e.g.

x @f

or perhaps

x @= f

to be more in line with other augmented assignment operators, by analogy, say, 
with how

x *= 2

can replace

x = 2*x

while removing the need to repeat x

ok, this is clearly an completely embryonic idea shown (and motivated) only by 
(and through) how it would apply to the simplest imaginable use case. The 
displaying of it is intended to stimulate community discussion on whether and 
how it might extend to a more useful wider and consistent extension of the 
python language, and not to invite approval ratings over its current, well, egg.

IOW, does anybody feel like me there is a challenge to see better whether/how 
these two disjoint python corners, e.g. decorators on the one hand, and 
augmented assignment on the other hand, may surprisingly reveal they can fit a 
unifying extension of both ?

Cheers, BB

More information about the Python-ideas mailing list