[pypy-commit] pypy default: describe invalid source strings at the pypy level vs rpython. simplifies py3k

2014-02-02 Thread pjenvey
Author: Philip Jenvey 
Branch: 
Changeset: r69047:3c0908d6f8ad
Date: 2014-02-02 14:08 -0800
http://bitbucket.org/pypy/pypy/changeset/3c0908d6f8ad/

Log:describe invalid source strings at the pypy level vs rpython.
simplifies py3k and improves error messages

diff --git a/pypy/module/_csv/interp_reader.py 
b/pypy/module/_csv/interp_reader.py
--- a/pypy/module/_csv/interp_reader.py
+++ b/pypy/module/_csv/interp_reader.py
@@ -39,6 +39,7 @@
 field_builder.append(c)
 
 def save_field(self, field_builder):
+space = self.space
 field = field_builder.build()
 if self.numeric_field:
 from rpython.rlib.rstring import ParseStringError
@@ -46,12 +47,12 @@
 self.numeric_field = False
 try:
 ff = string_to_float(field)
-except ParseStringError, e:
-raise OperationError(self.space.w_ValueError,
- self.space.wrap(e.msg))
-w_obj = self.space.wrap(ff)
+except ParseStringError as e:
+from pypy.objspace.std.inttype import wrap_parsestringerror
+raise wrap_parsestringerror(space, e, space.wrap(field))
+w_obj = space.wrap(ff)
 else:
-w_obj = self.space.wrap(field)
+w_obj = space.wrap(field)
 self.fields_w.append(w_obj)
 
 def next_w(self):
diff --git a/pypy/objspace/std/floattype.py b/pypy/objspace/std/floattype.py
--- a/pypy/objspace/std/floattype.py
+++ b/pypy/objspace/std/floattype.py
@@ -34,20 +34,11 @@
 value = space.float_w(w_obj)
 elif (space.isinstance_w(w_value, space.w_str) or
   space.isinstance_w(w_value, space.w_bytearray)):
-strvalue = space.bufferstr_w(w_value)
-try:
-value = rfloat.string_to_float(strvalue)
-except ParseStringError, e:
-raise OperationError(space.w_ValueError,
- space.wrap(e.msg))
+value = _string_to_float(space, w_value, space.bufferstr_w(w_value))
 elif space.isinstance_w(w_value, space.w_unicode):
 from unicodeobject import unicode_to_decimal_w
-strvalue = unicode_to_decimal_w(space, w_value)
-try:
-value = rfloat.string_to_float(strvalue)
-except ParseStringError, e:
-raise OperationError(space.w_ValueError,
- space.wrap(e.msg))
+value = _string_to_float(space, w_value,
+ unicode_to_decimal_w(space, w_value))
 else:
 value = space.float_w(w_x)
 w_obj = space.allocate_instance(W_FloatObject, w_floattype)
@@ -55,6 +46,14 @@
 return w_obj
 
 
+def _string_to_float(space, w_source, string):
+try:
+return rfloat.string_to_float(string)
+except ParseStringError as e:
+from pypy.objspace.std.inttype import wrap_parsestringerror
+raise wrap_parsestringerror(space, e, w_source)
+
+
 def detect_floatformat():
 from rpython.rtyper.lltypesystem import rffi, lltype
 buf = lltype.malloc(rffi.CCHARP.TO, 8, flavor='raw')
diff --git a/pypy/objspace/std/inttype.py b/pypy/objspace/std/inttype.py
--- a/pypy/objspace/std/inttype.py
+++ b/pypy/objspace/std/inttype.py
@@ -9,7 +9,8 @@
 from rpython.rlib.rarithmetic import r_uint, string_to_int
 from rpython.rlib.objectmodel import instantiate
 from rpython.rlib.rbigint import rbigint
-from rpython.rlib.rstring import ParseStringError, ParseStringOverflowError
+from rpython.rlib.rstring import (
+InvalidBaseError, ParseStringError, ParseStringOverflowError)
 from rpython.rlib import jit
 
 # 
@@ -63,27 +64,33 @@
 # 
 
 @jit.elidable
-def string_to_int_or_long(space, string, base=10):
+def string_to_int_or_long(space, w_source, string, base=10):
 w_longval = None
 value = 0
 try:
 value = string_to_int(string, base)
-except ParseStringError, e:
-raise OperationError(space.w_ValueError,
- space.wrap(e.msg))
+except ParseStringError as e:
+raise wrap_parsestringerror(space, e, w_source)
 except ParseStringOverflowError, e:
