[pypy-commit] pypy length-hint: __length_hint__ comes from the type dict, not getattr

pjenvey noreply at buildbot.pypy.org
Fri Jul 13 06:21:11 CEST 2012


Author: Philip Jenvey <pjenvey at underboss.org>
Branch: length-hint
Changeset: r56056:c0456a723fa3
Date: 2012-07-12 21:19 -0700
http://bitbucket.org/pypy/pypy/changeset/c0456a723fa3/

Log:	__length_hint__ comes from the type dict, not getattr thanks arigo

diff --git a/pypy/objspace/std/iterobject.py b/pypy/objspace/std/iterobject.py
--- a/pypy/objspace/std/iterobject.py
+++ b/pypy/objspace/std/iterobject.py
@@ -15,9 +15,11 @@
                 e.match(space, space.w_AttributeError)):
             raise
 
+    w_descr = space.lookup(w_obj, '__length_hint__')
+    if w_descr is None:
+        return default
     try:
-        XXX  # should not use call_method here, which is based on getattr
-        w_hint = space.call_method(w_obj, '__length_hint__')
+        w_hint = space.get_and_call_function(w_descr, w_obj)
     except OperationError, e:
         if not (e.match(space, space.w_TypeError) or
                 e.match(space, space.w_AttributeError)):
diff --git a/pypy/objspace/std/test/test_lengthhint.py b/pypy/objspace/std/test/test_lengthhint.py
--- a/pypy/objspace/std/test/test_lengthhint.py
+++ b/pypy/objspace/std/test/test_lengthhint.py
@@ -40,13 +40,13 @@
         from pypy.interpreter.error import OperationError
         space = self.space
         w_foo = space.appexec([], """():
-            class Foo:
+            class Foo(object):
                 def __length_hint__(self):
                     1 / 0
             return Foo()
         """)
         try:
-            assert length_hint(space, w_foo, 3)
+            length_hint(space, w_foo, 3)
         except OperationError, e:
             assert e.match(space, space.w_ZeroDivisionError)
         else:


More information about the pypy-commit mailing list