[pypy-commit] pypy py3k: merge default

2016-10-09 Thread pjenvey
Author: Philip Jenvey 
Branch: py3k
Changeset: r87685:e0d72435262a
Date: 2016-10-09 19:59 -0700
http://bitbucket.org/pypy/pypy/changeset/e0d72435262a/

Log:merge default

diff --git a/pypy/interpreter/test/test_zzpickle_and_slow.py 
b/pypy/interpreter/test/test_zzpickle_and_slow.py
--- a/pypy/interpreter/test/test_zzpickle_and_slow.py
+++ b/pypy/interpreter/test/test_zzpickle_and_slow.py
@@ -391,10 +391,10 @@
 def test_pickle_reversesequenceiter_stopped(self):
 import pickle
 iter = reversed([])
-raises(StopIteration, iter.next)
+raises(StopIteration, next, iter)
 pckl   = pickle.dumps(iter)
 result = pickle.loads(pckl)
-raises(StopIteration, result.next)
+raises(StopIteration, next, result)
 
 # This test used to be marked xfail and it tried to test for the past
 # support of pickling dictiter objects.
@@ -428,10 +428,10 @@
 raise IndexError
 for it in (), IE():
 iter = reversed(it)
-raises(StopIteration, iter.next)
+raises(StopIteration, next, iter)
 pckl   = pickle.dumps(iter)
 result = pickle.loads(pckl)
-raises(StopIteration, result.next)
+raises(StopIteration, next, result)
 
 def test_pickle_enum(self):
 import pickle
diff --git a/pypy/objspace/std/test/test_iterobject.py 
b/pypy/objspace/std/test/test_iterobject.py
--- a/pypy/objspace/std/test/test_iterobject.py
+++ b/pypy/objspace/std/test/test_iterobject.py
@@ -120,8 +120,8 @@
 n = 10
 d = range(n)
 it = reversed(d)
-it.next()
-it.next()
+next(it)
+next(it)
 assert it.__length_hint__() == n-2
 d.append(n)
 assert it.__length_hint__() == n-2
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: py3 compat

2016-10-09 Thread pjenvey
Author: Philip Jenvey 
Branch: 
Changeset: r87684:2fa8ddb56cfa
Date: 2016-10-09 19:59 -0700
http://bitbucket.org/pypy/pypy/changeset/2fa8ddb56cfa/

Log:py3 compat

diff --git a/pypy/interpreter/test/test_zzpickle_and_slow.py 
b/pypy/interpreter/test/test_zzpickle_and_slow.py
--- a/pypy/interpreter/test/test_zzpickle_and_slow.py
+++ b/pypy/interpreter/test/test_zzpickle_and_slow.py
@@ -370,10 +370,10 @@
 def test_pickle_reversesequenceiter_stopped(self):
 import pickle
 iter = reversed([])
-raises(StopIteration, iter.next)
+raises(StopIteration, next, iter)
 pckl   = pickle.dumps(iter)
 result = pickle.loads(pckl)
-raises(StopIteration, result.next)
+raises(StopIteration, next, result)
 
 # This test used to be marked xfail and it tried to test for the past
 # support of pickling dictiter objects.
@@ -405,10 +405,10 @@
 raise IndexError
 for it in (), IE():
 iter = reversed(it)
-raises(StopIteration, iter.next)
+raises(StopIteration, next, iter)
 pckl   = pickle.dumps(iter)
 result = pickle.loads(pckl)
-raises(StopIteration, result.next)
+raises(StopIteration, next, result)
 
 def test_pickle_enum(self):
 import pickle
diff --git a/pypy/objspace/std/test/test_iterobject.py 
b/pypy/objspace/std/test/test_iterobject.py
--- a/pypy/objspace/std/test/test_iterobject.py
+++ b/pypy/objspace/std/test/test_iterobject.py
@@ -106,8 +106,8 @@
 n = 10
 d = range(n)
 it = reversed(d)
-it.next()
-it.next()
+next(it)
+next(it)
 assert it.__length_hint__() == n-2
 d.append(n)
 assert it.__length_hint__() == n-2
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: adapt to py3

2016-10-09 Thread pjenvey
Author: Philip Jenvey 
Branch: py3k
Changeset: r87682:88ebbb0a0058
Date: 2016-10-09 19:29 -0700
http://bitbucket.org/pypy/pypy/changeset/88ebbb0a0058/

Log:adapt to py3

diff --git a/pypy/objspace/std/test/test_typeobject.py 
b/pypy/objspace/std/test/test_typeobject.py
--- a/pypy/objspace/std/test/test_typeobject.py
+++ b/pypy/objspace/std/test/test_typeobject.py
@@ -897,7 +897,7 @@
 Abc.__name__ = 'Def'
 assert Abc.__name__ == 'Def'
 raises(TypeError, "Abc.__name__ = 42")
-raises(TypeError, "Abc.__name__ = u'A'")
+raises(TypeError, "Abc.__name__ = b'A'")
 try:
 Abc.__name__ = 'G\x00hi'
 except ValueError as e:
@@ -1221,12 +1221,12 @@
 assert int.__subclasscheck__(AbstractClass()) is True
 
 def test_bad_args(self):
-import UserDict
+import collections
 raises(TypeError, type, 'A', (), dict={})
 raises(TypeError, type, 'A', [], {})
-raises(TypeError, type, 'A', (), UserDict.UserDict())
+raises(TypeError, type, 'A', (), collections.UserDict())
 raises(ValueError, type, 'A\x00B', (), {})
-raises(TypeError, type, u'A', (), {})
+raises(TypeError, type, b'A', (), {})
 
 
 class AppTestWithMethodCacheCounter:
diff --git a/pypy/objspace/std/typeobject.py b/pypy/objspace/std/typeobject.py
--- a/pypy/objspace/std/typeobject.py
+++ b/pypy/objspace/std/typeobject.py
@@ -684,7 +684,7 @@
 def _check_new_args(space, w_name, w_bases, w_dict):
 if w_bases is None or w_dict is None:
 raise oefmt(space.w_TypeError, "type() takes 1 or 3 arguments")
-if not space.isinstance_w(w_name, space.w_str):
+if not space.isinstance_w(w_name, space.w_text):
 raise oefmt(space.w_TypeError,
 "type() argument 1 must be string, not %T", w_name)
 if not space.isinstance_w(w_bases, space.w_tuple):
@@ -769,7 +769,7 @@
 w_type = _check(space, w_type)
 if not w_type.is_heaptype():
 raise oefmt(space.w_TypeError, "can't set %N.__name__", w_type)
-if not space.isinstance_w(w_value, space.w_str):
+if not space.isinstance_w(w_value, space.w_text):
 raise oefmt(space.w_TypeError,
 "can only assign string to %N.__name__, not '%T'",
 w_type, w_value)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: adapt a2d8b4680ef9 to py3

2016-10-09 Thread pjenvey
Author: Philip Jenvey 
Branch: py3k
Changeset: r87683:9f40d9cc4ac8
Date: 2016-10-09 19:30 -0700
http://bitbucket.org/pypy/pypy/changeset/9f40d9cc4ac8/

Log:adapt a2d8b4680ef9 to py3

diff --git a/pypy/objspace/std/intobject.py b/pypy/objspace/std/intobject.py
--- a/pypy/objspace/std/intobject.py
+++ b/pypy/objspace/std/intobject.py
@@ -864,9 +864,12 @@
 return w_value
 return newbigint(space, w_inttype, space.bigint_w(w_value))
 elif space.lookup(w_value, '__int__') is not None:
-return _from_intlike(space, w_inttype, w_value)
+return _from_intlike(space, w_inttype, space.int(w_value))
 elif space.lookup(w_value, '__trunc__') is not None:
-return _from_intlike(space, w_inttype, space.trunc(w_value))
+w_obj = space.trunc(w_value)
+if not space.isinstance_w(w_obj, space.w_int):
+w_obj = space.int(w_obj)
+return _from_intlike(space, w_inttype, w_obj)
 elif space.isinstance_w(w_value, space.w_unicode):
 from pypy.objspace.std.unicodeobject import unicode_to_decimal_w
 b = unicode_to_decimal_w(space, w_value, allow_surrogates=True)
@@ -910,11 +913,10 @@
 
 
 def _from_intlike(space, w_inttype, w_intlike):
-w_obj = space.int(w_intlike)
 if space.is_w(w_inttype, space.w_int):
-return w_obj
+return w_intlike
 from pypy.objspace.std.longobject import newbigint
