Author: Manuel Jacob
Branch: refactor-str-types
Changeset: r66716:fe46e12a3919
Date: 2013-08-31 13:54 +0100
http://bitbucket.org/pypy/pypy/changeset/fe46e12a3919/
Log: hg merge default
diff --git a/lib-python/2.7/uuid.py b/lib-python/2.7/uuid.py
--- a/lib-python/2.7/uuid.py
+++ b/lib-python/2.7/uuid.py
@@ -127,8 +127,12 @@
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('-', '')
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
@@ -75,3 +75,12 @@
.. 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.
diff --git a/pypy/module/micronumpy/loop.py b/pypy/module/micronumpy/loop.py
--- a/pypy/module/micronumpy/loop.py
+++ b/pypy/module/micronumpy/loop.py
@@ -132,7 +132,7 @@
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):
@@ -146,7 +146,7 @@
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):
diff --git a/pypy/module/micronumpy/test/test_zjit.py
b/pypy/module/micronumpy/test/test_zjit.py
--- a/pypy/module/micronumpy/test/test_zjit.py
+++ b/pypy/module/micronumpy/test/test_zjit.py
@@ -56,7 +56,7 @@
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,
@@ -139,11 +139,17 @@
'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])
diff --git a/pypy/module/pypyjit/test_pypy_c/test_containers.py
b/pypy/module/pypyjit/test_pypy_c/test_containers.py
--- a/pypy/module/pypyjit/test_pypy_c/test_containers.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_containers.py
@@ -241,22 +241,3 @@
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=...)
- """)
diff --git a/pypy/objspace/std/dictmultiobject.py
b/pypy/objspace/std/dictmultiobject.py
--- a/pypy/objspace/std/dictmultiobject.py
+++ b/pypy/objspace/std/dictmultiobject.py
@@ -434,6 +434,8 @@
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))
diff --git a/pypy/objspace/std/kwargsdict.py b/pypy/objspace/std/kwargsdict.py
--- a/pypy/objspace/std/kwargsdict.py
+++ b/pypy/objspace/std/kwargsdict.py
@@ -39,9 +39,6 @@
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)
@@ -57,7 +54,6 @@
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
@@ -72,7 +68,6 @@
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)
@@ -99,7 +94,6 @@
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]
@@ -164,14 +158,18 @@
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)
diff --git a/pypy/objspace/std/listobject.py b/pypy/objspace/std/listobject.py
--- a/pypy/objspace/std/listobject.py
+++ b/pypy/objspace/std/listobject.py
@@ -562,8 +562,6 @@
'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'''
diff --git a/pypy/objspace/std/stringmethods.py
b/pypy/objspace/std/stringmethods.py
--- a/pypy/objspace/std/stringmethods.py
+++ b/pypy/objspace/std/stringmethods.py
@@ -450,31 +450,7 @@
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)
@@ -489,35 +465,7 @@
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)
@@ -647,17 +595,19 @@
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)])
diff --git a/pypy/tool/pytest/apptest.py b/pypy/tool/pytest/apptest.py
--- a/pypy/tool/pytest/apptest.py
+++ b/pypy/tool/pytest/apptest.py
@@ -34,6 +34,8 @@
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
diff --git a/rpython/annotator/binaryop.py b/rpython/annotator/binaryop.py
--- a/rpython/annotator/binaryop.py
+++ b/rpython/annotator/binaryop.py
@@ -825,14 +825,14 @@
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
diff --git a/rpython/rlib/rstring.py b/rpython/rlib/rstring.py
--- a/rpython/rlib/rstring.py
+++ b/rpython/rlib/rstring.py
@@ -14,7 +14,36 @@
# -------------- 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:
@@ -58,7 +87,41 @@
@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:
diff --git a/rpython/rlib/test/test_rstring.py
b/rpython/rlib/test/test_rstring.py
--- a/rpython/rlib/test/test_rstring.py
+++ b/rpython/rlib/test/test_rstring.py
@@ -16,6 +16,11 @@
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'']
@@ -37,6 +42,11 @@
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'']
@@ -168,6 +178,7 @@
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'']
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit