[PEP 203] Augmented Assignment

Thomas Wouters thomas at xs4all.net
Mon Aug 14 16:59:35 EDT 2000


On Mon, Aug 14, 2000 at 07:19:18PM +0000, Frank Niessink wrote:
> Thomas Wouters <thomas at xs4all.net> wrote:

> > I've attached the current draft for the Augmented Assignment proposal. Due
> > to popular demand <wink> I've added a Rationale section that tries to
> > (*briefly*) explain why augmented assignment is a Good Thing. If you prefer
> > HTML over text, you can find the HTML version on the python PEP page:

> Maybe a stupid question, but why is there no hook for the regular
> assignment in this proposal? The proposal talks about 12 assignment 
> operators, of which 11 are 'inplace' and 1 regular. But there is
> no hook for the regular assignment. If a hook would be created for 
> regular assignment the object can decide what happens if something is
> assigned to it.

If you look closely, you see that the only thing the '_ab_' hooks do is the
'binary' part of the 'binary-assignment' combination that is augmented
assignment. Assignment in Python is a simple name-binding operation, not the
variable-filling operation it is in most other languages. Named variables
are like object indices. Which object would you expect to implement the
actual object storage in this expression:

list[10] = x

Or

dict["10"] = x

? Surely you don't expect 'x' to be able to handle all that ? And the fact
is that named variables are really, secretly, simply syntactic sugar for the
latter ;) (Except for local variables, which are secretly converted into a
more direct vector of objects whenever possible (aka "fastlocals") but are
translatable from 'fastlocals' to dictionary and back.)

The fact that Python instances, classes and namespaces use normal PyDict
objects helps a lot in making the Python C code almost as readable as bad
Python code ;)

In any case, this isn't likely to change, PEP or not. The 'name-binding'
type of assignment is at the heart of Python.

-- 
Thomas Wouters <thomas at xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!




More information about the Python-list mailing list