Message3293
this is fixed on the asm branch with:
r4684, r4693, r4694
Note that the iadd.py test still doesn't work exactly as CPython does,
it's now:
123
type(l) is NotList False
type(l_too) is list True
Which matches pypy. The discrepancy is due to CPython's odd behavior
with builtins
Basically in this example, list __iadd__ works on iterable objects:
Python 2.5.2 (r252:60911, Apr 22 2008, 12:00:45)
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from iadd import NotList
>>> l = []
>>> l.__iadd__(NotList([1,2,3]))
[1, 2, 3]
Since NotList is iterable, why is NotList.__radd__ called instead of
list.__iadd__ using NotList.__iter__? Because CPython makes subclass
slots (like __add/radd__) take precedent over builtin slots in cases
like this. A better example is:
Python 2.5.2 (r252:60911, Apr 22 2008, 12:00:45)
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> class Base(object):
... def __imul__(self, other):
... return 'Base imul'
...
>>> class Foo(Base):
... def __mul__(self, other):
... return 'Foo mul'
...
>>> f = Foo()
>>> f *= 1
>>> f # super __imul__ was consulted before Foo __mul__
'Base imul'
>>> class Bar(list):
... def __mul__(self, other):
... return 'Bar mul'
...
>>> b = Bar()
>>> b *= 1
>>> b # super __imul__ *NOT* consulted before Bar __mul__
'Bar mul'
>>> list.__imul__ # there's really a super __imul__ slot
<slot wrapper '__imul__' of 'list' objects>
Whereas Jython/Pypy would have called list.__imul__ and returned an
empty list
CPython's behavior seems inconsistent, and I don't see it documented
anywhere (reading http://docs.python.org/ref/coercion-rules.html gives
you the impression Jython/Pypy are correct).
We and the Pypy folk probably need to follow up on this with CPython
folk. (ccing pedronis) |
|
Date |
User |
Action |
Args |
2008-06-20 06:17:13 | pjenvey | set | spambayes_score: 0.000124955 -> 0.00012495482 messageid: <1213942633.39.0.355594312274.issue1873148@psf.upfronthosting.co.za> |
2008-06-20 06:17:13 | pjenvey | set | spambayes_score: 0.000124955 -> 0.000124955 recipients:
+ pjenvey, pedronis, jek |
2008-06-20 06:17:13 | pjenvey | link | issue1873148 messages |
2008-06-20 06:17:12 | pjenvey | create | |
|