-w_longval = retry_to_w_long(space, e.parser)
+w_longval = retry_to_w_long(space, e.parser, w_source)
 return value, w_longval
 
-def retry_to_w_long(space, parser):
+def retry_to_w_long(space, parser, w_source):
 parser.rewind()
 try:
 bigint = rbigint._from_numberstring_parser(parser)
-except ParseStringError, e:
-raise OperationError(space.w_ValueError,
- space.wrap(e.msg))
+except ParseStringError as e:
+raise wrap_parsestringerror(space, e, w_source)
 return space.newlong_from_rbigint(bigint)
 
+def wrap_parsestringerror(space, e, w_source):
+if isinstance(e, InvalidBaseError):
+w_m

[pypy-commit] pypy default: fix per 3c0908d

2014-02-02 Thread pjenvey
Author: Philip Jenvey 
Branch: 
Changeset: r69049:06e579dd1bbe
Date: 2014-02-02 20:18 -0800
http://bitbucket.org/pypy/pypy/changeset/06e579dd1bbe/

Log:fix per 3c0908d

diff --git a/rpython/rlib/test/test_rarithmetic.py 
b/rpython/rlib/test/test_rarithmetic.py
--- a/rpython/rlib/test/test_rarithmetic.py
+++ b/rpython/rlib/test/test_rarithmetic.py
@@ -492,9 +492,9 @@
 py.test.raises(ParseStringError, string_to_int, '-0x', 16)
 
 exc = py.test.raises(ParseStringError, string_to_int, '')
-assert exc.value.msg == "invalid literal for int() with base 10: ''"
+assert exc.value.msg == "invalid literal for int() with base 10"
 exc = py.test.raises(ParseStringError, string_to_int, '', 0)
-assert exc.value.msg == "invalid literal for int() with base 0: ''"
+assert exc.value.msg == "invalid literal for int() with base 0"
 
 def test_string_to_int_overflow(self):
 import sys
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: add test file that went missing in 083be7f23e9b

2014-02-02 Thread rlamy
Author: Ronan Lamy 
Branch: 
Changeset: r69050:6272b9da0c74
Date: 2014-02-03 05:18 +
http://bitbucket.org/pypy/pypy/changeset/6272b9da0c74/

Log:add test file that went missing in 083be7f23e9b

