1. Pypy
  2. Untitled project
  3. pypy

Commits

Manuel Jacob  committed fe46e12 Merge

hg merge default

  • Participants
  • Parent commits a8ceea5, 52103b6
  • Branches refactor-str-types

Comments (0)

Files changed (14)

File lib-python/2.7/uuid.py

View file
  • Ignore whitespace
         overriding the given 'hex', 'bytes', 'bytes_le', 'fields', or 'int'.
         """
 
-        if [hex, bytes, bytes_le, fields, int].count(None) != 4:
-            raise TypeError('need one of hex, bytes, bytes_le, fields, or int')
+        if (
+            ((hex is not None) + (bytes is not None) + (bytes_le is not None) +
+             (fields is not None) + (int is not None)) != 1
+        ):
+            raise TypeError('need exactly one of hex, bytes, bytes_le, fields,'
+                            ' or int')
         if hex is not None:
             hex = hex.replace('urn:', '').replace('uuid:', '')
             hex = hex.strip('{}').replace('-', '')

File pypy/doc/whatsnew-head.rst

View file
  • Ignore whitespace
 .. branch: reflex-support
 .. branch: numpypy-inplace-op
 .. branch: rewritten-loop-logging
+
+.. branch: nobold-backtrace
+Work on improving UnionError messages and stack trace displays.
+
+.. branch: improve-errors-again
+More improvements and refactorings of error messages.
+
+.. branch: improve-errors-again2
+Unbreak tests in rlib.

File pypy/module/micronumpy/loop.py

View file
  • Ignore whitespace
 
 reduce_driver = jit.JitDriver(name='numpy_reduce',
                               greens = ['shapelen', 'func', 'done_func',
-                                        'calc_dtype', 'identity'],
+                                        'calc_dtype'],
                               reds = 'auto')
 
 def compute_reduce(obj, calc_dtype, func, done_func, identity):
     while not obj_iter.done():
         reduce_driver.jit_merge_point(shapelen=shapelen, func=func,
                                       done_func=done_func,
-                                      calc_dtype=calc_dtype, identity=identity,
+                                      calc_dtype=calc_dtype,
                                       )
         rval = obj_iter.getitem().convert_to(calc_dtype)
         if done_func is not None and done_func(calc_dtype, rval):

File pypy/module/micronumpy/test/test_zjit.py

View file
  • Ignore whitespace
             elif isinstance(w_res, interp_boxes.W_BoolBox):
                 return float(w_res.value)
             raise TypeError(w_res)
-
+      
         if self.graph is None:
             interp, graph = self.meta_interp(f, [0],
                                              listops=True,
                                 'int_add': 3,
                                 })
 
+    def define_reduce():
+        return """
+        a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
+        sum(a)
+        """
+
     def test_reduce_compile_only_once(self):
         self.compile_graph()
         reset_stats()
         pyjitpl._warmrunnerdesc.memory_manager.alive_loops.clear()
-        i = self.code_mapping['sum']
+        i = self.code_mapping['reduce']
         # run it twice
         retval = self.interp.eval_graph(self.graph, [i])
         retval = self.interp.eval_graph(self.graph, [i])

File pypy/module/pypyjit/test_pypy_c/test_containers.py

View file
  • Ignore whitespace
         loop, = log.loops_by_filename(self.filepath)
         ops = loop.ops_by_id('getitem', include_guard_not_invalidated=False)
         assert log.opnames(ops) == []
-
-    def test_list_count_virtual_list(self):
-        def main(n):
-            i = 0
-            while i < n:
-                i += [n].count(n)
-            return i
-
-        log = self.run(main, [1000])
-        assert log.result == main(1000)
-        loop, = log.loops_by_filename(self.filepath)
-        assert loop.match("""
-            i7 = int_lt(i5, i6)
-            guard_true(i7, descr=...)
-            i9 = int_add(i5, 1)
-            guard_not_invalidated(descr=...)
-            --TICK--
-            jump(..., descr=...)
-        """)

File pypy/objspace/std/bytesobject.py

  • Ignore whitespace
File contents unchanged.

File pypy/objspace/std/dictmultiobject.py

View file
  • Ignore whitespace
     def get_empty_storage(self):
         raise NotImplementedError
 
+    @jit.look_inside_iff(lambda self, w_dict:
+                         w_dict_unrolling_heuristic(w_dict))
     def w_keys(self, w_dict):
         iterator = self.iterkeys(w_dict)
         result = newlist_hint(self.length(w_dict))

File pypy/objspace/std/kwargsdict.py

View file
  • Ignore whitespace
     def _never_equal_to(self, w_lookup_type):
         return False
 
-    def w_keys(self, w_dict):
-        return self.space.newlist([self.space.wrap(key) for key in self.unerase(w_dict.dstorage)[0]])
-
     def setitem(self, w_dict, w_key, w_value):
         if self.is_correct_type(w_key):
             self.setitem_str(w_dict, self.unwrap(w_key), w_value)
             jit.isconstant(self.length(w_dict)) and jit.isconstant(key))
     def _setitem_str_indirection(self, w_dict, key, w_value):
         keys, values_w = self.unerase(w_dict.dstorage)
-        result = []
         for i in range(len(keys)):
             if keys[i] == key:
                 values_w[i] = w_value
                 values_w.append(w_value)
 
     def setdefault(self, w_dict, w_key, w_default):
-        space = self.space
         if self.is_correct_type(w_key):
             key = self.unwrap(w_key)
             w_result = self.getitem_str(w_dict, key)
             jit.isconstant(self.length(w_dict)) and jit.isconstant(key))
     def _getitem_str_indirection(self, w_dict, key):
         keys, values_w = self.unerase(w_dict.dstorage)
-        result = []
         for i in range(len(keys)):
             if keys[i] == key:
                 return values_w[i]
 
     def getiterkeys(self, w_dict):
         return iter(self.unerase(w_dict.dstorage)[0])
+
     def getitervalues(self, w_dict):
         return iter(self.unerase(w_dict.dstorage)[1])
+
     def getiteritems(self, w_dict):
         keys = self.unerase(w_dict.dstorage)[0]
         return iter(range(len(keys)))
+
     def wrapkey(space, key):
         return space.wrap(key)
 
+
 def next_item(self):
     strategy = self.strategy
     assert isinstance(strategy, KwargsDictStrategy)

File pypy/objspace/std/listobject.py

View file
  • Ignore whitespace
         'L.reverse() -- reverse *IN PLACE*'
         self.reverse()
 
-    @jit.look_inside_iff(lambda self, space, w_value:
-            jit.loop_unrolling_heuristic(self, self.length(), UNROLL_CUTOFF))
     def descr_count(self, space, w_value):
         '''L.count(value) -> integer -- return number of
         occurrences of value'''

File pypy/objspace/std/stringmethods.py

View file
  • Ignore whitespace
         value = self._val(space)
         length = len(value)
         if space.is_none(w_sep):
-            i = 0
-            while True:
-                # find the beginning of the next word
-                while i < length:
-                    if not self._isspace(value[i]):
-                        break   # found
-                    i += 1
-                else:
-                    break  # end of string, finished
-
-                # find the end of the word
-                if maxsplit == 0:
-                    j = length   # take all the rest of the string
-                else:
-                    j = i + 1
-                    while j < length and not self._isspace(value[j]):
-                        j += 1
-                    maxsplit -= 1   # NB. if it's already < 0, it stays < 0
-
-                # the word is value[i:j]
-                res.append(value[i:j])
-
-                # continue to look from the character following the space after the word
-                i = j + 1
-
+            res = split(value, maxsplit=maxsplit)
             return self._newlist_unwrapped(space, res)
 
         by = self._op_val(space, w_sep)
         res = []
         value = self._val(space)
         if space.is_none(w_sep):
-            i = len(value)-1
-            while True:
-                # starting from the end, find the end of the next word
-                while i >= 0:
-                    if not self._isspace(value[i]):
-                        break   # found
-                    i -= 1
-                else:
-                    break  # end of string, finished
-
-                # find the start of the word
-                # (more precisely, 'j' will be the space character before the word)
-                if maxsplit == 0:
-                    j = -1   # take all the rest of the string
-                else:
-                    j = i - 1
-                    while j >= 0 and not self._isspace(value[j]):
-                        j -= 1
-                    maxsplit -= 1   # NB. if it's already < 0, it stays < 0
-
-                # the word is value[j+1:i+1]
-                j1 = j + 1
-                assert j1 >= 0
-                res.append(value[j1:i+1])
-
-                # continue to look from the character before the space before the word
-                i = j - 1
-
-            res.reverse()
+            res = rsplit(value, maxsplit=maxsplit)
             return self._newlist_unwrapped(space, res)
 
         by = self._op_val(space, w_sep)
         selfval = self._val(space)
         if len(selfval) == 0:
             return self
+        return self._new(self.title(selfval))
 
-        builder = self._builder(len(selfval))
+    @jit.elidable
+    def title(self, value):
+        builder = self._builder(len(value))
         previous_is_cased = False
-        for pos in range(len(selfval)):
-            ch = selfval[pos]
+        for ch in value:
             if not previous_is_cased:
                 builder.append(self._title(ch))
             else:
                 builder.append(self._lower(ch))
             previous_is_cased = self._iscased(ch)
-        return self._new(builder.build())
+        return builder.build()
 
     DEFAULT_NOOP_TABLE = ''.join([chr(i) for i in range(256)])
 

File pypy/tool/pytest/apptest.py

View file
  • Ignore whitespace
         try:
             target(*args)
         except OperationError, e:
+            if self.config.option.verbose:
+                raise
             tb = sys.exc_info()[2]
             if e.match(space, space.w_KeyboardInterrupt):
                 raise KeyboardInterrupt, KeyboardInterrupt(), tb

File rpython/annotator/binaryop.py

View file
  • Ignore whitespace
                 if pbc.isNone():
                     return %(classname)s(%(constructor_args)s)
                 else:
-                    return SomeObject()
+                    raise UnionError(pbc, obj)
 
         class __extend__(pairtype(SomePBC, %(classname)s)):
             def union((pbc, obj)):
                 if pbc.isNone():
                     return %(classname)s(%(constructor_args)s)
                 else:
-                    return SomeObject()
+                    raise UnionError(pbc, obj)
     """ % loc)
     exec source.compile() in glob
 

