Commits

Hakan Ardo  committed 662ca39 Merge

hg merge deafult

  • Participants
  • Parent commits 5fa8a8e, 50ae5cf
  • Branches jit-fromstart

Comments (0)

Files changed (12)

File lib-python/modified-2.7.0/test/test_descr.py

 
         for name, runner, meth_impl, ok, env in specials:
             if name == '__length_hint__':
-                if not check_impl_detail():
+                if not test_support.check_impl_detail():
                     continue
 
             class X(Checker):

File pypy/interpreter/baseobjspace.py

                                  self.wrap('read-write buffer expected'))
         return buffer
 
-    def bufferstr_w(self, w_obj):
+    def bufferstr_new_w(self, w_obj):
+        # Implement the "new buffer interface" (new in Python 2.7)
+        # returning an unwrapped string. It doesn't accept unicode
+        # strings
         buffer = self.buffer_w(w_obj)
         return buffer.as_str()
 
+    def bufferstr_w(self, w_obj):
+        # Directly returns an interp-level str.  Note that if w_obj is a
+        # unicode string, this is different from str_w(buffer(w_obj)):
+        # indeed, the latter returns a string with the raw bytes from
+        # the underlying unicode buffer, but bufferstr_w() just converts
+        # the unicode to an ascii string.  This inconsistency is kind of
+        # needed because CPython has the same issue.  (Well, it's
+        # unclear if there is any use at all for getting the bytes in
+        # the unicode buffer.)
+        try:
+            return self.str_w(w_obj)
+        except OperationError, e:
+            if not e.match(self, self.w_TypeError):
+                raise
+            buffer = self.buffer_w(w_obj)
+            return buffer.as_str()
+
     def str_or_None_w(self, w_obj):
         if self.is_w(w_obj, self.w_None):
             return None

File pypy/jit/metainterp/optimizeopt/optimizer.py

File contents unchanged.

File pypy/jit/metainterp/optimizeopt/unroll.py

File contents unchanged.

File pypy/module/_multiprocessing/interp_semaphore.py

     TIMEVALP       = rffi.CArrayPtr(TIMEVAL)
     TIMESPECP      = rffi.CArrayPtr(TIMESPEC)
     SEM_T          = rffi.COpaquePtr('sem_t', compilation_info=eci)
-    SEM_FAILED     = rffi.cast(SEM_T, config['SEM_FAILED'])
+    SEM_FAILED     = config['SEM_FAILED'] # rffi.cast(SEM_T, config['SEM_FAILED'])
     SEM_VALUE_MAX  = config['SEM_VALUE_MAX']
     SEM_TIMED_WAIT = config['SEM_TIMED_WAIT']
     HAVE_BROKEN_SEM_GETVALUE = config['SEM_GETVALUE']
 
     def sem_open(name, oflag, mode, value):
         res = _sem_open(name, oflag, mode, value)
-        if res == SEM_FAILED:
+        if res == rffi.cast(SEM_T, SEM_FAILED):
             raise OSError(rposix.get_errno(), "sem_open failed")
         return res
 
             time.sleep(0.001)
 
             # if this is main thread let KeyboardInterrupt be raised
-            _check_signals(self.space)
+            _check_signals(space)
 
             # recalculate timeout
             if msecs != rwin32.INFINITE:

File pypy/module/itertools/interp_itertools.py

 
 class W_Count(Wrappable):
 
-    def __init__(self, space, firstval, step):
+    def __init__(self, space, w_firstval, w_step):
         self.space = space
-        self.c = firstval
-        self.step = step
+        self.w_c = w_firstval
+        self.w_step = w_step
 
     def iter_w(self):
         return self.space.wrap(self)
 
     def next_w(self):
-        c = self.c
-        try:
-            self.c = ovfcheck(self.c + self.step)
-        except OverflowError:
-            raise OperationError(self.space.w_OverflowError,
-                    self.space.wrap("cannot count beyond sys.maxint"))
-
-        return self.space.wrap(c)
+        w_c = self.w_c
+        self.w_c = self.space.add(w_c, self.w_step)
+        return w_c
 
     def repr_w(self):
-        if self.step == 1:
-            s = 'count(%d)' % (self.c,)
+        space = self.space
+        c = space.str_w(space.repr(self.w_c))
+        if space.eq_w(self.w_step, space.wrap(1)):
+            s = 'count(%s)' % (c,)
         else:
-            s = 'count(%d, %d)' % (self.c, self.step)
+            step = space.str_w(space.repr(self.w_step))
+            s = 'count(%s, %s)' % (c, step)
         return self.space.wrap(s)