-return newbigint(space, w_inttype, space.bigint_w(w_obj))
+return newbigint(space, w_inttype, space.bigint_w(w_intlike))
 
 
 W_AbstractIntObject.typedef = TypeDef("int",
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: merge default

2016-10-09 Thread pjenvey
Author: Philip Jenvey 
Branch: py3k
Changeset: r87681:6434baec5a74
Date: 2016-10-09 18:01 -0700
http://bitbucket.org/pypy/pypy/changeset/6434baec5a74/

Log:merge default

diff too long, truncating to 2000 out of 38623 lines

diff --git a/lib-python/2.7/BaseHTTPServer.py b/lib-python/2.7/BaseHTTPServer.py
--- a/lib-python/2.7/BaseHTTPServer.py
+++ b/lib-python/2.7/BaseHTTPServer.py
@@ -362,14 +362,25 @@
 message = short
 explain = long
 self.log_error("code %d, message %s", code, message)
-# using _quote_html to prevent Cross Site Scripting attacks (see bug 
#1100201)
-content = (self.error_message_format %
-   {'code': code, 'message': _quote_html(message), 'explain': 
explain})
 self.send_response(code, message)
-self.send_header("Content-Type", self.error_content_type)
 self.send_header('Connection', 'close')
+
+# Message body is omitted for cases described in:
+#  - RFC7230: 3.3. 1xx, 204(No Content), 304(Not Modified)
+#  - RFC7231: 6.3.6. 205(Reset Content)
+content = None
+if code >= 200 and code not in (204, 205, 304):
+# HTML encode to prevent Cross Site Scripting attacks
+# (see bug #1100201)
+content = (self.error_message_format % {
+'code': code,
+'message': _quote_html(message),
+'explain': explain
+})
+self.send_header("Content-Type", self.error_content_type)
 self.end_headers()
-if self.command != 'HEAD' and code >= 200 and code not in (204, 304):
+
+if self.command != 'HEAD' and content:
 self.wfile.write(content)
 
 error_message_format = DEFAULT_ERROR_MESSAGE
diff --git a/lib-python/2.7/CGIHTTPServer.py b/lib-python/2.7/CGIHTTPServer.py
--- a/lib-python/2.7/CGIHTTPServer.py
+++ b/lib-python/2.7/CGIHTTPServer.py
@@ -84,7 +84,7 @@
 path begins with one of the strings in self.cgi_directories
 (and the next character is a '/' or the end of the string).
 """
-collapsed_path = _url_collapse_path(urllib.unquote(self.path))
+collapsed_path = _url_collapse_path(self.path)
 dir_sep = collapsed_path.find('/', 1)
 head, tail = collapsed_path[:dir_sep], collapsed_path[dir_sep+1:]
 if head in self.cgi_directories:
@@ -120,11 +120,7 @@
 break
 
 # find an explicit query string, if present.
-i = rest.rfind('?')
-if i >= 0:
-rest, query = rest[:i], rest[i+1:]
-else:
-query = ''
+rest, _, query = rest.partition('?')
 
 # dissect the part after the directory name into a script name &
 # a possible additional path, to be stored in PATH_INFO.
@@ -308,13 +304,15 @@
 The utility of this function is limited to is_cgi method and helps
 preventing some security attacks.
 
-Returns: A tuple of (head, tail) where tail is everything after the final /
-and head is everything before it.  Head will always start with a '/' and,
-if it contains anything else, never have a trailing '/'.
+Returns: The reconstituted URL, which will always start with a '/'.
 
 Raises: IndexError if too many '..' occur within the path.
 
 """
+# Query component should not be involved.
+path, _, query = path.partition('?')
+path = urllib.unquote(path)
+
 # Similar to os.path.split(os.path.normpath(path)) but specific to URL
 # path semantics rather than local operating system semantics.
 path_parts = path.split('/')
@@ -335,6 +333,9 @@
 else:
 tail_part = ''
 
+if query:
+tail_part = '?'.join((tail_part, query))
+
 splitpath = ('/' + '/'.join(head_parts), tail_part)
 collapsed_path = "/".join(splitpath)
 
diff --git a/lib-python/2.7/Cookie.py b/lib-python/2.7/Cookie.py
--- a/lib-python/2.7/Cookie.py
+++ b/lib-python/2.7/Cookie.py
@@ -190,7 +190,7 @@
 Backwards Compatibility
 ---
 
-In order to keep compatibilty with earlier versions of Cookie.py,
+In order to keep compatibility with earlier versions of Cookie.py,
 it is still possible to use Cookie.Cookie() to create a Cookie.  In
 fact, this simply returns a SmartCookie.
 
diff --git a/lib-python/2.7/SimpleHTTPServer.py 
b/lib-python/2.7/SimpleHTTPServer.py
--- a/lib-python/2.7/SimpleHTTPServer.py
+++ b/lib-python/2.7/SimpleHTTPServer.py
@@ -167,9 +167,9 @@
 words = filter(None, words)
 path = os.getcwd()
 for word in words:
-drive, word = os.path.splitdrive(word)
-head, word = os.path.split(word)
-if word in (os.curdir, os.pardir): continue
+if os.path.dirname(word) or word in (os.curdir, os.pardir):
+# Ignore components that are not a simple file/directory name
+continue
 path = os.path.join(path, word)
 if 

[pypy-commit] pypy stdlib-2.7.12: close branch before merge

2016-10-09 Thread pjenvey
Author: Philip Jenvey 
Branch: stdlib-2.7.12
Changeset: r87679:59fbca92a87f
Date: 2016-10-09 17:33 -0700
http://bitbucket.org/pypy/pypy/changeset/59fbca92a87f/

Log:close branch before merge

___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: merge default

2016-10-09 Thread pjenvey
Author: Philip Jenvey 
Branch: py3k
Changeset: r87678:ce7a5c1077b4
Date: 2016-10-09 17:35 -0700
http://bitbucket.org/pypy/pypy/changeset/ce7a5c1077b4/

Log:merge default

diff too long, truncating to 2000 out of 2071 lines

diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -67,3 +67,8 @@
 Change the ``timeit`` module: it now prints the average time and the standard
 deviation over 7 runs by default, instead of the minimum. The minimum is often
 misleading.
+
+.. branch: unrecursive-opt
+
+Make optimiseopt iterative instead of recursive so it can be reasoned about
+more easily and debugging is faster.
diff --git a/pypy/module/faulthandler/faulthandler.c 
b/pypy/module/faulthandler/faulthandler.c
--- a/pypy/module/faulthandler/faulthandler.c
+++ b/pypy/module/faulthandler/faulthandler.c
@@ -323,7 +323,7 @@
 faulthandler_register(int signum, int chain, _Py_sighandler_t *p_previous)
 {
 struct sigaction action;
-action.sa_handler = faulthandler_user;
+action.sa_sigaction = faulthandler_user;
 sigemptyset(_mask);
 /* if the signal is received while the kernel is executing a system
call, try to restart the system call instead of interrupting it and
diff --git a/rpython/jit/backend/tool/viewcode.py 
b/rpython/jit/backend/tool/viewcode.py
--- a/rpython/jit/backend/tool/viewcode.py
+++ b/rpython/jit/backend/tool/viewcode.py
@@ -28,7 +28,7 @@
 pass
 
 def find_objdump():
-exe = ('objdump', 'gobjdump')
+exe = ('objdump', 'gobjdump', 'objdump.exe')
 path = os.environ['PATH'].split(os.pathsep)
 for e in exe:
 for p in path:
diff --git a/rpython/jit/metainterp/optimizeopt/earlyforce.py 
b/rpython/jit/metainterp/optimizeopt/earlyforce.py
--- a/rpython/jit/metainterp/optimizeopt/earlyforce.py
+++ b/rpython/jit/metainterp/optimizeopt/earlyforce.py
@@ -26,7 +26,7 @@
 
 for arg in op.getarglist():
 self.optimizer.force_box(arg, self)
-self.emit_operation(op)
+return self.emit(op)
 
 def setup(self):
 self.optimizer.optearlyforce = self
diff --git a/rpython/jit/metainterp/optimizeopt/heap.py 
b/rpython/jit/metainterp/optimizeopt/heap.py
--- a/rpython/jit/metainterp/optimizeopt/heap.py
+++ b/rpython/jit/metainterp/optimizeopt/heap.py
@@ -128,7 +128,7 @@
 if a is optheap.postponed_op:
 optheap.emit_postponed_op()
 break
-optheap.next_optimization.propagate_forward(op)
+optheap.emit_extra(op, emit=False)
 if not can_cache:
 return
 # Once it is done, we can put at least one piece of information
@@ -259,7 +259,7 @@
 if self.postponed_op:
 postponed_op = self.postponed_op
 self.postponed_op = None
-self.next_optimization.propagate_forward(postponed_op)
+self.emit_extra(postponed_op, emit=False)
 
 def produce_potential_short_preamble_ops(self, sb):
 descrkeys = self.cached_fields.keys()
@@ -312,7 +312,7 @@
 cf = submap[index] = ArrayCachedItem(index)
 return cf
 
-def emit_operation(self, op):
+def emit(self, op):
 self.emitting_operation(op)
 self.emit_postponed_op()
 opnum = op.opnum
@@ -320,7 +320,7 @@
 or rop.is_ovf(opnum)):
 self.postponed_op = op
 else:
-Optimization.emit_operation(self, op)
+return Optimization.emit(self, op)
 
 def emitting_operation(self, op):
 if rop.has_no_side_effect(op.opnum):
@@ -370,7 +370,7 @@
 if oopspecindex == EffectInfo.OS_DICT_LOOKUP:
 if self._optimize_CALL_DICT_LOOKUP(op):
 return
-self.emit_operation(op)
+return self.emit(op)
 optimize_CALL_F = optimize_CALL_I
 optimize_CALL_R = optimize_CALL_I
 optimize_CALL_N = optimize_CALL_I
@@ -428,7 +428,7 @@
 def optimize_GUARD_NO_EXCEPTION(self, op):
 if self.last_emitted_operation is REMOVED:
 return
-self.emit_operation(op)
+return self.emit(op)
 
 optimize_GUARD_EXCEPTION = optimize_GUARD_NO_EXCEPTION
 
@@ -543,12 +543,21 @@
 return
 # default case: produce the operation
 self.make_nonnull(op.getarg(0))
-self.emit_operation(op)
+# return self.emit(op)
+return self.emit(op)
+
+def postprocess_GETFIELD_GC_I(self, op):
 # then remember the result of reading the field
-structinfo.setfield(descr, op.getarg(0), op, optheap=self, cf=cf)
+structinfo = self.ensure_ptr_info_arg0(op)
+cf = self.field_cache(op.getdescr())
+structinfo.setfield(op.getdescr(), op.getarg(0), op, optheap=self,
+cf=cf)
 optimize_GETFIELD_GC_R = optimize_GETFIELD_GC_I
 optimize_GETFIELD_GC_F = 

[pypy-commit] pypy default: upgrade the stdlib (merge stdlib-2.7.12)

2016-10-09 Thread pjenvey
Author: Philip Jenvey 
Branch: 
Changeset: r87680:45985a6302b0
Date: 2016-10-09 17:34 -0700
http://bitbucket.org/pypy/pypy/changeset/45985a6302b0/

Log:upgrade the stdlib (merge stdlib-2.7.12)

diff too long, truncating to 2000 out of 39761 lines

diff --git a/lib-python/2.7/BaseHTTPServer.py b/lib-python/2.7/BaseHTTPServer.py
--- a/lib-python/2.7/BaseHTTPServer.py
+++ b/lib-python/2.7/BaseHTTPServer.py
@@ -362,14 +362,25 @@
 message = short
 explain = long
 self.log_error("code %d, message %s", code, message)
-# using _quote_html to prevent Cross Site Scripting attacks (see bug 
#1100201)
-content = (self.error_message_format %
-   {'code': code, 'message': _quote_html(message), 'explain': 
explain})
 self.send_response(code, message)
-self.send_header("Content-Type", self.error_content_type)
 self.send_header('Connection', 'close')
+
+# Message body is omitted for cases described in:
+#  - RFC7230: 3.3. 1xx, 204(No Content), 304(Not Modified)
+#  - RFC7231: 6.3.6. 205(Reset Content)
+content = None
+if code >= 200 and code not in (204, 205, 304):
+# HTML encode to prevent Cross Site Scripting attacks
+# (see bug #1100201)
+content = (self.error_message_format % {
+'code': code,
+'message': _quote_html(message),
+'explain': explain
+})
+self.send_header("Content-Type", self.error_content_type)
 self.end_headers()
-if self.command != 'HEAD' and code >= 200 and code not in (204, 304):
+
+if self.command != 'HEAD' and content:
 self.wfile.write(content)
 
 error_message_format = DEFAULT_ERROR_MESSAGE
diff --git a/lib-python/2.7/CGIHTTPServer.py b/lib-python/2.7/CGIHTTPServer.py
--- a/lib-python/2.7/CGIHTTPServer.py
+++ b/lib-python/2.7/CGIHTTPServer.py
@@ -84,7 +84,7 @@
 path begins with one of the strings in self.cgi_directories
 (and the next character is a '/' or the end of the string).
 """
-collapsed_path = _url_collapse_path(urllib.unquote(self.path))
+collapsed_path = _url_collapse_path(self.path)
 dir_sep = collapsed_path.find('/', 1)
 head, tail = collapsed_path[:dir_sep], collapsed_path[dir_sep+1:]
 if head in self.cgi_directories:
@@ -120,11 +120,7 @@
 break
 
 # find an explicit query string, if present.
-i = rest.rfind('?')
-if i >= 0:
-rest, query = rest[:i], rest[i+1:]
-else:
-query = ''
+rest, _, query = rest.partition('?')
 
 # dissect the part after the directory name into a script name &
 # a possible additional path, to be stored in PATH_INFO.
@@ -308,13 +304,15 @@
 The utility of this function is limited to is_cgi method and helps
 preventing some security attacks.
 
-Returns: A tuple of (head, tail) where tail is everything after the final /
-and head is everything before it.  Head will always start with a '/' and,
-if it contains anything else, never have a trailing '/'.
+Returns: The reconstituted URL, which will always start with a '/'.
 
 Raises: IndexError if too many '..' occur within the path.
 
 """
+# Query component should not be involved.
+path, _, query = path.partition('?')
+path = urllib.unquote(path)
+
 # Similar to os.path.split(os.path.normpath(path)) but specific to URL
 # path semantics rather than local operating system semantics.
 path_parts = path.split('/')
@@ -335,6 +333,9 @@
 else:
 tail_part = ''
 
+if query:
+tail_part = '?'.join((tail_part, query))
+
 splitpath = ('/' + '/'.join(head_parts), tail_part)
 collapsed_path = "/".join(splitpath)
 
diff --git a/lib-python/2.7/Cookie.py b/lib-python/2.7/Cookie.py
--- a/lib-python/2.7/Cookie.py
+++ b/lib-python/2.7/Cookie.py
@@ -190,7 +190,7 @@
 Backwards Compatibility
 ---
 
-In order to keep compatibilty with earlier versions of Cookie.py,
+In order to keep compatibility with earlier versions of Cookie.py,
 it is still possible to use Cookie.Cookie() to create a Cookie.  In
 fact, this simply returns a SmartCookie.
 
diff --git a/lib-python/2.7/SimpleHTTPServer.py 
b/lib-python/2.7/SimpleHTTPServer.py
--- a/lib-python/2.7/SimpleHTTPServer.py
+++ b/lib-python/2.7/SimpleHTTPServer.py
@@ -167,9 +167,9 @@
 words = filter(None, words)
 path = os.getcwd()
 for word in words:
-drive, word = os.path.splitdrive(word)
-head, word = os.path.split(word)
-if word in (os.curdir, os.pardir): continue
+if os.path.dirname(word) or word in (os.curdir, os.pardir):
+# Ignore components that are not a simple file/directory name
+continue
 path = os.path.join(path, 

[pypy-commit] pypy Tiberiumk/fix-2412-1476011166874: Fix #2412

2016-10-09 Thread Tiberiumk
Author: Daniil Yarancev 
Branch: Tiberiumk/fix-2412-1476011166874
Changeset: r87676:4974546c78e0
Date: 2016-10-09 11:08 +
http://bitbucket.org/pypy/pypy/changeset/4974546c78e0/

Log:Fix #2412

diff --git a/rpython/jit/backend/tool/viewcode.py 
b/rpython/jit/backend/tool/viewcode.py
--- a/rpython/jit/backend/tool/viewcode.py
+++ b/rpython/jit/backend/tool/viewcode.py
@@ -28,7 +28,7 @@
 pass
 
 def find_objdump():
-exe = ('objdump', 'gobjdump')
+exe = ('objdump', 'gobjdump', 'objdump.exe')
 path = os.environ['PATH'].split(os.pathsep)
 for e in exe:
 for p in path:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Merged in Tiberiumk/pypy/Tiberiumk/fix-2412-1476011166874 (pull request #487)

2016-10-09 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r87677:a4c04ebd809e
Date: 2016-10-09 19:53 +0200
http://bitbucket.org/pypy/pypy/changeset/a4c04ebd809e/

Log:Merged in Tiberiumk/pypy/Tiberiumk/fix-2412-1476011166874 (pull
request #487)

Fix #2412

diff --git a/rpython/jit/backend/tool/viewcode.py 
b/rpython/jit/backend/tool/viewcode.py
--- a/rpython/jit/backend/tool/viewcode.py
+++ b/rpython/jit/backend/tool/viewcode.py
@@ -28,7 +28,7 @@
 pass
 
 def find_objdump():
-exe = ('objdump', 'gobjdump')
+exe = ('objdump', 'gobjdump', 'objdump.exe')
 path = os.environ['PATH'].split(os.pathsep)
 for e in exe:
 for p in path:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: Fix interpreter/test/test_raise:test_context_with_suppressed by

2016-10-09 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r87675:6fe3befdcc99
Date: 2016-10-09 19:51 +0200
http://bitbucket.org/pypy/pypy/changeset/6fe3befdcc99/

Log:Fix interpreter/test/test_raise:test_context_with_suppressed by
copying 7737b9ffdd0b, which was lost in some merge

Disclaimer: this might be still incomplete

diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -1155,11 +1155,15 @@
 old_last_exception = self.last_exception
 self.last_exception = operr
 w_traceback = self.space.wrap(operr.get_traceback())
-w_res = self.call_contextmanager_exit_function(
-w_exitfunc,
-operr.w_type,
-operr.get_w_value(self.space),
-w_traceback)
+try:
+w_res = self.call_contextmanager_exit_function(
+w_exitfunc,
+operr.w_type,
+operr.get_w_value(self.space),
+w_traceback)
+except:
+self.last_exception = old_last_exception
+raise
 # push a marker that also contains the old_last_exception,
 # which must be restored as 'self.last_exception' but only
 # in WITH_CLEANUP_FINISH
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Close unrecursive-opt branch.

2016-10-09 Thread jerith
Author: Jeremy Thurgood 
Branch: 
Changeset: r87674:056aa96369a4
Date: 2016-10-09 19:39 +0200
http://bitbucket.org/pypy/pypy/changeset/056aa96369a4/

Log:Close unrecursive-opt branch.

___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy unrecursive-opt: Close branch unrecursive-opt.

2016-10-09 Thread jerith
Author: Jeremy Thurgood 
Branch: unrecursive-opt
Changeset: r87673:6d72d11bf9c3
Date: 2016-10-09 17:37 +
http://bitbucket.org/pypy/pypy/changeset/6d72d11bf9c3/

Log:Close branch unrecursive-opt.

___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Update whatsnew-head before the builds all fail.

2016-10-09 Thread jerith
Author: Jeremy Thurgood 
Branch: 
Changeset: r87672:8b4dd04c1900
Date: 2016-10-09 19:32 +0200
http://bitbucket.org/pypy/pypy/changeset/8b4dd04c1900/

Log:Update whatsnew-head before the builds all fail.

diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -61,3 +61,8 @@
 Change the ``timeit`` module: it now prints the average time and the standard
 deviation over 7 runs by default, instead of the minimum. The minimum is often
 misleading.
+
+.. branch: unrecursive-opt
+
+Make optimiseopt iterative instead of recursive so it can be reasoned about
+more easily and debugging is faster.
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Merge unrecursive-opt branch

2016-10-09 Thread jerith
Author: Jeremy Thurgood 
Branch: 
Changeset: r87671:e26ed9527792
Date: 2016-10-09 19:28 +0200
http://bitbucket.org/pypy/pypy/changeset/e26ed9527792/

Log:Merge unrecursive-opt branch

This makes optimiseopt iterative instead of recursive so it can be
reasoned about more easily and debugging is faster.

diff too long, truncating to 2000 out of 2035 lines

diff --git a/rpython/jit/metainterp/optimizeopt/earlyforce.py 
b/rpython/jit/metainterp/optimizeopt/earlyforce.py
--- a/rpython/jit/metainterp/optimizeopt/earlyforce.py
+++ b/rpython/jit/metainterp/optimizeopt/earlyforce.py
@@ -26,7 +26,7 @@
 
 for arg in op.getarglist():
 self.optimizer.force_box(arg, self)
-self.emit_operation(op)
+return self.emit(op)
 
 def setup(self):
 self.optimizer.optearlyforce = self
diff --git a/rpython/jit/metainterp/optimizeopt/heap.py 
b/rpython/jit/metainterp/optimizeopt/heap.py
--- a/rpython/jit/metainterp/optimizeopt/heap.py
+++ b/rpython/jit/metainterp/optimizeopt/heap.py
@@ -128,7 +128,7 @@
 if a is optheap.postponed_op:
 optheap.emit_postponed_op()
 break
-optheap.next_optimization.propagate_forward(op)
+optheap.emit_extra(op, emit=False)
 if not can_cache:
 return
 # Once it is done, we can put at least one piece of information
@@ -259,7 +259,7 @@
 if self.postponed_op:
 postponed_op = self.postponed_op
 self.postponed_op = None
-self.next_optimization.propagate_forward(postponed_op)
+self.emit_extra(postponed_op, emit=False)
 
 def produce_potential_short_preamble_ops(self, sb):
 descrkeys = self.cached_fields.keys()
@@ -312,7 +312,7 @@
 cf = submap[index] = ArrayCachedItem(index)
 return cf
 
-def emit_operation(self, op):
+def emit(self, op):
 self.emitting_operation(op)
 self.emit_postponed_op()
 opnum = op.opnum
@@ -320,7 +320,7 @@
 or rop.is_ovf(opnum)):
 self.postponed_op = op
 else:
-Optimization.emit_operation(self, op)
+return Optimization.emit(self, op)
 
 def emitting_operation(self, op):
 if rop.has_no_side_effect(op.opnum):
@@ -370,7 +370,7 @@
 if oopspecindex == EffectInfo.OS_DICT_LOOKUP:
 if self._optimize_CALL_DICT_LOOKUP(op):
 return
-self.emit_operation(op)
+return self.emit(op)
 optimize_CALL_F = optimize_CALL_I
 optimize_CALL_R = optimize_CALL_I
 optimize_CALL_N = optimize_CALL_I
@@ -428,7 +428,7 @@
 def optimize_GUARD_NO_EXCEPTION(self, op):
 if self.last_emitted_operation is REMOVED:
 return
-self.emit_operation(op)
+return self.emit(op)
 
 optimize_GUARD_EXCEPTION = optimize_GUARD_NO_EXCEPTION
 
@@ -543,12 +543,21 @@
 return
 # default case: produce the operation
 self.make_nonnull(op.getarg(0))
-self.emit_operation(op)
+# return self.emit(op)
+return self.emit(op)
+
+def postprocess_GETFIELD_GC_I(self, op):
 # then remember the result of reading the field
-structinfo.setfield(descr, op.getarg(0), op, optheap=self, cf=cf)
+structinfo = self.ensure_ptr_info_arg0(op)
+cf = self.field_cache(op.getdescr())
+structinfo.setfield(op.getdescr(), op.getarg(0), op, optheap=self,
+cf=cf)
 optimize_GETFIELD_GC_R = optimize_GETFIELD_GC_I
 optimize_GETFIELD_GC_F = optimize_GETFIELD_GC_I
 
+postprocess_GETFIELD_GC_R = postprocess_GETFIELD_GC_I
+postprocess_GETFIELD_GC_F = postprocess_GETFIELD_GC_I
+
 def optimize_SETFIELD_GC(self, op):
 self.setfield(op)
 #opnum = OpHelpers.getfield_pure_for_descr(op.getdescr())
@@ -582,9 +591,16 @@
  self.getintbound(op.getarg(1)))
 # default case: produce the operation
 self.make_nonnull(op.getarg(0))
-self.emit_operation(op)
+# return self.emit(op)
+return self.emit(op)
+
+def postprocess_GETARRAYITEM_GC_I(self, op):
 # then remember the result of reading the array item
-if cf is not None:
+arrayinfo = self.ensure_ptr_info_arg0(op)
+indexb = self.getintbound(op.getarg(1))
+if indexb.is_constant():
+index = indexb.getint()
+cf = self.arrayitem_cache(op.getdescr(), index)
 arrayinfo.setitem(op.getdescr(), indexb.getint(),
   self.get_box_replacement(op.getarg(0)),
   self.get_box_replacement(op), optheap=self,
@@ -592,6 +608,9 @@
 optimize_GETARRAYITEM_GC_R = optimize_GETARRAYITEM_GC_I
 optimize_GETARRAYITEM_GC_F = optimize_GETARRAYITEM_GC_I
 
+postprocess_GETARRAYITEM_GC_R 

[pypy-commit] pypy py3.5: Fix segfault in itertools.product.__setstate__

2016-10-09 Thread amauryfa
Author: Amaury Forgeot d'Arc 
Branch: py3.5
Changeset: r87667:c03d2d2eff2f
Date: 2016-10-09 17:30 +0200
http://bitbucket.org/pypy/pypy/changeset/c03d2d2eff2f/

Log:Fix segfault in itertools.product.__setstate__ (CPython issue 25021)

diff --git a/pypy/module/itertools/interp_itertools.py 
b/pypy/module/itertools/interp_itertools.py
--- a/pypy/module/itertools/interp_itertools.py
+++ b/pypy/module/itertools/interp_itertools.py
@@ -1216,6 +1216,7 @@
 #
 for gear in self.gears:
 if len(gear) == 0:
+self.indices = None
 self.lst = None
 self.stopped = True
 break
@@ -1303,12 +1304,16 @@
 for i, gear in enumerate(self.gears):
 w_index = indices_w[i]
 index = space.int_w(w_index)
+gear_size = len(gear)
+if self.indices is None or gear_size == 0:
+self.stopped = True
+return
 if index < 0:
 index = 0
-if index > gear_count - 1:
-index = gear_count - 1
+if index > gear_size - 1:
+index = gear_size - 1
 self.indices[i] = index
-lst.append(gear[self.indices[i]])
+lst.append(gear[index])
 self.lst = lst
 
 def W_Product__new__(space, w_subtype, __args__):
diff --git a/pypy/module/itertools/test/test_itertools.py 
b/pypy/module/itertools/test/test_itertools.py
--- a/pypy/module/itertools/test/test_itertools.py
+++ b/pypy/module/itertools/test/test_itertools.py
@@ -820,6 +820,20 @@
 assert list(product('ab', '', 'ef')) == []
 assert list(product('', 'cd', 'ef')) == []
 
+def test_product_setstate(self):
+# test that indices are properly clamped to the length of the tuples
+from itertools import product
+p = product((1, 2),(3,))
+# will access tuple element 1 if not clamped
+p.__setstate__((0, 0x1000))
+assert next(p) == (2, 3)
+# test that empty tuple in the list will result in an
+# immediate StopIteration
+p = product((1, 2), (), (3,))
+# will access tuple element 1 if not clamped
+p.__setstate__((0, 0, 0x1000))
+raises(StopIteration, next, p)
+
 def test_permutations(self):
 from itertools import permutations
 assert list(permutations('AB')) == [('A', 'B'), ('B', 'A')]
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: Fix test_islice when run with -A, then change itertools.islice() to clear the iterator when exhausted.

2016-10-09 Thread amauryfa
Author: Amaury Forgeot d'Arc 
Branch: py3.5
Changeset: r87669:55828ab39bab
Date: 2016-10-09 17:56 +0200
http://bitbucket.org/pypy/pypy/changeset/55828ab39bab/

Log:Fix test_islice when run with -A, then change itertools.islice() to
clear the iterator when exhausted.

diff --git a/pypy/module/itertools/interp_itertools.py 
b/pypy/module/itertools/interp_itertools.py
--- a/pypy/module/itertools/interp_itertools.py
+++ b/pypy/module/itertools/interp_itertools.py
@@ -317,7 +317,6 @@
 def __init__(self, space, w_iterable, w_startstop, args_w):
 self.iterable = space.iter(w_iterable)
 self.space = space
-self.exhausted = False
 
 num_args = len(args_w)
 
@@ -385,24 +384,24 @@
 # has no effect any more
 if stop > 0:
 self._ignore_items(stop)
-self.exhausted = True
+self.iterable = None
 raise OperationError(self.space.w_StopIteration,
  self.space.w_None)
 self.stop = stop - (ignore + 1)
 if ignore > 0:
 self._ignore_items(ignore)
-if self.exhausted:
+if self.iterable is None:
 raise OperationError(self.space.w_StopIteration, self.space.w_None)
 try:
 return self.space.next(self.iterable)
 except OperationError as e:
 if e.match(self.space, self.space.w_StopIteration):
-self.exhausted = True
+self.iterable = None
 raise
 
 def _ignore_items(self, num):
 w_iterator = self.iterable
-if self.exhausted:
+if w_iterator is None:
 raise OperationError(self.space.w_StopIteration, self.space.w_None)
 
 tp = self.space.type(w_iterator)
@@ -415,13 +414,22 @@
 self.space.next(w_iterator)
 except OperationError as e:
 if e.match(self.space, self.space.w_StopIteration):
-self.exhausted = True
+self.iterable = None
 raise
 num -= 1
 if num <= 0:
 break
 
 def descr_reduce(self, space):
+if self.iterable is None:
+return space.newtuple([
+space.type(self),
+space.newtuple([space.iter(space.newlist([])),
+space.wrap(0),
+space.wrap(0),
+space.wrap(1),
+]),
+])
 start = self.start
 stop = self.stop
 if start == -1:
diff --git a/pypy/module/itertools/test/test_itertools.py 
b/pypy/module/itertools/test/test_itertools.py
--- a/pypy/module/itertools/test/test_itertools.py
+++ b/pypy/module/itertools/test/test_itertools.py
@@ -222,7 +222,7 @@
 assert wr() is not None
 list(it)  # exhaust the iterator
 import gc; gc.collect()
-assert wr() is not None
+assert wr() is None
 raises(StopIteration, next, it)
 
 def test_islice_dropitems_exact(self):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: Let all tests pass with -A. Remove the obsolete skip instructions:

2016-10-09 Thread amauryfa
Author: Amaury Forgeot d'Arc 
Branch: py3.5
Changeset: r87670:d4253042e13e
Date: 2016-10-09 18:12 +0200
http://bitbucket.org/pypy/pypy/changeset/d4253042e13e/

Log:Let all tests pass with -A. Remove the obsolete skip instructions:
at least with python3, we always test with the same version as the
PyPy version.

diff --git a/pypy/module/itertools/test/test_itertools.py 
b/pypy/module/itertools/test/test_itertools.py
--- a/pypy/module/itertools/test/test_itertools.py
+++ b/pypy/module/itertools/test/test_itertools.py
@@ -598,7 +598,7 @@
 class MyIterator(object):
 def __iter__(self):
 return self
-def next(self):
+def __next__(self):
 raise NotImplementedError
 def __copy__(self):
 return iter('def')
@@ -623,12 +623,6 @@
 class AppTestItertools26:
 spaceconfig = dict(usemodules=['itertools'])
 
-def setup_class(cls):
-if cls.space.is_true(cls.space.appexec([], """():
-import sys; return sys.version_info < (2, 6)
-""")):
-py.test.skip("Requires Python 2.6")
-
 def test_count_overflow(self):
 import itertools, sys
 it = itertools.count(sys.maxsize - 1)
@@ -1071,12 +1065,6 @@
 class AppTestItertools32:
 spaceconfig = dict(usemodules=['itertools'])
 
-def setup_class(cls):
-if cls.space.is_true(cls.space.appexec([], """():
-import sys; return sys.version_info < (3, 2)
-""")):
-py.test.skip("Requires Python 3.2")
-
 def test_accumulate(self):
 """copied from ./lib-python/3/test/test_itertools.py"""
 from itertools import accumulate
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: Rename operator._length_hint to length_hint.

2016-10-09 Thread amauryfa
Author: Amaury Forgeot d'Arc 
Branch: py3.5
Changeset: r87668:60272f813dd6
Date: 2016-10-09 17:38 +0200
http://bitbucket.org/pypy/pypy/changeset/60272f813dd6/

Log:Rename operator._length_hint to length_hint.

diff --git a/pypy/module/itertools/test/test_itertools.py 
b/pypy/module/itertools/test/test_itertools.py
--- a/pypy/module/itertools/test/test_itertools.py
+++ b/pypy/module/itertools/test/test_itertools.py
@@ -97,7 +97,7 @@
 raises(TypeError, "len(itertools.repeat('xkcd'))")
 
 r = itertools.repeat('a', -3)
-assert operator._length_hint(r, 3) == 0
+assert operator.length_hint(r, 3) == 0
 
 def test_takewhile(self):
 import itertools
diff --git a/pypy/module/operator/__init__.py b/pypy/module/operator/__init__.py
--- a/pypy/module/operator/__init__.py
+++ b/pypy/module/operator/__init__.py
@@ -20,7 +20,7 @@
 'iadd', 'iand', 'iconcat', 'ifloordiv',
 'ilshift', 'imod', 'imul', 'ior', 'ipow',
 'irshift', 'isub', 'itruediv', 'imatmul', 'ixor',
-'_length_hint', 'indexOf']
+'length_hint', 'indexOf']
 
 interpleveldefs = {
 '_compare_digest': 'tscmp.compare_digest',
diff --git a/pypy/module/operator/interp_operator.py 
b/pypy/module/operator/interp_operator.py
--- a/pypy/module/operator/interp_operator.py
+++ b/pypy/module/operator/interp_operator.py
@@ -209,8 +209,11 @@
 
 return space.inplace_add(w_obj1, w_obj2)
 
-# _length_hint (to be length_hint in 3.4)
-
 @unwrap_spec(default=int)
-def _length_hint(space, w_iterable, default):
+def length_hint(space, w_iterable, default):
+"""Return an estimate of the number of items in obj.
+This is useful for presizing containers when building from an iterable.
+If the object supports len(), the result will be exact.
+Otherwise, it may over- or under-estimate by an arbitrary amount.
+The result will be an integer >= 0."""
 return space.wrap(space.length_hint(w_iterable, default))
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: Implement deque.index and fix spacing

2016-10-09 Thread reubano
Author: Reuben Cummings 
Branch: py3.5
Changeset: r87666:f5ff941a8b4b
Date: 2016-10-09 16:48 +0200
http://bitbucket.org/pypy/pypy/changeset/f5ff941a8b4b/

Log:Implement deque.index and fix spacing

diff --git a/pypy/module/_collections/interp_deque.py 
b/pypy/module/_collections/interp_deque.py
--- a/pypy/module/_collections/interp_deque.py
+++ b/pypy/module/_collections/interp_deque.py
@@ -194,7 +194,6 @@
 
 return space.wrap(copied)
 
-
 def imul(self, w_int):
 space = self.space
 copied = self.copy()
@@ -205,7 +204,6 @@
 
 return space.wrap(self)
 
-
 def copy(self):
 """ A shallow copy """
 space = self.space
@@ -343,6 +341,45 @@
 def iter(self):
 return W_DequeIter(self)
 
+def index(self, w_x, w_start=None, w_stop=None):
+space = self.space
+w_iter = space.iter(self)
+_len = self.len
+start = 0
+stop = _len
+
+if w_start is not None:
+start = space.int_w(w_start)
+
+if start < 0:
+start += _len
+
+if start < 0:
+start = 0
+elif start > _len:
+start = _len
+
+if w_stop is not None:
+stop = space.int_w(w_stop)
+
+if stop < 0:
+stop += _len
+
+if 0 <= stop > _len:
+stop = _len
+
+for i in range(0, stop):
+value = space.next(w_iter)
+
+if i < start:
+continue
+
+if space.eq_w(value, w_x):
+return space.wrap(i)
+
+x = space.repr(w_x)
+raise oefmt(self.space.w_ValueError, "%s is not in deque" % x)
+
 def reviter(self):
 "Return a reverse iterator over the deque."
 return W_DequeRevIter(self)
@@ -508,6 +545,7 @@
 count  = interp2app(W_Deque.count),
 extend = interp2app(W_Deque.extend),
 extendleft = interp2app(W_Deque.extendleft),
+index  = interp2app(W_Deque.index),
 pop= interp2app(W_Deque.pop),
 popleft= interp2app(W_Deque.popleft),
 remove = interp2app(W_Deque.remove),
diff --git a/pypy/module/_collections/test/test_deque.py 
b/pypy/module/_collections/test/test_deque.py
--- a/pypy/module/_collections/test/test_deque.py
+++ b/pypy/module/_collections/test/test_deque.py
@@ -290,6 +290,21 @@
 mut[0] = 11
 assert d == e
 
+def test_index(self):
+from _collections import deque
+d = deque([1,2,'a',1,2])
+assert d.index(1) is 0
+assert d.index('a') is 2
+assert d.index(1,2) is 3
+assert d.index('a',-3) is 2
+assert d.index('a',-3,-1) is 2
+assert d.index('a',-9) is 2
+raises(ValueError, d.index, 2, 2, -1)
+raises(ValueError, d.index, 1, 1, 3)
+raises(ValueError, d.index, 'a', -3, -3)
+raises(ValueError, d.index, 'a', 1, -3)
+raises(ValueError, d.index, 'a', -3, -9)
+
 def test_reversed(self):
 from _collections import deque
 for s in ('abcd', range(200)):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: Fix own test pypy/interpreter/test/test_syntax.py,

2016-10-09 Thread amauryfa
Author: Amaury Forgeot d'Arc 
Branch: py3.5
Changeset: r87664:57ef7c44238c
Date: 2016-10-01 22:45 +0200
http://bitbucket.org/pypy/pypy/changeset/57ef7c44238c/

Log:Fix own test pypy/interpreter/test/test_syntax.py, this clears
test_grammar.

diff --git a/pypy/interpreter/astcompiler/codegen.py 
b/pypy/interpreter/astcompiler/codegen.py
--- a/pypy/interpreter/astcompiler/codegen.py
+++ b/pypy/interpreter/astcompiler/codegen.py
@@ -352,7 +352,13 @@
 space = self.space
 names = []
 self._visit_arg_annotations(args.args, names)
+if args.vararg:
+self._visit_arg_annotation(args.vararg.arg, args.vararg.annotation,
+   names)
 self._visit_arg_annotations(args.kwonlyargs, names)
+if args.kwarg:
+self._visit_arg_annotation(args.kwarg.arg, args.kwarg.annotation,
+   names)
 self._visit_arg_annotation("return", returns, names)
 l = len(names)
 if l:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: python Issue #21408: The default __ne__() now returns NotImplemented if __eq__() returned NotImplemented.

2016-10-09 Thread amauryfa
Author: Amaury Forgeot d'Arc 
Branch: py3.5
Changeset: r87665:0fd09e396a7c
Date: 2016-10-09 16:46 +0200
http://bitbucket.org/pypy/pypy/changeset/0fd09e396a7c/

Log:python Issue #21408: The default __ne__() now returns NotImplemented
if __eq__() returned NotImplemented.

diff --git a/pypy/objspace/descroperation.py b/pypy/objspace/descroperation.py
--- a/pypy/objspace/descroperation.py
+++ b/pypy/objspace/descroperation.py
@@ -589,7 +589,10 @@
 else:
 return space.w_False
 elif left == '__ne__':
-return space.not_(space.eq(w_obj1, w_obj2))
+if space.is_w(w_obj1, w_obj2):
+return space.w_False
+else:
+return space.w_True
 #
 # if we arrived here, they are unorderable
 raise oefmt(space.w_TypeError,
diff --git a/pypy/objspace/std/objectobject.py 
b/pypy/objspace/std/objectobject.py
--- a/pypy/objspace/std/objectobject.py
+++ b/pypy/objspace/std/objectobject.py
@@ -207,7 +207,13 @@
 return space.w_NotImplemented
 
 def descr__ne__(space, w_self, w_other):
-return space.not_(space.eq(w_self, w_other))
+# By default, __ne__() delegates to __eq__() and inverts the result,
+# unless the latter returns NotImplemented.
+w_eq = space.lookup(w_self, '__eq__')
+w_res = space.get_and_call_function(w_eq, w_self, w_other)
+if space.is_w(w_res, space.w_NotImplemented):
+return w_res
+return space.not_(w_res)
 
 def descr_richcompare(space, w_self, w_other):
 return space.w_NotImplemented
diff --git a/pypy/objspace/std/test/test_obj.py 
b/pypy/objspace/std/test/test_obj.py
--- a/pypy/objspace/std/test/test_obj.py
+++ b/pypy/objspace/std/test/test_obj.py
@@ -276,7 +276,7 @@
 assert o.__eq__(o) is True
 assert o.__eq__(o2) is NotImplemented
 assert o.__ne__(o) is False
-assert o.__ne__(o2) is True
+assert o.__ne__(o2) is NotImplemented
 assert o.__le__(o2) is NotImplemented
 assert o.__lt__(o2) is NotImplemented
 assert o.__ge__(o2) is NotImplemented
diff --git a/pypy/objspace/test/test_descroperation.py 
b/pypy/objspace/test/test_descroperation.py
--- a/pypy/objspace/test/test_descroperation.py
+++ b/pypy/objspace/test/test_descroperation.py
@@ -464,6 +464,42 @@
 assert not(A(1) != B(1))
 assert not(B(1) != A(1))
 
+def test_ne_high_priority(self):
+"""object.__ne__() should allow reflected __ne__() to be tried"""
+calls = []
+class Left:
+# Inherits object.__ne__()
+def __eq__(*args):
+calls.append('Left.__eq__')
+return NotImplemented
+class Right:
+def __eq__(*args):
+calls.append('Right.__eq__')
+return NotImplemented
+def __ne__(*args):
+calls.append('Right.__ne__')
+return NotImplemented
+Left() != Right()
+assert calls == ['Left.__eq__', 'Right.__ne__']
+
+def test_ne_low_priority(self):
+"""object.__ne__() should not invoke reflected __eq__()"""
+calls = []
+class Base:
+# Inherits object.__ne__()
+def __eq__(*args):
+calls.append('Base.__eq__')
+return NotImplemented
+class Derived(Base):  # Subclassing forces higher priority
+def __eq__(*args):
+calls.append('Derived.__eq__')
+return NotImplemented
+def __ne__(*args):
+calls.append('Derived.__ne__')
+return NotImplemented
+Base() != Derived()
+assert calls == ['Derived.__ne__', 'Base.__eq__']
+
 def test_partial_ordering(self):
 class A(object):
 def __lt__(self, other):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: "print x" now raises a nice SyntaxError("Missing parentheses in call to 'print'")

2016-10-09 Thread amauryfa
Author: Amaury Forgeot d'Arc 
Branch: py3.5
Changeset: r87663:eacce032f81c
Date: 2016-10-01 22:29 +0200
http://bitbucket.org/pypy/pypy/changeset/eacce032f81c/

Log:"print x" now raises a nice SyntaxError("Missing parentheses in call
to 'print'")

diff --git a/pypy/module/exceptions/interp_exceptions.py 
b/pypy/module/exceptions/interp_exceptions.py
--- a/pypy/module/exceptions/interp_exceptions.py
+++ b/pypy/module/exceptions/interp_exceptions.py
@@ -728,6 +728,8 @@
 args_w = args_w[:]
 args_w[1] = space.newtuple(values_w[:4])
 W_BaseException.descr_init(self, space, args_w)
+if self.w_text and space.isinstance_w(self.w_text, space.w_unicode):
+self._report_missing_parentheses(space)
 
 def descr_str(self, space):
 return space.appexec([self], """(self):
@@ -770,6 +772,42 @@
 else:
 return W_Exception.descr_repr(self, space)
 
+# CPython Issue #21669: Custom error for 'print' & 'exec' as statements
+def _report_missing_parentheses(self, space):
+text = space.unicode_w(self.w_text)
+if u'(' in text:
+# Use default error message for any line with an opening paren
+return
+# handle the simple statement case
+if self._check_for_legacy_statements(space, text, 0):
+return
+# Handle the one-line complex statement case
+pos = text.find(u':')
+if pos < 0:
+return
+# Check again, starting from just after the colon
+self._check_for_legacy_statements(space, text, pos+1)
+
+def _check_for_legacy_statements(self, space, text, start):
+# Ignore leading whitespace
+while start < len(text) and text[start] == u' ':
+start += 1
+# Checking against an empty or whitespace-only part of the string
+if start == len(text):
+return False
+if start > 0:
+text = text[start:]
+# Check for legacy print statements
+if text.startswith(u"print "):
+self.w_msg = space.wrap("Missing parentheses in call to 'print'")
+return True
+# Check for legacy exec statements
+if text.startswith(u"exec "):
+self.w_msg = space.wrap("Missing parentheses in call to 'exec'")
+return True
+return False
+
+
 W_SyntaxError.typedef = TypeDef(
 'SyntaxError',
 W_Exception.typedef,
diff --git a/pypy/module/exceptions/test/test_exc.py 
b/pypy/module/exceptions/test/test_exc.py
--- a/pypy/module/exceptions/test/test_exc.py
+++ b/pypy/module/exceptions/test/test_exc.py
@@ -375,3 +375,27 @@
 assert e.baz == "baz"
 assert e.args == ("some message",)
 
+# Check the heuristic for print & exec covers significant cases
+# As well as placing some limits on false positives
+def test_former_statements_refer_to_builtins(self):
+keywords = "print", "exec"
+def exec_(s): exec(s)
+# Cases where we want the custom error
+cases = [
+"{} foo",
+"{} {{1:foo}}",
+"if 1: {} foo",
+"if 1: {} {{1:foo}}",
+"if 1:\n{} foo",
+"if 1:\n{} {{1:foo}}",
+]
+for keyword in keywords:
+custom_msg = "call to '{}'".format(keyword)
+for case in cases:
+source = case.format(keyword)
+exc = raises(SyntaxError, exec_, source)
+assert custom_msg in exc.value.msg
+assert exc.value.args[0] == 'invalid syntax'
+source = source.replace("foo", "(foo.)")
+exc = raises(SyntaxError, exec_, source)
+assert custom_msg not in exc.value.msg
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy stdlib-2.7.12: document branches

2016-10-09 Thread pjenvey
Author: Philip Jenvey 
Branch: stdlib-2.7.12
Changeset: r87662:f89d6d4e067b
Date: 2016-10-09 07:42 -0700
http://bitbucket.org/pypy/pypy/changeset/f89d6d4e067b/

Log:document branches

diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -61,3 +61,12 @@
 Change the ``timeit`` module: it now prints the average time and the standard
 deviation over 7 runs by default, instead of the minimum. The minimum is often
 misleading.
+
+.. branch: stdlib-2.7.11
+
+Update stdlib to version 2.7.11
+
+.. branch: vendor/stdlib
+.. branch: stdlib-2.7.12
+
+Update stdlib to version 2.7.12
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: skip the tests, adding the method to the __setstate__ slot works, but pickling will never use that method. removed and test is skipped to not create confusion

2016-10-09 Thread plan_rich
Author: Richard Plangger 
Branch: py3.5
Changeset: r87661:569b72af42d9
Date: 2016-10-09 13:16 +0200
http://bitbucket.org/pypy/pypy/changeset/569b72af42d9/

Log:skip the tests, adding the method to the __setstate__ slot works,
but pickling will never use that method. removed and test is skipped
to not create confusion

diff --git a/lib-python/3/test/test_iter.py b/lib-python/3/test/test_iter.py
--- a/lib-python/3/test/test_iter.py
+++ b/lib-python/3/test/test_iter.py
@@ -938,6 +938,7 @@
 with self.assertRaises(OverflowError):
 next(it)
 
+@cpython_only
 def test_iter_neg_setstate(self):
 it = iter(UnlimitedSequenceClass())
 it.__setstate__(-42)
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
@@ -40,15 +40,6 @@
 def descr_length_hint(self, space):
 return self.getlength(space)
 
-def descr_setstate(self, space, w_state):
-index = space.int_w(w_state)
-if self.w_seq is not space.w_None:
-if index < 0:
-index = 0
-
-self.index = index
-
-
 W_AbstractSeqIterObject.typedef = TypeDef(
 "sequenceiterator",
 __doc__ = '''iter(collection) -> iterator
@@ -61,7 +52,6 @@
 __next__ = interpindirect2app(W_AbstractSeqIterObject.descr_next),
 __reduce__ = interp2app(W_AbstractSeqIterObject.descr_reduce),
 __length_hint__ = interp2app(W_AbstractSeqIterObject.descr_length_hint),
-__setstate__ = interp2app(W_AbstractSeqIterObject.descr_setstate),
 )
 W_AbstractSeqIterObject.typedef.acceptable_as_base_class = False
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: Fix deque mul and implement imul (reubano & plan_rich)

2016-10-09 Thread reubano
Author: Reuben Cummings 
Branch: py3.5
Changeset: r87660:a9547a8c7444
Date: 2016-10-09 13:14 +0300
http://bitbucket.org/pypy/pypy/changeset/a9547a8c7444/

Log:Fix deque mul and implement imul (reubano & plan_rich)

diff --git a/pypy/module/_collections/interp_deque.py 
b/pypy/module/_collections/interp_deque.py
--- a/pypy/module/_collections/interp_deque.py
+++ b/pypy/module/_collections/interp_deque.py
@@ -185,17 +185,26 @@
 return self.space.wrap(self)
 
 def mul(self, w_int):
-copied = self.copy()
-num = self.space.int_w(w_int)
+space = self.space
+copied = W_Deque(space)
+num = space.int_w(w_int)
 
 for _ in range(num):
-copied.extend(copied)
+copied.extend(self)
 
-return self.space.wrap(copied)
+return space.wrap(copied)
 
 
-def imul(self, w_iterable):
-pass
+def imul(self, w_int):
+space = self.space
+copied = self.copy()
+num = space.int_w(w_int)
+
+for _ in range(num - 1):
+self.extend(copied)
+
+return space.wrap(self)
+
 
 def copy(self):
 """ A shallow copy """
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: Move, rename, and add tests (reubano & plan_rich)

2016-10-09 Thread reubano
Author: Reuben Cummings 
Branch: py3.5
Changeset: r87659:27e75ff51d20
Date: 2016-10-09 12:55 +0300
http://bitbucket.org/pypy/pypy/changeset/27e75ff51d20/

Log:Move, rename, and add tests (reubano & plan_rich)

Rename test_deque_add to test_add and move above test_iadd Remove
duplicate test_copy Add test_imul Implement imul

diff --git a/pypy/module/_collections/interp_deque.py 
b/pypy/module/_collections/interp_deque.py
--- a/pypy/module/_collections/interp_deque.py
+++ b/pypy/module/_collections/interp_deque.py
@@ -184,8 +184,15 @@
 self.extend(w_iterable)
 return self.space.wrap(self)
 
-def mul(self, w_iterable):
-pass
+def mul(self, w_int):
+copied = self.copy()
+num = self.space.int_w(w_int)
+
+for _ in range(num):
+copied.extend(copied)
+
+return self.space.wrap(copied)
+
 
 def imul(self, w_iterable):
 pass
diff --git a/pypy/module/_collections/test/test_deque.py 
b/pypy/module/_collections/test/test_deque.py
--- a/pypy/module/_collections/test/test_deque.py
+++ b/pypy/module/_collections/test/test_deque.py
@@ -116,6 +116,12 @@
 d.extend(d)
 assert list(d) == list('abcdabcd')
 
+def test_add(self):
+from _collections import deque
+d1 = deque([1,2,3])
+d2 = deque([3,4,5])
+assert d1 + d2 == deque([1,2,3,3,4,5])
+
 def test_iadd(self):
 from _collections import deque
 d = deque('a')
@@ -318,18 +324,14 @@
 copy = pickle.loads(pickle.dumps(iterator))
 assert list(iterator) == list(copy)
 
-def test_deque_add(self):
-from _collections import deque
-d1 = deque([1,2,3])
-d2 = deque([3,4,5])
-assert d1 + d2 == deque([1,2,3,3,4,5])
-
 def test_queue_mul(self):
 from _collections import deque
 d = deque([1,2,3])
 assert d*3 == deque([1,2,3]*3)
 
-def test_copy(self):
+def test_queue_imul(self):
 from _collections import deque
 d = deque([1,2,3])
-assert d is not d.copy()
+d *= 3
+assert d == deque([1,2,3]*3)
+assert d is not deque([1,2,3]*3)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: test deque's new mul method

2016-10-09 Thread plan_rich
Author: Richard Plangger 
Branch: py3.5
Changeset: r87655:0deaad2bf1c1
Date: 2016-10-09 11:18 +0200
http://bitbucket.org/pypy/pypy/changeset/0deaad2bf1c1/

Log:test deque's new mul method

diff --git a/pypy/module/_collections/test/test_deque.py 
b/pypy/module/_collections/test/test_deque.py
--- a/pypy/module/_collections/test/test_deque.py
+++ b/pypy/module/_collections/test/test_deque.py
@@ -323,3 +323,9 @@
 d1 = deque([1,2,3])
 d2 = deque([3,4,5])
 assert d1 + d2 == deque([1,2,3,3,4,5])
+
+def test_queue_mul(self):
+from _collections import deque
+d = deque([1,2,3])
+assert d*3 == deque([1,2,3]*3)
+
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: remove paramter to W_Deque.copy (reubano, plan_rich)

2016-10-09 Thread plan_rich
Author: Richard Plangger 
Branch: py3.5
Changeset: r87657:ed20d5312f0a
Date: 2016-10-09 11:38 +0200
http://bitbucket.org/pypy/pypy/changeset/ed20d5312f0a/

Log:remove paramter to W_Deque.copy (reubano, plan_rich)

diff --git a/pypy/module/_collections/interp_deque.py 
b/pypy/module/_collections/interp_deque.py
--- a/pypy/module/_collections/interp_deque.py
+++ b/pypy/module/_collections/interp_deque.py
@@ -176,7 +176,7 @@
 self.append(w_obj)
 
 def add(self, w_iterable):
-copied = self.copy(self)
+copied = self.copy()
 copied.extend(w_iterable)
 return self.space.wrap(copied)
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: test deque's and impl deque copy

2016-10-09 Thread plan_rich
Author: Richard Plangger 
Branch: py3.5
Changeset: r87656:08c15132273f
Date: 2016-10-09 11:33 +0200
http://bitbucket.org/pypy/pypy/changeset/08c15132273f/

Log:test deque's and impl deque copy

diff --git a/pypy/module/_collections/interp_deque.py 
b/pypy/module/_collections/interp_deque.py
--- a/pypy/module/_collections/interp_deque.py
+++ b/pypy/module/_collections/interp_deque.py
@@ -184,6 +184,27 @@
 self.extend(w_iterable)
 return self.space.wrap(self)
 
+def mul(self, w_iterable):
+pass
+
+def imul(self, w_iterable):
+pass
+
+def copy(self):
+""" A shallow copy """
+space = self.space
+w_iter = space.iter(w_iterable)
+copy = W_Deque(self.space)
+while True:
+try:
+w_obj = space.next(w_iter)
+except OperationError as e:
+if e.match(space, space.w_StopIteration):
+break
+raise
+copy.appendleft(w_obj)
+return copy
+
 def extendleft(self, w_iterable):
 "Extend the left side of the deque with elements from the iterable"
 # Handle case where id(deque) == id(iterable)
@@ -191,7 +212,6 @@
 if space.is_w(space.wrap(self), w_iterable):
 w_iterable = space.call_function(space.w_list, w_iterable)
 #
-space = self.space
 w_iter = space.iter(w_iterable)
 while True:
 try:
@@ -477,6 +497,7 @@
 remove = interp2app(W_Deque.remove),
 reverse= interp2app(W_Deque.reverse),
 rotate = interp2app(W_Deque.rotate),
+copy   = interp2app(W_Deque.copy),
 __weakref__ = make_weakref_descr(W_Deque),
 __iter__ = interp2app(W_Deque.iter),
 __reversed__ = interp2app(W_Deque.reviter),
@@ -496,6 +517,8 @@
 __delitem__ = interp2app(W_Deque.delitem),
 __copy__ = interp2app(W_Deque.copy),
 __reduce__ = interp2app(W_Deque.reduce),
+__mul__ = interp2app(W_Deque.mul),
+__imul__ = interp2app(W_Deque.imul),
 maxlen = GetSetProperty(W_Deque.get_maxlen),
 )
 
diff --git a/pypy/module/_collections/test/test_deque.py 
b/pypy/module/_collections/test/test_deque.py
--- a/pypy/module/_collections/test/test_deque.py
+++ b/pypy/module/_collections/test/test_deque.py
@@ -328,4 +328,8 @@
 from _collections import deque
 d = deque([1,2,3])
 assert d*3 == deque([1,2,3]*3)
-
+
+def test_copy(self):
+from _collections import deque
+d = deque([1,2,3])
+assert d is not d.copy()
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: Implement W_Deque.add method (reubano & plan_rich)

2016-10-09 Thread reubano
Author: Reuben Cummings 
Branch: py3.5
Changeset: r87654:116c76f74d58
Date: 2016-10-09 12:33 +0300
http://bitbucket.org/pypy/pypy/changeset/116c76f74d58/

Log:Implement W_Deque.add method (reubano & plan_rich)

diff --git a/pypy/module/_collections/interp_deque.py 
b/pypy/module/_collections/interp_deque.py
--- a/pypy/module/_collections/interp_deque.py
+++ b/pypy/module/_collections/interp_deque.py
@@ -175,6 +175,11 @@
 raise
 self.append(w_obj)
 
+def add(self, w_iterable):
+copied = self.copy(self)
+copied.extend(w_iterable)
+return self.space.wrap(copied)
+
 def iadd(self, w_iterable):
 self.extend(w_iterable)
 return self.space.wrap(self)
@@ -484,6 +489,7 @@
 __gt__ = interp2app(W_Deque.gt),
 __ge__ = interp2app(W_Deque.ge),
 __hash__ = None,
+__add__ = interp2app(W_Deque.add),
 __iadd__ = interp2app(W_Deque.iadd),
 __getitem__ = interp2app(W_Deque.getitem),
 __setitem__ = interp2app(W_Deque.setitem),
@@ -536,7 +542,7 @@
 w_self = space.allocate_instance(W_DequeIter, w_subtype)
 if not isinstance(w_deque, W_Deque):
 raise oefmt(space.w_TypeError, "must be collections.deque, not %T", 
w_deque)
-
+
 W_DequeIter.__init__(space.interp_w(W_DequeIter, w_self), w_deque)
 return w_self
 
@@ -592,7 +598,7 @@
 w_self = space.allocate_instance(W_DequeRevIter, w_subtype)
 if not isinstance(w_deque, W_Deque):
 raise oefmt(space.w_TypeError, "must be collections.deque, not %T", 
w_deque)
-
+
 W_DequeRevIter.__init__(space.interp_w(W_DequeRevIter, w_self), w_deque)
 return w_self
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: Add failing deque_add test (reubano & plan_rich)

2016-10-09 Thread reubano
Author: Reuben Cummings 
Branch: py3.5
Changeset: r87653:3ed61f318357
Date: 2016-10-09 12:18 +0300
http://bitbucket.org/pypy/pypy/changeset/3ed61f318357/

Log:Add failing deque_add test (reubano & plan_rich)

diff --git a/pypy/module/_collections/test/test_deque.py 
b/pypy/module/_collections/test/test_deque.py
--- a/pypy/module/_collections/test/test_deque.py
+++ b/pypy/module/_collections/test/test_deque.py
@@ -317,3 +317,9 @@
 iterator = reversed(d)
 copy = pickle.loads(pickle.dumps(iterator))
 assert list(iterator) == list(copy)
+
+def test_deque_add(self):
+from _collections import deque
+d1 = deque([1,2,3])
+d2 = deque([3,4,5])
+assert d1 + d2 == deque([1,2,3,3,4,5])
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: Add setstate method to SeqIterObject (reubano & plan_rich)

2016-10-09 Thread reubano
Author: Reuben Cummings 
Branch: py3.5
Changeset: r87652:1e446f2bd949
Date: 2016-10-09 11:52 +0300
http://bitbucket.org/pypy/pypy/changeset/1e446f2bd949/

Log:Add setstate method to SeqIterObject (reubano & plan_rich)

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
@@ -40,6 +40,15 @@
 def descr_length_hint(self, space):
 return self.getlength(space)
 
+def descr_setstate(self, space, w_state):
+index = space.int_w(w_state)
+if self.w_seq is not space.w_None:
+if index < 0:
+index = 0
+
+self.index = index
+
+
 W_AbstractSeqIterObject.typedef = TypeDef(
 "sequenceiterator",
 __doc__ = '''iter(collection) -> iterator
@@ -52,6 +61,7 @@
 __next__ = interpindirect2app(W_AbstractSeqIterObject.descr_next),
 __reduce__ = interp2app(W_AbstractSeqIterObject.descr_reduce),
 __length_hint__ = interp2app(W_AbstractSeqIterObject.descr_length_hint),
+__setstate__ = interp2app(W_AbstractSeqIterObject.descr_setstate),
 )
 W_AbstractSeqIterObject.typedef.acceptable_as_base_class = False
 
diff --git a/pypy/objspace/std/test/test_iterobject.py 
b/pypy/objspace/std/test/test_iterobject.py
--- a/pypy/objspace/std/test/test_iterobject.py
+++ b/pypy/objspace/std/test/test_iterobject.py
@@ -19,7 +19,7 @@
 w_tuple = self.space.newtuple([w(5), w(3), w(99)])
 w_iter = W_SeqIterObject(w_tuple)
 self.body3(w_iter)
-
+
 def test_iter_builtin(self):
 w = self.space.wrap
 w_tuple = self.space.newtuple([w(5), w(3), w(99)])
@@ -30,7 +30,7 @@
 w_list = self.space.newlist([])
 w_iter = W_SeqIterObject(w_list)
 self.body0(w_iter)
-
+
 def test_emptyiter_builtin(self):
 w_list = self.space.newlist([])
 w_iter = self.space.iter(w_list)
@@ -63,10 +63,20 @@
 iterable = [1,2,3,4]
 raises(TypeError, len, iter(iterable))
 
+def test_list_iter_setstate(self):
+iterable = iter([1,2,3,4])
+assert next(iterable) == 1
+iterable.__setstate__(0)
+assert next(iterable) == 1
+iterable.__setstate__(-100)
+assert next(iterable) == 1
+raises(TypeError, iterable.__setstate__, '0')
+
+
 def test_no_len_on_tuple_iter(self):
 iterable = (1,2,3,4)
 raises(TypeError, len, iter(iterable))
-
+
 def test_no_len_on_deque_iter(self):
 from _collections import deque
 iterable = deque([1,2,3,4])
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit