[Python-bugs-list] [ python-Bugs-459188 ] unicode.__imul__ etc. missing

noreply@sourceforge.net noreply@sourceforge.net
Thu, 06 Sep 2001 10:11:12 -0700


Bugs item #459188, was opened at 2001-09-06 07:38
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=459188&group_id=5470

Category: Type/class unification
Group: Not a Bug
Status: Closed
Resolution: Invalid
Priority: 5
Submitted By: Walter Dörwald (doerwalter)
Assigned to: Guido van Rossum (gvanrossum)
Summary: unicode.__imul__ etc. missing

Initial Comment:
The str and the unicode type are missing all the 
__i*__ methods in 2.2a2:

>>> s = u"foo"
>>> s*=5
>>> s
u'foofoofoofoofoo'
>>> s.__imul__(5)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: 'unicode' object has no 
attribute '__imul__'
>>> s+="bar"
>>> s              
u'foofoofoofoofoobar'
>>> s.__iadd__("bar")
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: 'unicode' object has no 
attribute '__iadd__'

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

>Comment By: Guido van Rossum (gvanrossum)
Date: 2001-09-06 10:11

Message:
Logged In: YES 
user_id=6380

That's because these are sequence concatenations, and
"reversed-argument" add is not defined there. s+u works
because the string.__add__ () method special-cases a Unicode
right argument, not because unicode has a __radd__().


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

Comment By: Walter Dörwald (doerwalter)
Date: 2001-09-06 09:49

Message:
Logged In: YES 
user_id=89016

Not for str and unicode:

> python2.2
Python 2.2a2+ (#1, Sep  6 2001, 15:47:43) 
[GCC 2.95.2 19991024 (release)] on linux2
Type "help", "copyright", "credits" or "license" for more 
information.
>>> u"foo".__radd__(u"bar")        
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: 'unicode' object has no attribute '__radd__'


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

Comment By: Guido van Rossum (gvanrossum)
Date: 2001-09-06 09:35

Message:
Logged In: YES 
user_id=6380

Oh? It's there for me.

$ python
Python 2.2a2 (#176, Aug 22 2001, 16:23:28) 
[GCC 2.95.3 19991030 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more
information.
>>> 1 .__radd__
<method-wrapper object at 0x8125cd0>
>>> 1 .__radd__(2)
3
>>> 


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

Comment By: Walter Dörwald (doerwalter)
Date: 2001-09-06 09:29

Message:
Logged In: YES 
user_id=89016

What about __radd__? It seems to be missing too.

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

Comment By: Guido van Rossum (gvanrossum)
Date: 2001-09-06 08:13

Message:
Logged In: YES 
user_id=6380

This is not a bug. These (immutable) types don't implement
those operations, and then the system falls back to
implementing x+=y as x=x+y.

If you define a regular class without __iadd__ etc., += is
implemented in the same way.

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

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=459188&group_id=5470