diff --git a/rpython/rtyper/test/test_llannotation.py 
b/rpython/rtyper/test/test_llannotation.py
new file mode 100644
--- /dev/null
+++ b/rpython/rtyper/test/test_llannotation.py
@@ -0,0 +1,89 @@
+import py.test
+from rpython.annotator.model import (
+SomeInteger, SomeBool, SomeChar, unionof, SomeImpossibleValue,
+UnionError, SomeInstance, SomeSingleFloat)
+from rpython.rlib.rarithmetic import r_uint, r_singlefloat
+from rpython.rtyper.llannotation import (
+SomePtr, annotation_to_lltype, ll_to_annotation)
+from rpython.rtyper.typesystem import lltype
+import rpython.rtyper.rtyper  # make sure to import the world
+
+class C(object):
+pass
+
+class DummyClassDef:
+def __init__(self, cls=C):
+self.cls = cls
+self.name = cls.__name__
+
+def test_ll_to_annotation():
+s_z = ll_to_annotation(lltype.Signed._defl())
+s_s = SomeInteger()
+s_u = SomeInteger(nonneg=True, unsigned=True)
+assert s_z.contains(s_s)
+assert not s_z.contains(s_u)
+s_uz = ll_to_annotation(lltype.Unsigned._defl())
+assert s_uz.contains(s_u)
+assert ll_to_annotation(lltype.Bool._defl()).contains(SomeBool())
+assert ll_to_annotation(lltype.Char._defl()).contains(SomeChar())
+S = lltype.GcStruct('s')
+A = lltype.GcArray()
+s_p = ll_to_annotation(lltype.malloc(S))
+assert isinstance(s_p, SomePtr) and s_p.ll_ptrtype == lltype.Ptr(S)
+s_p = ll_to_annotation(lltype.malloc(A, 0))
+assert isinstance(s_p, SomePtr) and s_p.ll_ptrtype == lltype.Ptr(A)
+
+def test_annotation_to_lltype():
+s_i = SomeInteger()
+s_pos = SomeInteger(nonneg=True)
+s_1 = SomeInteger(nonneg=True)
+s_1.const = 1
+s_m1 = SomeInteger(nonneg=False)
+s_m1.const = -1
+s_u = SomeInteger(nonneg=True, unsigned=True)
+s_u1 = SomeInteger(nonneg=True, unsigned=True)
+s_u1.const = r_uint(1)
+assert annotation_to_lltype(s_i) == lltype.Signed
+assert annotation_to_lltype(s_pos) == lltype.Signed
+assert annotation_to_lltype(s_1) == lltype.Signed
+assert annotation_to_lltype(s_m1) == lltype.Signed
+assert annotation_to_lltype(s_u) == lltype.Unsigned
+assert annotation_to_lltype(s_u1) == lltype.Unsigned
+assert annotation_to_lltype(SomeBool()) == lltype.Bool
+assert annotation_to_lltype(SomeChar()) == lltype.Char
+PS = lltype.Ptr(lltype.GcStruct('s'))
+s_p = SomePtr(ll_ptrtype=PS)
+assert annotation_to_lltype(s_p) == PS
+si0 = SomeInstance(DummyClassDef(), True)
+with py.test.raises(ValueError):
+annotation_to_lltype(si0)
+s_singlefloat = SomeSingleFloat()
+s_singlefloat.const = r_singlefloat(0.0)
+assert annotation_to_lltype(s_singlefloat) == lltype.SingleFloat
+
+def test_ll_union():
+PS1 = lltype.Ptr(lltype.GcStruct('s'))
+PS2 = lltype.Ptr(lltype.GcStruct('s'))
+PS3 = lltype.Ptr(lltype.GcStruct('s3'))
+PA1 = lltype.Ptr(lltype.GcArray())
+PA2 = lltype.Ptr(lltype.GcArray())
+
+assert unionof(SomePtr(PS1), SomePtr(PS1)) == SomePtr(PS1)
+assert unionof(SomePtr(PS1), SomePtr(PS2)) == SomePtr(PS2)
+assert unionof(SomePtr(PS1), SomePtr(PS2)) == SomePtr(PS1)
+
+assert unionof(SomePtr(PA1), SomePtr(PA1)) == SomePtr(PA1)
+assert unionof(SomePtr(PA1), SomePtr(PA2)) == SomePtr(PA2)
+assert unionof(SomePtr(PA1), SomePtr(PA2)) == SomePtr(PA1)
+
+assert unionof(SomePtr(PS1), SomeImpossibleValue()) == SomePtr(PS1)
+assert unionof(SomeImpossibleValue(), SomePtr(PS1)) == SomePtr(PS1)
+
+with py.test.raises(UnionError):
+unionof(SomePtr(PA1), SomePtr(PS1))
+with py.test.raises(UnionError):
+unionof(SomePtr(PS1), SomePtr(PS3))
+with py.test.raises(UnionError):
+unionof(SomePtr(PS1), SomeInteger())
+with py.test.raises(UnionError):
+unionof(SomeInteger(), SomePtr(PS1))
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: adapt to string based api

2014-02-02 Thread pjenvey
Author: Philip Jenvey 
Branch: py3k
Changeset: r69054:05d1dbaef6bd
Date: 2014-02-02 21:39 -0800
http://bitbucket.org/pypy/pypy/changeset/05d1dbaef6bd/

Log:adapt to string based api

diff --git a/pypy/module/_csv/interp_reader.py 
b/pypy/module/_csv/interp_reader.py
--- a/pypy/module/_csv/interp_reader.py
+++ b/pypy/module/_csv/interp_reader.py
@@ -42,15 +42,8 @@
 space = self.space
 field = field_builder.build()
 if self.numeric_field:
-from rpython.rlib.rstring import ParseStringError
-from rpython.rlib.rfloat import string_to_float
 self.numeric_field = False
-try:
-ff = string_to_float(field)
-except ParseStringError as e:
-from pypy.objspace.std.inttype import wrap_parsestringerror
-raise wrap_parsestringerror(space, e, space.wrap(field))
-w_obj = space.wrap(ff)
+w_obj = space.call_function(space.w_float, space.wrap(field))
 else:
 w_obj = space.wrap(field)
 self.fields_w.append(w_obj)
diff --git a/pypy/objspace/std/complextype.py b/pypy/objspace/std/complextype.py
--- a/pypy/objspace/std/complextype.py
+++ b/pypy/objspace/std/complextype.py
@@ -1,4 +1,3 @@
-from rpython.tool.sourcetools import with_unicode_literals
 from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault
 from pypy.interpreter.error import OperationError, operationerrfmt
 from pypy.objspace.std.register_all import register_all