File rpython/rlib/rstring.py

View file
  • Ignore whitespace
 # -------------- public API for string functions -----------------------
 
 @specialize.argtype(0)
-def split(value, by, maxsplit=-1):
+def split(value, by=None, maxsplit=-1):
+    if by is None:
+        length = len(value)
+        i = 0
+        res = []
+        while True:
+            # find the beginning of the next word
+            while i < length:
+                if not value[i].isspace():
+                    break   # found
+                i += 1
+            else:
+                break  # end of string, finished
+
+            # find the end of the word
+            if maxsplit == 0:
+                j = length   # take all the rest of the string
+            else:
+                j = i + 1
+                while j < length and not value[j].isspace():
+                    j += 1
+                maxsplit -= 1   # NB. if it's already < 0, it stays < 0
+
+            # the word is value[i:j]
+            res.append(value[i:j])
+
+            # continue to look from the character following the space after the word
+            i = j + 1
+        return res
+
     if isinstance(value, str):
         assert isinstance(by, str)
     else:
 
 
 @specialize.argtype(0)
-def rsplit(value, by, maxsplit=-1):
+def rsplit(value, by=None, maxsplit=-1):
+    if by is None:
+        res = []
+
+        i = len(value) - 1
+        while True:
+            # starting from the end, find the end of the next word
+            while i >= 0:
+                if not value[i].isspace():
+                    break   # found
+                i -= 1
+            else:
+                break  # end of string, finished
+
+            # find the start of the word
+            # (more precisely, 'j' will be the space character before the word)
+            if maxsplit == 0:
+                j = -1   # take all the rest of the string
+            else:
+                j = i - 1
+                while j >= 0 and not value[j].isspace():
+                    j -= 1
+                maxsplit -= 1   # NB. if it's already < 0, it stays < 0
+
+            # the word is value[j+1:i+1]
+            j1 = j + 1
+            assert j1 >= 0
+            res.append(value[j1:i+1])
+
+            # continue to look from the character before the space before the word
+            i = j - 1
+
+        res.reverse()
+        return res
+
     if isinstance(value, str):
         assert isinstance(by, str)
     else:

File rpython/rlib/test/test_rstring.py

View file
  • Ignore whitespace
     assert split('endcase test', 'test') == ['endcase ', '']
     py.test.raises(ValueError, split, 'abc', '')
 
+def test_split_None():
+    assert split("") == []
+    assert split(' a\ta\na b') == ['a', 'a', 'a', 'b']
+    assert split(" a a ", maxsplit=1) == ['a', 'a ']
+
 def test_split_unicode():
     assert split(u"", u'x') == [u'']
     assert split(u"a", u"a", 1) == [u'', u'']
     assert rsplit('endcase test', 'test') == ['endcase ', '']
     py.test.raises(ValueError, rsplit, "abc", '')
 
+def test_rsplit_None():
+    assert rsplit("") == []
+    assert rsplit(' a\ta\na b') == ['a', 'a', 'a', 'b']
+    assert rsplit(" a a ", maxsplit=1) == [' a', 'a']
+
 def test_rsplit_unicode():
     assert rsplit(u"a", u"a", 1) == [u'', u'']
     assert rsplit(u" ", u" ", 1) == [u'', u'']
         def fn():
             res = True
             res = res and split('a//b//c//d', '//') == ['a', 'b', 'c', 'd']
+            res = res and split(' a\ta\na b') == ['a', 'a', 'a', 'b']
             res = res and split('a//b//c//d', '//', 2) == ['a', 'b', 'c//d']
             res = res and split(u'a//b//c//d', u'//') == [u'a', u'b', u'c', u'd']
             res = res and split(u'endcase test', u'test') == [u'endcase ', u'']