Overloadable Assignment PEP

Ben Hutchings do-not-spam-ben.hutchings at businesswebsoftware.com
Thu Apr 3 14:21:28 EST 2003


In article <qp5o8voto8li6p854klt7vo6dhon69hk2o at 4ax.com>, Richie Hindle wrote:
<snip> 
> So the line `page.message = "New message"` changes the content of the tag
> with id 'message'.  In this context, it makes sense that assigning to an
> object *changes* that object, rather than *replacing* it with another.

That's assigning to an attribute, not to an object.

> What you can't do with PyMeld is this:
> 
>>>> message = page.message
>>>> message = "Another new message"
>>>> print page
><html><body>
><textarea id="message">Another new message.</textarea>
></body></html>
> 
> There are workarounds, but over loadable assignment would make this much
> neater.
<snip>

No, it would make it very weird, and massively incompatible with existing
code.  Binding and mutating are fundamentally different and shouldn't be
combined in one operator.  (Look at the confusion people sometimes have with
initialisation and assignment in C++.)  Python's augmented assignment
operators already have this horrible behaviour, and I stay clear of them
because of this.




More information about the Python-list mailing list