[pypy-dev] behaviour difference int-subclasses pypy 1.5 to cpython 2.6.6.
Armin Rigo
arigo at tunes.org
Tue Aug 16 15:44:20 CEST 2011
Hi Michael,
On Tue, Aug 16, 2011 at 2:06 PM, Michael Foord <fuzzyman at gmail.com> wrote:
> I assume the difference is that int has an __init__ method on pypy.
No, it doesn't; the issue is that the call int.__init__("12") is not
strictly equivalent to object.__init__("12"). It is on CPython, but
that's a bit by chance. If you define your own Python classes like
this:
class MyObject(object):
def __init__(self):
pass
class MyInt(MyObject):
pass
Then for an instance "o=MyObject()", the call MyInt.__init__(o) is not
equivalent to the call MyObject.__init__(o): indeed, the former fails
on CPython too, because MyInt.__init__ returns an unbound method
object attached specifically to MyInt. In PyPy the same occurs even
with built-in types (because there is no type "built-in method" in
PyPy).
A bientôt,
Armin.
More information about the pypy-dev
mailing list