OK, you're saying that it is correct behavior, and I believe you.

However, it is unexpected enough (and hard enough to notice) that you
ought to mention it in the documentation.
Something on the order of

"Note that deriving classes from some
built-in types may give unexpected results because they are immutable.
For instance, the in-place arithmetic operators like __iadd__ will
never be called for a class derived from an immutable type like
int, float or string."


Ideally, python would warn you if you defined __iadd__ on a class
derived from float, because it would never be called automatically.




Matthias Klose wrote:
SourceForge.net writes:
Bugs item #1633630, was opened at 2007-01-11 18:49
Message generated for change (Comment added) made by jimjjewett
You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1633630&group_id=5470

For instance, consider the following:

class Float(float):
...     def __init__(self, v):
...             float.__init__(self, v)
...             self.x = 1
...
a = Float(2.0)
b = Float(3.0)
type(a)
<class '__main__.Float'>
type(b)
<class '__main__.Float'>
a += b
type(a)
<type 'float'>

Now,  the type of a has silently changed.   It was a Float, a derived class with
all kinds of properties, and it became a float -- a plain vanilla number.

My understanding is that this is incorrect, and certainly unexpected.
If it *is* correct, it certainly deserves mention somewhere in the 
documentation.

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

Comment By: Jim Jewett (jimjjewett)
Date: 2007-01-12 16:26
Python float objects are immutable and can be shared. Therefore, their values cannot be modified -- which is why it falls back
to not-in-place assignment.



--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to