Overloadable Assignment PEP

Lulu of the Lotus-Eaters mertz at gnosis.cx
Thu Apr 3 14:22:11 EST 2003


drew at astro.pas.rochester.edu (Drew Moore) wrote previously:
|voltage += 5  # (raise the voltage by 5 volts)
|voltage *= 2  # (double the current voltage)
|voltage = 3  # (set the voltage to 3 volts)
|my voltage object is clobbered with an integer object.

The case makes sense... but IMO, not nearly enough to change the
behavior of assignment.

For this particular case, you could simply coopt the meaning of some
other augmented operator to set voltage.  For example:

    voltage |= 3

The need to bitwise-and on voltage seems unlikely, so you should not
step on anything important.  Of course, experienced Python programmers
might do a little double take on the meaning, but documentation can
explain it.

Then again, I wouldn't mind adding the new operator ":=" which was
"generic augmentation"... the operator could do -absolutely nothing- for
standard types, but could be available for custom meaning in custom
types.

Yours, Lulu...

--
    _/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY: Postmodern Enterprises _/_/_/
   _/_/    ~~~~~~~~~~~~~~~~~~~~[mertz at gnosis.cx]~~~~~~~~~~~~~~~~~~~~~  _/_/
  _/_/  The opinions expressed here must be those of my employer...   _/_/
 _/_/_/_/_/_/_/_/_/_/ Surely you don't think that *I* believe them!  _/_/






More information about the Python-list mailing list