operator overloading

sjdevnull at yahoo.com sjdevnull at yahoo.com
Wed Apr 4 18:49:26 EDT 2007


On Apr 4, 4:55 pm, "Terry Reedy" <tjre... at udel.edu> wrote:
> "Ziga Seilnacht" <ziga.seilna... at gmail.com> wrote in message
>
> news:1175711246.488717.262560 at e65g2000hsc.googlegroups.com...
> | This looks like a bug in Python. It works for all the other
> | operators:
[SNIP]
> | >>> i ** 3
> | 74088
> |
> | You should submit a bug report to the bug tracker:
> |
> |http://sourceforge.net/bugs/?group_id=5470
>
> Nice test.  I thought maybe __pow__ might be different in not having a
> reverse form, but indeed, int has an __rpow__ method.
>
> Before submitting, make sure that this does not work in 2.5, and then say
> so in the bug report.  In fact, copy the version/system info that the
> interactive interpreter puts up when it starts.

FWIW:
Python 2.5 (r25:51908, Jan 21 2007, 03:10:25)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-3)] on HOSTNAME_REDACTED
Type "help", "copyright", "credits" or "license" for more information.
>>> class MyInt(int):
...     __pow__ = int.__add__
...
>>> i=MyInt(42)
>>> i**3
74088




More information about the Python-list mailing list