-        
 
 
-def W_Count___new__(space, w_subtype, start=0, step=1):
-    return space.wrap(W_Count(space, start, step))
+@unwrap_spec(ObjSpace, W_Root, W_Root, W_Root)
+def W_Count___new__(space, w_subtype, w_start=0, w_step=1):
+    r = space.allocate_instance(W_Count, w_subtype)
+    r.__init__(space, w_start, w_step)
+    return space.wrap(r)
 
 W_Count.typedef = TypeDef(
         'count',
-        __new__ = interp2app(W_Count___new__, unwrap_spec=[ObjSpace, W_Root, int, int]),
+        __new__ = interp2app(W_Count___new__),
         __iter__ = interp2app(W_Count.iter_w, unwrap_spec=['self']),
         next = interp2app(W_Count.next_w, unwrap_spec=['self']),
         __repr__ = interp2app(W_Count.repr_w, unwrap_spec=['self']),
         return self.space.wrap(s)
 
 def W_Repeat___new__(space, w_subtype, w_object, w_times=None):
-    return space.wrap(W_Repeat(space, w_object, w_times))
+    r = space.allocate_instance(W_Repeat, w_subtype)
+    r.__init__(space, w_object, w_times)
+    return space.wrap(r)
 
 W_Repeat.typedef = TypeDef(
         'repeat',
         return w_obj
 
 def W_TakeWhile___new__(space, w_subtype, w_predicate, w_iterable):
-    return space.wrap(W_TakeWhile(space, w_predicate, w_iterable))
+    r = space.allocate_instance(W_TakeWhile, w_subtype)
+    r.__init__(space, w_predicate, w_iterable)
+    return space.wrap(r)
 
 
 W_TakeWhile.typedef = TypeDef(
         return w_obj
 
 def W_DropWhile___new__(space, w_subtype, w_predicate, w_iterable):
-    return space.wrap(W_DropWhile(space, w_predicate, w_iterable))
+    r = space.allocate_instance(W_DropWhile, w_subtype)
+    r.__init__(space, w_predicate, w_iterable)
+    return space.wrap(r)
 
 
 W_DropWhile.typedef = TypeDef(
     reverse = False
 
 def W_IFilter___new__(space, w_subtype, w_predicate, w_iterable):
-    return space.wrap(W_IFilter(space, w_predicate, w_iterable))
+    r = space.allocate_instance(W_IFilter, w_subtype)
+    r.__init__(space, w_predicate, w_iterable)
+    return space.wrap(r)
 
 W_IFilter.typedef = TypeDef(
         'ifilter',
     reverse = True
 
 def W_IFilterFalse___new__(space, w_subtype, w_predicate, w_iterable):
-    return space.wrap(W_IFilterFalse(space, w_predicate, w_iterable))
+    r = space.allocate_instance(W_IFilterFalse, w_subtype)
+    r.__init__(space, w_predicate, w_iterable)
+    return space.wrap(r)
 
 W_IFilterFalse.typedef = TypeDef(
         'ifilterfalse',
                 return w_obj
 
 def W_ISlice___new__(space, w_subtype, w_iterable, w_startstop, args_w):
-    return space.wrap(W_ISlice(space, w_iterable, w_startstop, args_w))
+    r = space.allocate_instance(W_ISlice, w_subtype)
+    r.__init__(space, w_iterable, w_startstop, args_w)
+    return space.wrap(r)
 
 W_ISlice.typedef = TypeDef(
         'islice',
                 pass # loop back to the start of _handle_error(e)
 
 def W_Chain___new__(space, w_subtype, args_w):
+    r = space.allocate_instance(W_Chain, w_subtype)
     w_args = space.newtuple(args_w)
-    return space.wrap(W_Chain(space, space.iter(w_args)))
+    r.__init__(space, space.iter(w_args))
+    return space.wrap(r)
 
 def chain_from_iterable(space, w_cls, w_arg):
     """chain.from_iterable(iterable) --> chain object
 
     Alternate chain() contructor taking a single iterable argument
     that evaluates lazily."""
-    return space.wrap(W_Chain(space, space.iter(w_arg)))
+    r = space.allocate_instance(W_Chain, w_cls)
+    r.__init__(space, space.iter(w_arg))
+    return space.wrap(r)
 
 W_Chain.typedef = TypeDef(
         'chain',
     if len(args_w) == 0:
         raise OperationError(space.w_TypeError,
                   space.wrap("imap() must have at least two arguments"))
-    return space.wrap(W_IMap(space, w_fun, args_w))
+    r = space.allocate_instance(W_IMap, w_subtype)
+    r.__init__(space, w_fun, args_w)
+    return space.wrap(r)
 
 W_IMap.typedef = TypeDef(
         'imap',
         return W_IMap.next_w(self)
 
 def W_IZip___new__(space, w_subtype, args_w):
-    return space.wrap(W_IZip(space, space.w_None, args_w))
+    r = space.allocate_instance(W_IZip, w_subtype)
+    r.__init__(space, space.w_None, args_w)
+    return space.wrap(r)
 
 W_IZip.typedef = TypeDef(
         'izip',
 
 @unwrap_spec(ObjSpace, W_Root, Arguments)
 def W_IZipLongest___new__(space, w_subtype, __args__):
-    kwds = __args__.keywords
+    arguments_w, kwds_w = __args__.unpack()
     w_fillvalue = space.w_None
-    if kwds:
-        if kwds[0] == "fillvalue" and len(kwds) == 1:
-            w_fillvalue = __args__.keywords_w[0]
-        else:
+    if kwds_w:
+        if "fillvalue" in kwds_w:
+            w_fillvalue = kwds_w["fillvalue"]
+            del kwds_w["fillvalue"]
+        if kwds_w:
             raise OperationError(space.w_TypeError, space.wrap(
-                "izip_longest() got unexpected keyword argument"))
+                "izip_longest() got unexpected keyword argument(s)"))
 
-    self = W_IZipLongest(space, space.w_None, __args__.arguments_w)
+    self = space.allocate_instance(W_IZipLongest, w_subtype)
+    self.__init__(space, space.w_None, arguments_w)
     self.w_fillvalue = w_fillvalue
     self.active = len(self.iterators_w)
 
         return w_obj
 
 def W_Cycle___new__(space, w_subtype, w_iterable):
-    return space.wrap(W_Cycle(space, w_iterable))
+    r = space.allocate_instance(W_Cycle, w_subtype)
+    r.__init__(space, w_iterable)
+    return space.wrap(r)
 
 W_Cycle.typedef = TypeDef(
         'cycle',
         return self.space.call(self.w_fun, w_obj)
 
 def W_StarMap___new__(space, w_subtype, w_fun, w_iterable):
-    return space.wrap(W_StarMap(space, w_fun, w_iterable))
+    r = space.allocate_instance(W_StarMap, w_subtype)
+    r.__init__(space, w_fun, w_iterable)
+    return space.wrap(r)
 
 W_StarMap.typedef = TypeDef(
         'starmap',
                     raise StopIteration
 
 def W_GroupBy___new__(space, w_subtype, w_iterable, w_key=None):
-    return space.wrap(W_GroupBy(space, w_iterable, w_key))
+    r = space.allocate_instance(W_GroupBy, w_subtype)
+    r.__init__(space, w_iterable, w_key)
+    return space.wrap(r)
 
 W_GroupBy.typedef = TypeDef(
         'groupby',
 
 
 def W_Compress__new__(space, w_subtype, w_data, w_selectors):
-    return space.wrap(W_Compress(space, w_data, w_selectors))
+    r = space.allocate_instance(W_Compress, w_subtype)
+    r.__init__(space, w_data, w_selectors)
+    return space.wrap(r)
 
 W_Compress.typedef = TypeDef(
     'compress',
 
     def __init__(self, space, args_w, w_repeat):
         self.space = space
-        self.gears_w = [x for x in args_w] * space.int_w(w_repeat)
+        self.gears_w = args_w * space.int_w(w_repeat)
         self.num_gears = len(self.gears_w)
         # initialization of indicies to loop over
         self.indicies = [(0, space.int_w(space.len(w_gear)))
         return self.space.newtuple(l)
 
 
-def W_Product__new__(space, args_w):
-    star_args_w, kw_args_w = args_w.unpack()
-    if len(kw_args_w) > 1:
-        raise OperationError(space.w_TypeError,
-                             space.wrap("product() takes at most 1 argument (%d given)" %
-                             len(kw_args_w)))
-    w_repeat = kw_args_w.get('repeat', space.wrap(1))
-    return space.wrap(W_Product(space, star_args_w[1:], w_repeat))
+@unwrap_spec(ObjSpace, W_Root, Arguments)
+def W_Product__new__(space, w_subtype, __args__):
+    arguments_w, kwds_w = __args__.unpack()
+    w_repeat = space.wrap(1)
+    if kwds_w:
+        if 'repeat' in kwds_w:
+            w_repeat = kwds_w['repeat']
+            del kwds_w['repeat']
+        if kwds_w:
+            raise OperationError(space.w_TypeError, space.wrap(
+                "product() got unexpected keyword argument(s)"))
+
+    r = space.allocate_instance(W_Product, w_subtype)
+    r.__init__(space, arguments_w, w_repeat)
+    return space.wrap(r)
 
 W_Product.typedef = TypeDef(
     'product',
-    __new__ = interp2app(W_Product__new__,
-                         unwrap_spec=[ObjSpace, Arguments]),
+    __new__ = interp2app(W_Product__new__),
     __iter__ = interp2app(W_Product.iter_w, unwrap_spec=['self']),
     next = interp2app(W_Product.next_w, unwrap_spec=['self']),
     __doc__ = """
             space.wrap("r must be non-negative")
         )
     indices = range(len(pool_w))
-    return W_Combinations(space, pool_w, indices, r)
+    res = space.allocate_instance(W_Combinations, w_subtype)
+    res.__init__(space, pool_w, indices, r)
+    return space.wrap(res)
 
 W_Combinations.typedef = TypeDef("combinations",
     __new__ = interp2app(W_Combinations__new__),
     __iter__ = interp2app(W_Combinations.descr__iter__),
     next = interp2app(W_Combinations.descr_next),
+    __doc__ = """\
+combinations(iterable, r) --> combinations object
+
+Return successive r-length combinations of elements in the iterable.
+
+combinations(range(4), 3) --> (0,1,2), (0,1,3), (0,2,3), (1,2,3)""",
 )
 
 class W_CombinationsWithReplacement(W_Combinations):
 
 @unwrap_spec(ObjSpace, W_Root, W_Root, int)
 def W_CombinationsWithReplacement__new__(space, w_subtype, w_iterable, r):
-        pool_w = space.fixedview(w_iterable)
-        if r < 0:
-            raise OperationError(space.w_ValueError,
-                space.wrap("r must be non-negative")
-            )
-        indices = [0] * len(pool_w)
-        return W_CombinationsWithReplacement(space, pool_w, indices, r)
+    pool_w = space.fixedview(w_iterable)
+    if r < 0:
+        raise OperationError(space.w_ValueError,
+                             space.wrap("r must be non-negative"))
+    indices = [0] * len(pool_w)
+    res = space.allocate_instance(W_CombinationsWithReplacement, w_subtype)
+    res.__init__(space, pool_w, indices, r)
+    return space.wrap(res)
 
 W_CombinationsWithReplacement.typedef = TypeDef("combinations_with_replacement",
     __new__ = interp2app(W_CombinationsWithReplacement__new__),
     __iter__ = interp2app(W_CombinationsWithReplacement.descr__iter__),
     next = interp2app(W_CombinationsWithReplacement.descr_next),
+    __doc__ = """\
+combinations_with_replacement(iterable, r) --> combinations_with_replacement object
+
+Return successive r-length combinations of elements in the iterable
+allowing individual elements to have successive repeats.
+combinations_with_replacement('ABC', 2) --> AA AB AC BB BC CC""",
 )

File pypy/module/itertools/test/test_itertools.py

+import py
 from pypy.conftest import gettestobjspace
 
 class AppTestItertools: 
     def setup_class(cls):
         cls.space = gettestobjspace(usemodules=['itertools'])
 
-    def test_compress(self):
-        import itertools
-
-        it = itertools.compress(['a', 'b', 'c'], [0, 1, 0])
-
-        assert list(it) == ['b']
-
-    def test_compress_diff_len(self):
-        import itertools
-
-        it = itertools.compress(['a'], [])
-        raises(StopIteration, it.next)
-
     def test_count(self):
         import itertools
 
         for x in range(10):
             assert it.next() == x + 3
 
-    def test_count_overflow(self):
-        import itertools, sys
-
-        # this checks for exact implementation details... that's 2.5 behavior
-        it = itertools.count(sys.maxint - 1)
-        assert it.next() == sys.maxint - 1
-        raises(OverflowError, it.next)
-        raises(OverflowError, it.next)
-
-        raises(OverflowError, itertools.count, sys.maxint + 1)
-
     def test_count_repr(self):
         import itertools
 
         it.next()
         assert repr(it) == 'count(124)'
 
-    def test_count_kwargs(self):
-        import itertools
-
-        it = itertools.count(start=2, step=3)
-        assert it.next() == 2
-        assert it.next() == 5
-        assert it.next() == 8
-
     def test_repeat(self):
         import itertools
 
         raises(StopIteration, it.next)
         raises(StopIteration, it.next)
 
-        assert list(itertools.repeat(object='a', times=3)) == ['a', 'a', 'a']
-
     def test_repeat_overflow(self):
         import itertools
         import sys
     def test_islice_overflow(self):
         import itertools
         import sys
-        if '__pypy__' not in sys.builtin_module_names:
-            skip("CPython 2.5 gives a strange ValueError")
-        raises(OverflowError, itertools.islice, [], sys.maxint + 1)
+        raises((OverflowError, ValueError),    # ValueError on top of CPython
+               itertools.islice, [], sys.maxint + 1)
 
     def test_islice_wrongargs(self):
         import itertools
         assert it.next() == 1
         raises(StopIteration, it.next)
 
-    def test_chain_fromiterable(self):
-        import itertools
-        l = [[1, 2, 3], [4], [5, 6]]
-        it = itertools.chain.from_iterable(l)
-        assert list(it) == sum(l, [])
-
     def test_imap(self):
         import itertools
 
         ref = weakref.ref(b)
         assert ref() is b
 
+
+class AppTestItertools26:
+    def setup_class(cls):
+        cls.space = gettestobjspace(usemodules=['itertools'])
+        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.maxint - 1)
+        assert it.next() == sys.maxint - 1
+        assert it.next() == sys.maxint
+        assert it.next() == sys.maxint + 1
+        it = itertools.count(sys.maxint + 1)
+        assert it.next() == sys.maxint + 1
+        assert it.next() == sys.maxint + 2
+        it = itertools.count(-sys.maxint-2)
+        assert it.next() == -sys.maxint - 2
+        assert it.next() == -sys.maxint - 1
+        assert it.next() == -sys.maxint
+        assert it.next() == -sys.maxint + 1
+        it = itertools.count(0, sys.maxint)
+        assert it.next() == sys.maxint * 0
+        assert it.next() == sys.maxint * 1
+        assert it.next() == sys.maxint * 2
+        it = itertools.count(0, sys.maxint + 1)
+        assert it.next() == (sys.maxint + 1) * 0
+        assert it.next() == (sys.maxint + 1) * 1
+        assert it.next() == (sys.maxint + 1) * 2
+
+    def test_chain_fromiterable(self):
+        import itertools
+        l = [[1, 2, 3], [4], [5, 6]]
+        it = itertools.chain.from_iterable(l)
+        assert list(it) == sum(l, [])
+
+    def test_combinations(self):
+        from itertools import combinations
+
+        raises(TypeError, combinations, "abc")
+        raises(TypeError, combinations, "abc", 2, 1)
+        raises(TypeError, combinations, None)
+        raises(ValueError, combinations, "abc", -2)
+        assert list(combinations(range(4), 3)) == [(0, 1, 2), (0, 1, 3), (0, 2, 3), (1, 2, 3)]
+
     def test_iziplongest(self):
         from itertools import izip_longest, islice, count
         for args in [
             return result
         assert run(r1, r2) ==  [(1,2), (1,2), (1,2), (0,2)]
 
-        # Formerly, the RuntimeError would be lost
-        # and StopIteration would stop as expected
-        r1 = Repeater(1, 3, RuntimeError)
-        r2 = Repeater(2, 4, StopIteration)
-        it = itertools.izip_longest(r1, r2, fillvalue=0)
-        assert it.next() == (1, 2)
-        assert it.next() == (1, 2)
-        assert it.next()== (1, 2)
-        raises(RuntimeError, it.next)
-
     def test_product(self):
         from itertools import product
         l = [1, 2]
                (2, 'b', 2, 'b')]
         assert list(prodlist) == ans
 
+        raises(TypeError, product, [], foobar=3)
+
     def test_product_diff_sizes(self):
         from itertools import product
         l = [1, 2]
         assert prod.next() == ()
         raises (StopIteration, prod.next)
 
-    def test_combinations(self):
+
+class AppTestItertools27:
+    def setup_class(cls):
+        cls.space = gettestobjspace(usemodules=['itertools'])
+        if cls.space.is_true(cls.space.appexec([], """():
+            import sys; return sys.version_info < (2, 7)
+            """)):
+            py.test.skip("Requires Python 2.7")
+
+    def test_compress(self):
+        import itertools
+        it = itertools.compress(['a', 'b', 'c'], [0, 1, 0])
+        assert list(it) == ['b']
+
+    def test_compress_diff_len(self):
+        import itertools
+        it = itertools.compress(['a'], [])
+        raises(StopIteration, it.next)
+
+    def test_count_kwargs(self):
+        import itertools
+        it = itertools.count(start=2, step=3)
+        assert it.next() == 2
+        assert it.next() == 5
+        assert it.next() == 8
+
+    def test_repeat_kwargs(self):
+        import itertools
+        assert list(itertools.repeat(object='a', times=3)) == ['a', 'a', 'a']
+
+    def test_combinations_overflow(self):
         from itertools import combinations
-
-        raises(TypeError, combinations, "abc")
-        raises(TypeError, combinations, "abc", 2, 1)
-        raises(TypeError, combinations, None)
-        raises(ValueError, combinations, "abc", -2)
         assert list(combinations("abc", 32)) == []
-        assert list(combinations(range(4), 3)) == [(0, 1, 2), (0, 1, 3), (0, 2, 3), (1, 2, 3)]
 
     def test_combinations_with_replacement(self):
         from itertools import combinations_with_replacement
-
         raises(TypeError, combinations_with_replacement, "abc")
         raises(TypeError, combinations_with_replacement, "abc", 2, 1)
         raises(TypeError, combinations_with_replacement, None)
         raises(ValueError, combinations_with_replacement, "abc", -2)
         assert list(combinations_with_replacement("ABC", 2)) == [("A", "A"), ("A", 'B'), ("A", "C"), ("B", "B"), ("B", "C"), ("C", "C")]
+
+    def test_izip_longest3(self):
+        import itertools
+        class Repeater(object):
+            # this class is similar to itertools.repeat
+            def __init__(self, o, t, e):
+                self.o = o
+                self.t = int(t)
+                self.e = e
+            def __iter__(self): # its iterator is itself
+                return self
+            def next(self):
+                if self.t > 0:
+                    self.t -= 1
+                    return self.o
+                else:
+                    raise self.e
+
+        # Formerly, the RuntimeError would be lost
+        # and StopIteration would stop as expected
+        r1 = Repeater(1, 3, RuntimeError)
+        r2 = Repeater(2, 4, StopIteration)
+        it = itertools.izip_longest(r1, r2, fillvalue=0)
+        assert it.next() == (1, 2)
+        assert it.next() == (1, 2)
+        assert it.next()== (1, 2)
+        raises(RuntimeError, it.next)
+
+    def test_subclassing(self):
+        import itertools
+        class A(itertools.count): pass
+        assert type(A(5)) is A
+        class A(itertools.repeat): pass
+        assert type(A('foo')) is A
+        class A(itertools.takewhile): pass
+        assert type(A(lambda x: True, [])) is A
+        class A(itertools.dropwhile): pass
+        assert type(A(lambda x: True, [])) is A
+        class A(itertools.ifilter): pass
+        assert type(A(lambda x: True, [])) is A
+        class A(itertools.ifilterfalse): pass
+        assert type(A(lambda x: True, [])) is A
+        class A(itertools.islice): pass
+        assert type(A([], 0)) is A
+        class A(itertools.chain): pass
+        assert type(A([], [])) is A
+        assert type(A.from_iterable([])) is A
+        class A(itertools.imap): pass
+        assert type(A(lambda: 5, [])) is A
+        class A(itertools.izip): pass
+        assert type(A([], [])) is A
+        class A(itertools.izip_longest): pass
+        assert type(A([], [])) is A
+        class A(itertools.cycle): pass
+        assert type(A([])) is A
+        class A(itertools.starmap): pass
+        assert type(A(lambda: 5, [])) is A
+        class A(itertools.groupby): pass
+        assert type(A([], lambda: 5)) is A
+        class A(itertools.compress): pass
+        assert type(A('', [])) is A
+        class A(itertools.product): pass
+        assert type(A('', '')) is A
+        class A(itertools.combinations): pass
+        assert type(A('', 0)) is A
+        class A(itertools.combinations_with_replacement): pass
+        assert type(A('', 0)) is A

File pypy/objspace/flow/flowcontext.py

     def call_contextmanager_exit_function(self, w_func, w_typ, w_val, w_tb):
         if w_typ is not self.space.w_None:
             # The annotator won't allow to merge exception types with None.
-            # Replace it with an object which will break translation when used
-            # (except maybe with 'exc_typ is None')
-            w_typ = self.space.w_None
+            # Replace it with the exception value...
+            w_typ = w_val
         self.space.call_function(w_func, w_typ, w_val, w_tb)
         # Return None so that the flow space statically knows that we didn't
         # swallow the exception

File pypy/objspace/std/bytearrayobject.py

 
 def contains__Bytearray_ANY(space, w_bytearray, w_sub):
     # XXX slow - copies, needs rewriting
-    w_str = space.wrap(space.bufferstr_w(w_sub))
+    w_str = space.wrap(space.bufferstr_new_w(w_sub))
     w_str2 = str__Bytearray(space, w_bytearray)
     return stringobject.contains__String_String(space, w_str2, w_str)
 
 
 def add__Bytearray_ANY(space, w_bytearray1, w_other):
     data1 = w_bytearray1.data
-    data2 = [c for c in space.bufferstr_w(w_other)]
+    data2 = [c for c in space.bufferstr_new_w(w_other)]
     return W_BytearrayObject(data1 + data2)
 
 def add__String_Bytearray(space, w_str, w_bytearray):
     return space.wrap(count)
 
 def str_count__Bytearray_ANY_ANY_ANY(space, w_bytearray, w_char, w_start, w_stop):
-    w_char = space.wrap(space.bufferstr_w(w_char))
+    w_char = space.wrap(space.bufferstr_new_w(w_char))
     w_str = str__Bytearray(space, w_bytearray)
     return stringobject.str_count__String_String_ANY_ANY(space, w_str, w_char,
                                                          w_start, w_stop)
 
 def str_index__Bytearray_ANY_ANY_ANY(space, w_bytearray, w_char, w_start, w_stop):
-    w_char = space.wrap(space.bufferstr_w(w_char))
+    w_char = space.wrap(space.bufferstr_new_w(w_char))
     w_str = str__Bytearray(space, w_bytearray)
     return stringobject.str_index__String_String_ANY_ANY(space, w_str, w_char,
                                                          w_start, w_stop)
 
 def str_rindex__Bytearray_ANY_ANY_ANY(space, w_bytearray, w_char, w_start, w_stop):
-    w_char = space.wrap(space.bufferstr_w(w_char))
+    w_char = space.wrap(space.bufferstr_new_w(w_char))
     w_str = str__Bytearray(space, w_bytearray)
     return stringobject.str_rindex__String_String_ANY_ANY(space, w_str, w_char,
                                                          w_start, w_stop)
 
 def str_find__Bytearray_ANY_ANY_ANY(space, w_bytearray, w_char, w_start, w_stop):
-    w_char = space.wrap(space.bufferstr_w(w_char))
+    w_char = space.wrap(space.bufferstr_new_w(w_char))
     w_str = str__Bytearray(space, w_bytearray)
     return stringobject.str_find__String_String_ANY_ANY(space, w_str, w_char,
                                                          w_start, w_stop)
 
 def str_rfind__Bytearray_ANY_ANY_ANY(space, w_bytearray, w_char, w_start, w_stop):
-    w_char = space.wrap(space.bufferstr_w(w_char))
+    w_char = space.wrap(space.bufferstr_new_w(w_char))
     w_str = str__Bytearray(space, w_bytearray)
     return stringobject.str_rfind__String_String_ANY_ANY(space, w_str, w_char,
                                                          w_start, w_stop)
 
 def str_startswith__Bytearray_ANY_ANY_ANY(space, w_bytearray, w_prefix, w_start, w_stop):
-    w_prefix = space.wrap(space.bufferstr_w(w_prefix))
+    w_prefix = space.wrap(space.bufferstr_new_w(w_prefix))
     w_str = str__Bytearray(space, w_bytearray)
     return stringobject.str_startswith__String_String_ANY_ANY(space, w_str, w_prefix,
                                                               w_start, w_stop)
 
 def str_startswith__Bytearray_Tuple_ANY_ANY(space, w_bytearray, w_prefix, w_start, w_stop):
     w_str = str__Bytearray(space, w_bytearray)
-    w_prefix = space.newtuple([space.wrap(space.bufferstr_w(w_entry)) for w_entry in
+    w_prefix = space.newtuple([space.wrap(space.bufferstr_new_w(w_entry)) for w_entry in
                                space.unpackiterable(w_prefix)])
     return stringobject.str_startswith__String_Tuple_ANY_ANY(space, w_str, w_prefix,
                                                               w_start, w_stop)
 
 def str_endswith__Bytearray_ANY_ANY_ANY(space, w_bytearray, w_suffix, w_start, w_stop):
-    w_suffix = space.wrap(space.bufferstr_w(w_suffix))
+    w_suffix = space.wrap(space.bufferstr_new_w(w_suffix))
     w_str = str__Bytearray(space, w_bytearray)
     return stringobject.str_endswith__String_String_ANY_ANY(space, w_str, w_suffix,
                                                               w_start, w_stop)
 
 def str_endswith__Bytearray_Tuple_ANY_ANY(space, w_bytearray, w_suffix, w_start, w_stop):
     w_str = str__Bytearray(space, w_bytearray)
-    w_suffix = space.newtuple([space.wrap(space.bufferstr_w(w_entry)) for w_entry in
+    w_suffix = space.newtuple([space.wrap(space.bufferstr_new_w(w_entry)) for w_entry in
                                space.unpackiterable(w_suffix)])
     return stringobject.str_endswith__String_Tuple_ANY_ANY(space, w_str, w_suffix,
                                                               w_start, w_stop)
 
         if data and i != 0:
             newdata.extend(data)
-        newdata.extend([c for c in space.bufferstr_w(w_s)])
+        newdata.extend([c for c in space.bufferstr_new_w(w_s)])
     return W_BytearrayObject(newdata)
 
 def str_decode__Bytearray_ANY_ANY(space, w_bytearray, w_encoding, w_errors):
     return _strip(space, w_bytearray, _space_chars, 1, 1)
 
 def bytearray_strip__Bytearray_ANY(space, w_bytearray, w_chars):
-    return _strip(space, w_bytearray, space.bufferstr_w(w_chars), 1, 1)
+    return _strip(space, w_bytearray, space.bufferstr_new_w(w_chars), 1, 1)
 
 def bytearray_lstrip__Bytearray_None(space, w_bytearray, w_chars):
     return _strip(space, w_bytearray, _space_chars, 1, 0)
 
 def bytearray_lstrip__Bytearray_ANY(space, w_bytearray, w_chars):
-    return _strip(space, w_bytearray, space.bufferstr_w(w_chars), 1, 0)
+    return _strip(space, w_bytearray, space.bufferstr_new_w(w_chars), 1, 0)
 
 def bytearray_rstrip__Bytearray_None(space, w_bytearray, w_chars):
     return _strip(space, w_bytearray, _space_chars, 0, 1)
 
 def bytearray_rstrip__Bytearray_ANY(space, w_bytearray, w_chars):
-    return _strip(space, w_bytearray, space.bufferstr_w(w_chars), 0, 1)
+    return _strip(space, w_bytearray, space.bufferstr_new_w(w_chars), 0, 1)
 
 # These methods could just delegate to the string implementation,
 # but they have to return a bytearray.
 def str_split__Bytearray_ANY_ANY(space, w_bytearray, w_by, w_maxsplit=-1):
     w_str = str__Bytearray(space, w_bytearray)
     if not space.is_w(w_by, space.w_None):
-        w_by = space.wrap(space.bufferstr_w(w_by))
+        w_by = space.wrap(space.bufferstr_new_w(w_by))
     w_list = space.call_method(w_str, "split", w_by, w_maxsplit)
     list_w = space.listview(w_list)
     for i in range(len(list_w)):
 def str_rsplit__Bytearray_ANY_ANY(space, w_bytearray, w_by, w_maxsplit=-1):
     w_str = str__Bytearray(space, w_bytearray)
     if not space.is_w(w_by, space.w_None):
-        w_by = space.wrap(space.bufferstr_w(w_by))
+        w_by = space.wrap(space.bufferstr_new_w(w_by))
     w_list = space.call_method(w_str, "rsplit", w_by, w_maxsplit)
     list_w = space.listview(w_list)
     for i in range(len(list_w)):
 
 def str_partition__Bytearray_ANY(space, w_bytearray, w_sub):
     w_str = str__Bytearray(space, w_bytearray)
-    w_sub = space.wrap(space.bufferstr_w(w_sub))
+    w_sub = space.wrap(space.bufferstr_new_w(w_sub))
     w_tuple = stringobject.str_partition__String_String(space, w_str, w_sub)
     w_a, w_b, w_c = space.fixedview(w_tuple, 3)
     return space.newtuple([
 
 def str_rpartition__Bytearray_ANY(space, w_bytearray, w_sub):
     w_str = str__Bytearray(space, w_bytearray)
-    w_sub = space.wrap(space.bufferstr_w(w_sub))
+    w_sub = space.wrap(space.bufferstr_new_w(w_sub))
     w_tuple = stringobject.str_rpartition__String_String(space, w_str, w_sub)
     w_a, w_b, w_c = space.fixedview(w_tuple, 3)
     return space.newtuple([

File pypy/objspace/std/bytearraytype.py

 def makebytearraydata_w(space, w_source):
     # String-like argument
     try:
-        string = space.bufferstr_w(w_source)
+        string = space.bufferstr_new_w(w_source)
     except OperationError, e:
         if not e.match(space, space.w_TypeError):
             raise

File pypy/objspace/std/complextype.py

     if s[i] == '(' and s[slen-1] == ')':
         i += 1
         slen -= 1
+        # ignore whitespace after bracket
+        while i < slen and s[i] == ' ':
+            i += 1
 
     # extract first number
     realstart = i

File pypy/objspace/std/test/test_complexobject.py

         test_cparse('.e+5', '.e+5', '0.0')
         test_cparse('(1+2j)', '1', '2')
         test_cparse('(1-6j)', '1', '-6')
+        test_cparse(' ( +3.14-6J )','+3.14','-6')
 
     def test_unpackcomplex(self):
         space = self.space
         h.assertAlmostEqual(complex(),  0)
         h.assertAlmostEqual(complex("-1"), -1)
         h.assertAlmostEqual(complex("+1"), +1)
+        h.assertAlmostEqual(complex(" ( +3.14-6J )"), 3.14-6j)
 
         class complex2(complex): pass
         h.assertAlmostEqual(complex(complex2(1+1j)), 1+1j)
         x.foo = 42
         assert x.foo == 42
         assert type(complex(x)) == complex
-    
+
     def test_infinity(self):
         inf = 1e200*1e200
         assert complex("1"*500) == complex(inf)
         assert complex("-inf") == complex(-inf)
-        
+
     def test_repr(self):
         assert repr(1+6j) == '(1+6j)'
         assert repr(1-6j) == '(1-6j)'