[pypy-commit] pypy default: Issue #2353: improve the error message when doing 'enumerate(x)'

arigo pypy.commits at gmail.com
Sat Jul 30 11:54:26 EDT 2016


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r85932:a5faa8d03e8a
Date: 2016-07-30 17:56 +0200
http://bitbucket.org/pypy/pypy/changeset/a5faa8d03e8a/

Log:	Issue #2353: improve the error message when doing 'enumerate(x)'
	where x is not a regular list

diff --git a/rpython/rtyper/rrange.py b/rpython/rtyper/rrange.py
--- a/rpython/rtyper/rrange.py
+++ b/rpython/rtyper/rrange.py
@@ -199,8 +199,11 @@
         self.r_baseiter = r_baseiter
         self.lowleveltype = r_baseiter.lowleveltype
         # only supports for now enumerate() on sequence types whose iterators
-        # have a method ll_getnextindex.  It's easy to add one for most
-        # iterator types, but I didn't do it so far.
+        # have a method ll_getnextindex.  It could be added for most
+        # iterator types, but it's a bit messy for no clear benefit.
+        if not hasattr(r_baseiter, 'll_getnextindex'):
+            raise TyperError("not implemented for now: enumerate(x) where x "
+                             "is not a regular list (got %r)" % (r_baseiter,))
         self.ll_getnextindex = r_baseiter.ll_getnextindex
 
     def rtype_next(self, hop):


More information about the pypy-commit mailing list