[pypy-issue] [issue1158] Different in custom list casting

mikefc tracker at bugs.pypy.org
Thu Jun 7 06:10:16 CEST 2012


New submission from mikefc <coolbutuseless at gmail.com>:

tos9 posted this snippeit to irc which behaves differently on pypy and cpython

==========================
class Foo(object):
    def __len__(self):
        raise Exception()
    def __iter__(self):
        return iter([])

list(Foo())
==========================

#############################################################################
# ipython2.7.2:
#############################################################################
In [1]: class Foo(object):
   ...:         def __len__(self):
   ...:                 raise Exception()
   ...:         def __iter__(self):
   ...:                 return iter([])
   ...:     

In [2]: list(Foo())
---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
/Users/mike/<ipython-input-2-1282cd60499e> in <module>()
----> 1 list(Foo())

/Users/mike/<ipython-input-1-02f6df2fcbd9> in __len__(self)
      1 class Foo(object):
      2         def __len__(self):
----> 3                 raise Exception()
      4         def __iter__(self):
      5                 return iter([])

Exception: 

In [3]:


#############################################################################
# PyPy
#############################################################################
Python 2.7.2 (c6d48bfb9d2f, May 30 2012, 03:00:21)
[PyPy 1.9.1-dev0 with GCC 4.2.1] on darwin
Type "help", "copyright", "credits" or "license" for more information.
And now for something completely different: ``in pypy you are always at the
wrong level, in one way or the other''
>>>> class Foo(object):
....     def __len__(self):
....         raise Exception()
....     def __iter__(self):
....         return iter([])
.... 
>>>> list(Foo())
[]
>>>>

----------
messages: 4373
nosy: mikefc, pypy-issue
priority: bug
status: unread
title: Different in custom list casting

________________________________________
PyPy bug tracker <tracker at bugs.pypy.org>
<https://bugs.pypy.org/issue1158>
________________________________________


More information about the pypy-issue mailing list