@@ -19,7 +18,6 @@
 
 register_all(vars(),globals())
 
-@with_unicode_literals
 def _split_complex(s):
 slen = len(s)
 if slen == 0:
diff --git a/pypy/objspace/std/inttype.py b/pypy/objspace/std/inttype.py
--- a/pypy/objspace/std/inttype.py
+++ b/pypy/objspace/std/inttype.py
@@ -94,8 +94,8 @@
 if isinstance(e, InvalidBaseError):
 w_msg = space.wrap(e.msg)
 else:
-w_msg = space.wrap('%s: %s' % (e.msg,
-   space.str_w(space.repr(w_source
+w_msg = space.wrap(u'%s: %s' % (unicode(e.msg),
+space.unicode_w(space.repr(w_source
 return OperationError(space.w_ValueError, w_msg)
 
 ## @unwrap_spec(w_x = WrappedDefault(0))
diff --git a/pypy/objspace/std/longtype.py b/pypy/objspace/std/longtype.py
--- a/pypy/objspace/std/longtype.py
+++ b/pypy/objspace/std/longtype.py
@@ -67,8 +67,7 @@
 s = unicode_to_decimal_w(space, w_value)
 else:
 try:
-strval = space.bufferstr_w(w_value)
-s = strval.decode('latin-1')
+s = space.bufferstr_w(w_value)
 except OperationError:
 raise OperationError(space.w_TypeError,
  space.wrap("int() can't convert 
non-string "
@@ -86,7 +85,7 @@
 def string_to_w_long(space, w_longtype, w_source, string, base=10):
 try:
 bigint = rbigint.fromstr(string, base, ignore_l_suffix=True,
- fname=u'int')
+ fname='int')
 except ParseStringError as e:
 from pypy.objspace.std.inttype import wrap_parsestringerror
 raise wrap_parsestringerror(space, e, w_source)
diff --git a/pypy/objspace/std/unicodeobject.py 
b/pypy/objspace/std/unicodeobject.py
--- a/pypy/objspace/std/unicodeobject.py
+++ b/pypy/objspace/std/unicodeobject.py
@@ -1144,9 +1144,7 @@
 #
 # In CPython3 the call to PyUnicode_EncodeDecimal has been replaced to a call
 # to PyUnicode_TransformDecimalToASCII, which is much simpler. Here, we do the
-# equivalent.
-#
-# Note that, differently than default, we return an *unicode* RPython string
+# equivalent plus the final step of encoding the result to utf-8.
 def unicode_to_decimal_w(space, w_unistr):
 if not isinstance(w_unistr, W_UnicodeObject):
 raise operationerrfmt(space.w_TypeError, "expected unicode, got '%T'",
@@ -1164,7 +1162,7 @@
 except KeyError:
 pass
 result[i] = unichr(uchr)
-return u''.join(result)
+return unicodehelper.encode_utf8(space, u''.join(result))
 
 
 _repr_function, _ = make_unicode_escape_function(
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: merge default

2014-02-02 Thread pjenvey
Author: Philip Jenvey 
Branch: py3k
Changeset: r69056:5b5f0da64f64
Date: 2014-02-02 21:42 -0800
http://bitbucket.org/pypy/pypy/changeset/5b5f0da64f64/

Log:merge default

diff --git a/rpython/rlib/test/test_rarithmetic.py 
b/rpython/rlib/test/test_rarithmetic.py
--- a/rpython/rlib/test/test_rarithmetic.py
+++ b/rpython/rlib/test/test_rarithmetic.py
@@ -492,9 +492,9 @@
 py.test.raises(ParseStringError, string_to_int, '-0x', 16)
 
 exc = py.test.raises(ParseStringError, string_to_int, '')
-assert exc.value.msg == "invalid literal for int() with base 10: ''"
+assert exc.value.msg == "invalid literal for int() with base 10"
 exc = py.test.raises(ParseStringError, string_to_int, '', 0)
-assert exc.value.msg == "invalid literal for int() with base 0: ''"
+assert exc.value.msg == "invalid literal for int() with base 0"
 
 def test_string_to_int_overflow(self):
 import sys
diff --git a/rpython/rtyper/test/test_llannotation.py 
b/rpython/rtyper/test/test_llannotation.py
new file mode 100644
--- /dev/null
+++ b/rpython/rtyper/test/test_llannotation.py
@@ -0,0 +1,89 @@
+import py.test
+from rpython.annotator.model import (
+SomeInteger, SomeBool, SomeChar, unionof, SomeImpossibleValue,
+UnionError, SomeInstance, SomeSingleFloat)
+from rpython.rlib.rarithmetic import r_uint, r_singlefloat
+from rpython.rtyper.llannotation import (
+SomePtr, annotation_to_lltype, ll_to_annotation)
+from rpython.rtyper.typesystem import lltype
+import rpython.rtyper.rtyper  # make sure to import the world
+
+class C(object):
+pass
+
+class DummyClassDef:
+def __init__(self, cls=C):
+self.cls = cls
+self.name = cls.__name__
+
+def test_ll_to_annotation():
+s_z = ll_to_annotation(lltype.Signed._defl())
+s_s = SomeInteger()
+s_u = SomeInteger(nonneg=True, unsigned=True)
+assert s_z.contains(s_s)
+assert not s_z.contains(s_u)
+s_uz = ll_to_annotation(lltype.Unsigned._defl())
+assert s_uz.contains(s_u)
+assert ll_to_annotation(lltype.Bool._defl()).contains(SomeBool())
+assert ll_to_annotation(lltype.Char._defl()).contains(SomeChar())
+S = lltype.GcStruct('s')
+A = lltype.GcArray()
+s_p = ll_to_annotation(lltype.malloc(S))
+assert isinstance(s_p, SomePtr) and s_p.ll_ptrtype == lltype.Ptr(S)
+s_p = ll_to_annotation(lltype.malloc(A, 0))
+assert isinstance(s_p, SomePtr) and s_p.ll_ptrtype == lltype.Ptr(A)
+
+def test_annotation_to_lltype():
+s_i = SomeInteger()
+s_pos = SomeInteger(nonneg=True)
+s_1 = SomeInteger(nonneg=True)
+s_1.const = 1
+s_m1 = SomeInteger(nonneg=False)
+s_m1.const = -1
+s_u = SomeInteger(nonneg=True, unsigned=True)
+s_u1 = SomeInteger(nonneg=True, unsigned=True)
+s_u1.const = r_uint(1)
+assert annotation_to_lltype(s_i) == lltype.Signed
+assert annotation_to_lltype(s_pos) == lltype.Signed
+assert annotation_to_lltype(s_1) == lltype.Signed
+assert annotation_to_lltype(s_m1) == lltype.Signed
+assert annotation_to_lltype(s_u) == lltype.Unsigned
+assert annotation_to_lltype(s_u1) == lltype.Unsigned
+assert annotation_to_lltype(SomeBool()) == lltype.Bool
+assert annotation_to_lltype(SomeChar()) == lltype.Char
+PS = lltype.Ptr(lltype.GcStruct('s'))
+s_p = SomePtr(ll_ptrtype=PS)
+assert annotation_to_lltype(s_p) == PS
+si0 = SomeInstance(DummyClassDef(), True)
+with py.test.raises(ValueError):
+annotation_to_lltype(si0)
+s_singlefloat = SomeSingleFloat()
+s_singlefloat.const = r_singlefloat(0.0)
+assert annotation_to_lltype(s_singlefloat) == lltype.SingleFloat
+
+def test_ll_union():
+PS1 = lltype.Ptr(lltype.GcStruct('s'))
+PS2 = lltype.Ptr(lltype.GcStruct('s'))
+PS3 = lltype.Ptr(lltype.GcStruct('s3'))
+PA1 = lltype.Ptr(lltype.GcArray())
+PA2 = lltype.Ptr(lltype.GcArray())
+
+assert unionof(SomePtr(PS1), SomePtr(PS1)) == SomePtr(PS1)
+assert unionof(SomePtr(PS1), SomePtr(PS2)) == SomePtr(PS2)
+assert unionof(SomePtr(PS1), SomePtr(PS2)) == SomePtr(PS1)
+
+assert unionof(SomePtr(PA1), SomePtr(PA1)) == SomePtr(PA1)
+assert unionof(SomePtr(PA1), SomePtr(PA2)) == SomePtr(PA2)
+assert unionof(SomePtr(PA1), SomePtr(PA2)) == SomePtr(PA1)
+
+assert unionof(SomePtr(PS1), SomeImpossibleValue()) == SomePtr(PS1)
+assert unionof(SomeImpossibleValue(), SomePtr(PS1)) == SomePtr(PS1)
+
+with py.test.raises(UnionError):
+unionof(SomePtr(PA1), SomePtr(PS1))
+with py.test.raises(UnionError):
+unionof(SomePtr(PS1), SomePtr(PS3))
+with py.test.raises(UnionError):
+unionof(SomePtr(PS1), SomeInteger())
+with py.test.raises(UnionError):
+unionof(SomeInteger(), SomePtr(PS1))
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: sync with upstream rpython

2014-02-02 Thread pjenvey
Author: Philip Jenvey 
Branch: py3k
Changeset: r69053:9d1738eabe37
Date: 2014-02-02 21:38 -0800
http://bitbucket.org/pypy/pypy/changeset/9d1738eabe37/

Log:sync with upstream rpython

diff --git a/rpython/rlib/rarithmetic.py b/rpython/rlib/rarithmetic.py
--- a/rpython/rlib/rarithmetic.py
+++ b/rpython/rlib/rarithmetic.py
@@ -684,7 +684,6 @@
 # String parsing support
 # ---
 
-@objectmodel.enforceargs(unicode, None)
 def string_to_int(s, base=10):
 """Utility to converts a string to an integer.
 If base is 0, the proper base is guessed based on the leading
@@ -694,7 +693,7 @@
 from rpython.rlib.rstring import (
 NumberStringParser, ParseStringOverflowError, strip_spaces)
 s = literal = strip_spaces(s)
-p = NumberStringParser(s, literal, base, u'int')
+p = NumberStringParser(s, literal, base, 'int')
 base = p.base
 result = 0
 while True:
diff --git a/rpython/rlib/rbigint.py b/rpython/rlib/rbigint.py
--- a/rpython/rlib/rbigint.py
+++ b/rpython/rlib/rbigint.py
@@ -4,7 +4,7 @@
 from rpython.rlib.rfloat import isinf, isnan
 from rpython.rlib.rstring import StringBuilder
 from rpython.rlib.debug import make_sure_not_resized, check_regular_int
-from rpython.rlib.objectmodel import we_are_translated, specialize, enforceargs
+from rpython.rlib.objectmodel import we_are_translated, specialize
 from rpython.rlib import jit
 from rpython.rtyper.lltypesystem import lltype, rffi
 from rpython.rtyper import extregistry
@@ -254,8 +254,7 @@
 
 @staticmethod
 @jit.elidable
-@enforceargs(unicode, None, None, None)
-def fromstr(s, base=0, ignore_l_suffix=False, fname=u'long'):
+def fromstr(s, base=0, ignore_l_suffix=False, fname='long'):
 """As string_to_int(), but optionally ignores an optional 'l' or
 'L' suffix and returns an rbigint.
 """
diff --git a/rpython/rlib/rfloat.py b/rpython/rlib/rfloat.py
--- a/rpython/rlib/rfloat.py
+++ b/rpython/rlib/rfloat.py
@@ -41,22 +41,7 @@
 if not s:
 raise ParseStringError(INVALID_MSG)
 
-try:
-ascii_s = s.encode('ascii')
-except UnicodeEncodeError:
-# if s is not ASCII, it certainly is not a float literal (because the
-# unicode-decimal to ascii-decimal conversion already happened
-# earlier). We just set ascii_s to something which will fail when
-# passed to rstring_to_float, to keep the code as similar as possible
-# to the one we have on default.
-#
-# Note that CPython does something different and it encodes the string
-# to UTF-8 before trying to parse it. We cannot since .encode('utf-8')
-# is not RPython. However, it doesn't change anything since the UTF-8
-# encoded string would make rstring_to_float to fail anyway.
-ascii_s = "not a float"
-
-low = ascii_s.lower()
+low = s.lower()
 if low == "-inf" or low == "-infinity":
 return -INFINITY
 elif low == "inf" or low == "+inf":
@@ -69,7 +54,7 @@
 return -NAN
 
 try:
-return rstring_to_float(ascii_s)
+return rstring_to_float(s)
 except ValueError:
 raise ParseStringError(INVALID_MSG)
 
diff --git a/rpython/rlib/rstring.py b/rpython/rlib/rstring.py
--- a/rpython/rlib/rstring.py
+++ b/rpython/rlib/rstring.py
@@ -6,12 +6,11 @@
 SomeInteger, SomeUnicodeCodePoint, SomeUnicodeString, SomePBC)
 from rpython.rtyper.llannotation import SomePtr
 from rpython.rlib import jit
-from rpython.rlib.objectmodel import newlist_hint, specialize, enforceargs
+from rpython.rlib.objectmodel import newlist_hint, specialize
 from rpython.rlib.rarithmetic import ovfcheck
 from rpython.rlib.unicodedata import unicodedb_5_2_0 as unicodedb
 from rpython.rtyper.extregistry import ExtRegistryEntry
 from rpython.tool.pairtype import pairtype
-from rpython.tool.sourcetools import with_unicode_literals
 
 
 # -- public API for string functions ---
@@ -264,8 +263,6 @@
 
 # -- numeric parsing support 
 
-@enforceargs(unicode)
-@with_unicode_literals
 def strip_spaces(s):
 # XXX this is not locale-dependent
 p = 0
@@ -278,7 +275,6 @@
 return s[p:q]
 
 class ParseStringError(Exception):
-@enforceargs(None, unicode)
 def __init__(self, msg):
 self.msg = msg
 
@@ -296,8 +292,6 @@
 raise ParseStringError("invalid literal for %s() with base %d" %
(self.fname, self.original_base))
 
-@enforceargs(None, unicode, unicode, int, unicode)
-@with_unicode_literals
 def __init__(self, s, literal, base, fname):
 self.fname = fname
 sign = 1
@@ -337,7 +331,6 @@
 def rewind(self):
 self.i = 0
 
-@with_unicode_literals
 def next_digit(self): # -1 => exhausted
 if self.i < self.n:
 c = self.s[self.i]
diff --git a/rpython/rlib/test/test_rarithmetic.py 
b/rpython/rlib/test/test_rarithmetic.py
---

[pypy-commit] pypy py3k: rekill str_w which snuck back in during a merge

2014-02-02 Thread pjenvey
Author: Philip Jenvey 
Branch: py3k
Changeset: r69051:f2754640183a
Date: 2014-01-31 11:04 -0800
http://bitbucket.org/pypy/pypy/changeset/f2754640183a/

Log:rekill str_w which snuck back in during a merge

diff --git a/pypy/objspace/std/unicodeobject.py 
b/pypy/objspace/std/unicodeobject.py
--- a/pypy/objspace/std/unicodeobject.py
+++ b/pypy/objspace/std/unicodeobject.py
@@ -57,9 +57,6 @@
 return None
 return space.wrap(compute_unique_id(space.unicode_w(self)))
 
-def str_w(self, space):
-return space.str_w(space.str(self))
-
 def unicode_w(self, space):
 return self._value
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: 2to3

2014-02-02 Thread pjenvey
Author: Philip Jenvey 
Branch: py3k
Changeset: r69055:274c5ad9d1ee
Date: 2014-02-02 21:41 -0800
http://bitbucket.org/pypy/pypy/changeset/274c5ad9d1ee/

Log:2to3

diff --git a/pypy/objspace/std/test/test_intobject.py 
b/pypy/objspace/std/test/test_intobject.py
--- a/pypy/objspace/std/test/test_intobject.py
+++ b/pypy/objspace/std/test/test_intobject.py
@@ -497,7 +497,7 @@
 import sys
 if '__pypy__' not in sys.builtin_module_names:
 skip('PyPy 2.x/CPython 3.4 only')
-for value in b'  1j ', u'  1٢٣٤j ':
+for value in b'  1j ', '  1٢٣٤j ':
 try:
 int(value)
 except ValueError as e:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: merge default

2014-02-02 Thread pjenvey
Author: Philip Jenvey 
Branch: py3k
Changeset: r69052:220c588360e5
Date: 2014-02-02 16:35 -0800
http://bitbucket.org/pypy/pypy/changeset/220c588360e5/

Log:merge default

diff --git a/pypy/module/_cffi_backend/test/test_handle.py 
b/pypy/module/_cffi_backend/test/test_handle.py
--- a/pypy/module/_cffi_backend/test/test_handle.py
+++ b/pypy/module/_cffi_backend/test/test_handle.py
@@ -1,20 +1,5 @@
 import random
-from pypy.module._cffi_backend.handle import CffiHandles, reduced_value
-
-
-def test_reduced_value():
-assert reduced_value(0) == 0
-assert reduced_value(1) == 0
-assert reduced_value(2) == 1
-assert reduced_value(3) == 0
-assert reduced_value(4) == 2
-assert reduced_value(5) == 1
-assert reduced_value(6) == 3
-assert reduced_value(7) == 0
-assert reduced_value(8) == 4
-assert reduced_value(9) == 2
-assert reduced_value(10) == 5
-assert reduced_value(11) == 1
+from pypy.module._cffi_backend.handle import CffiHandles
 
 
 class PseudoWeakRef(object):
diff --git a/pypy/module/_csv/interp_reader.py 
b/pypy/module/_csv/interp_reader.py
--- a/pypy/module/_csv/interp_reader.py
+++ b/pypy/module/_csv/interp_reader.py
@@ -39,6 +39,7 @@
 field_builder.append(c)
 
 def save_field(self, field_builder):
+space = self.space
 field = field_builder.build()
 if self.numeric_field:
 from rpython.rlib.rstring import ParseStringError
@@ -46,12 +47,12 @@
 self.numeric_field = False
 try:
 ff = string_to_float(field)
-except ParseStringError, e:
-raise OperationError(self.space.w_ValueError,
- self.space.wrap(e.msg))
-w_obj = self.space.wrap(ff)
+except ParseStringError as e:
+from pypy.objspace.std.inttype import wrap_parsestringerror
+raise wrap_parsestringerror(space, e, space.wrap(field))
+w_obj = space.wrap(ff)
 else:
-w_obj = self.space.wrap(field)
+w_obj = space.wrap(field)
 self.fields_w.append(w_obj)
 
 def next_w(self):
diff --git a/pypy/module/micronumpy/interp_boxes.py 
b/pypy/module/micronumpy/interp_boxes.py
--- a/pypy/module/micronumpy/interp_boxes.py
+++ b/pypy/module/micronumpy/interp_boxes.py
@@ -251,6 +251,10 @@
 value = space.is_true(self)
 return get_dtype_cache(space).w_booldtype.box(value)
 
+def descr_zero(self, space):
+from pypy.module.micronumpy.interp_dtype import get_dtype_cache
+return get_dtype_cache(space).w_longdtype.box(0)
+
 def descr_ravel(self, space):
 from pypy.module.micronumpy.base import convert_to_array
 w_values = space.newtuple([self])
@@ -582,6 +586,12 @@
 __hash__ = interp2app(W_GenericBox.descr_hash),
 
 tolist = interp2app(W_GenericBox.item),
+min = interp2app(W_GenericBox.descr_self),
+max = interp2app(W_GenericBox.descr_self),
+argmin = interp2app(W_GenericBox.descr_zero),
+argmax = interp2app(W_GenericBox.descr_zero),
+sum = interp2app(W_GenericBox.descr_self),
+prod = interp2app(W_GenericBox.descr_self),
 any = interp2app(W_GenericBox.descr_any),
 all = interp2app(W_GenericBox.descr_all),
 ravel = interp2app(W_GenericBox.descr_ravel),
diff --git a/pypy/module/micronumpy/test/test_scalar.py 
b/pypy/module/micronumpy/test/test_scalar.py
--- a/pypy/module/micronumpy/test/test_scalar.py
+++ b/pypy/module/micronumpy/test/test_scalar.py
@@ -102,6 +102,16 @@
 assert b == a
 assert b is not a
 
+def test_methods(self):
+import numpy as np
+for a in [np.int32(2), np.float64(2.0), np.complex64(42)]:
+for op in ['min', 'max', 'sum', 'prod']:
+assert getattr(a, op)() == a
+for op in ['argmin', 'argmax']:
+b = getattr(a, op)()
+assert type(b) is np.int_
+assert b == 0
+
 def test_buffer(self):
 import numpy as np
 a = np.int32(123)
diff --git a/pypy/objspace/std/floattype.py b/pypy/objspace/std/floattype.py
--- a/pypy/objspace/std/floattype.py
+++ b/pypy/objspace/std/floattype.py
@@ -34,20 +34,11 @@
 value = space.float_w(w_obj)
 elif (space.isinstance_w(w_value, space.w_str) or
   space.isinstance_w(w_value, space.w_bytearray)):
-strvalue = space.bufferstr_w(w_value)
-try:
-value = rfloat.string_to_float(strvalue.decode('latin-1'))
-except ParseStringError, e:
-raise OperationError(space.w_ValueError,
- space.wrap(e.msg))
+value = _string_to_float(space, w_value, space.bufferstr_w(w_value))
 elif space.isinstance_w(w_value, space.w_unicode):
 from unicodeobject import unicode_to_decimal_w
-strvalue = unicode_to_decimal_w(space, w_value)
-try:
-value = rfloat.string_to_float(strvalue)