Bugs item #1694663, was opened at 2007-04-04 18:44
Message generated for change (Comment added) made by rhettinger
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1694663&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
>Group: Python 2.5
Status: Open
Resolution: None
>Priority: 3
Private: No
Submitted By: Terry J. Reedy (tjreedy)
>Assigned to: Raymond Hettinger (rhettinger)
Summary: Overloading  int.__pow__ does not work

Initial Comment:
>From c.l.p: in response to glitch report, 2nd person showed that it is 
>specific to __pow__

>>> class MyInt(int):
...     __sub__ = int.__add__
# similar lines for 9 other methods omitted
...     __or__ = int.__add__
...     __pow__ = int.__add__
...
>>> i = MyInt(42)
>>> i + 3
45
>>> i - 3
45
# similar outputs omitted
>>> i | 3
45
>>> i ** 3
74088

Another person (3rd) confirmed presence in 2.5 
Python 2.5 (r25:51908, Jan 21 2007, 03:10:25)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-3)] 


----------------------------------------------------------------------

>Comment By: Raymond Hettinger (rhettinger)
Date: 2007-04-04 23:54

Message:
Logged In: YES 
user_id=80475
Originator: NO

I'll take a look at your patch.

The root problem is that the wrapper functions will return NULL if they
are fed the wrong number of arguments (i.e. the int.__add__ wrapper expects
exactly two arguments but the ** call provides three) -- you will see a
similar result if int.__neg__ or int.__invert__ are assigned to __add__.  
It looks like an upstream step is seeing the NULL and deciding that it
needs to look to skip the given method call and instead try the base the
class.

Am lowering the priority because there is no good use case for deliberate
argument mismatches in the override.  Am leaving the bug open because we
want the appropriate error message to surface.



----------------------------------------------------------------------

Comment By: Ziga Seilnacht (zseil)
Date: 2007-04-04 20:47

Message:
Logged In: YES 
user_id=1326842
Originator: NO

Here is a patch (with tests) that should fix this.
There was another problem when the slot wrapper
came from a different type:

>>> class MyInt(int):
...     __mul__ = float.__add__
...
>>> MyInt(3) * 3
9

This now raises a TypeError.

File Added: mixing_slots.diff

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1694663&group_id=5470
_______________________________________________
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to