Author: Manuel Jacob Branch: refactor-str-types Changeset: r65894:6d17d2b8ae2b Date: 2013-08-02 11:38 +0200 http://bitbucket.org/pypy/pypy/changeset/6d17d2b8ae2b/
Log: hg merge default diff --git a/pypy/doc/conf.py b/pypy/doc/conf.py --- a/pypy/doc/conf.py +++ b/pypy/doc/conf.py @@ -45,9 +45,9 @@ # built documents. # # The short X.Y version. -version = '2.0' +version = '2.1' # The full version, including alpha/beta/rc tags. -release = '2.0.2' +release = '2.1.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/pypy/doc/getting-started-python.rst b/pypy/doc/getting-started-python.rst --- a/pypy/doc/getting-started-python.rst +++ b/pypy/doc/getting-started-python.rst @@ -104,8 +104,8 @@ executable. The executable behaves mostly like a normal Python interpreter:: $ ./pypy-c - Python 2.7.3 (7e4f0faa3d51, Nov 22 2012, 10:35:18) - [PyPy 2.0.0 with GCC 4.7.1] on linux2 + Python 2.7.3 (480845e6b1dd, Jul 31 2013, 11:05:31) + [PyPy 2.1.0 with GCC 4.7.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. And now for something completely different: ``RPython magically makes you rich and famous (says so on the tin)'' @@ -171,7 +171,7 @@ the ``bin/pypy`` executable. To install PyPy system wide on unix-like systems, it is recommended to put the -whole hierarchy alone (e.g. in ``/opt/pypy2.0``) and put a symlink to the +whole hierarchy alone (e.g. in ``/opt/pypy2.1``) and put a symlink to the ``pypy`` executable into ``/usr/bin`` or ``/usr/local/bin`` If the executable fails to find suitable libraries, it will report diff --git a/pypy/doc/getting-started.rst b/pypy/doc/getting-started.rst --- a/pypy/doc/getting-started.rst +++ b/pypy/doc/getting-started.rst @@ -53,10 +53,10 @@ PyPy is ready to be executed as soon as you unpack the tarball or the zip file, with no need to install it in any specific location:: - $ tar xf pypy-2.0.tar.bz2 - $ ./pypy-2.0/bin/pypy - Python 2.7.3 (7e4f0faa3d51, Nov 22 2012, 10:35:18) - [PyPy 2.0.0 with GCC 4.7.1] on linux2 + $ tar xf pypy-2.1.tar.bz2 + $ ./pypy-2.1/bin/pypy + Python 2.7.3 (480845e6b1dd, Jul 31 2013, 11:05:31) + [PyPy 2.1.0 with GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. And now for something completely different: ``PyPy is an exciting technology that lets you to write fast, portable, multi-platform interpreters with less @@ -75,14 +75,14 @@ $ curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py - $ ./pypy-2.0/bin/pypy distribute_setup.py + $ ./pypy-2.1/bin/pypy distribute_setup.py - $ ./pypy-2.0/bin/pypy get-pip.py + $ ./pypy-2.1/bin/pypy get-pip.py - $ ./pypy-2.0/bin/pip install pygments # for example + $ ./pypy-2.1/bin/pip install pygments # for example -3rd party libraries will be installed in ``pypy-2.0/site-packages``, and -the scripts in ``pypy-2.0/bin``. +3rd party libraries will be installed in ``pypy-2.1/site-packages``, and +the scripts in ``pypy-2.1/bin``. Installing using virtualenv --------------------------- diff --git a/pypy/doc/index.rst b/pypy/doc/index.rst --- a/pypy/doc/index.rst +++ b/pypy/doc/index.rst @@ -40,7 +40,7 @@ * `FAQ`_: some frequently asked questions. -* `Release 2.0.2`_: the latest official release +* `Release 2.1.0`_: the latest official release * `PyPy Blog`_: news and status info about PyPy @@ -110,7 +110,7 @@ .. _`Getting Started`: getting-started.html .. _`Papers`: extradoc.html .. _`Videos`: video-index.html -.. _`Release 2.0.2`: http://pypy.org/download.html +.. _`Release 2.1.0`: http://pypy.org/download.html .. _`speed.pypy.org`: http://speed.pypy.org .. _`RPython toolchain`: translation.html .. _`potential project ideas`: project-ideas.html diff --git a/pypy/doc/release-2.1.0.rst b/pypy/doc/release-2.1.0.rst --- a/pypy/doc/release-2.1.0.rst +++ b/pypy/doc/release-2.1.0.rst @@ -15,7 +15,7 @@ .. _`Raspberry Pi Foundation`: http://www.raspberrypi.org -The first beta of PyPy3 2.1, targetting version 3 of the Python language, was +The first beta of PyPy3 2.1, targeting version 3 of the Python language, was just released, more details can be found `here`_. .. _`here`: http://morepypy.blogspot.com/2013/07/pypy3-21-beta-1.html 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 @@ -58,3 +58,7 @@ .. branch: foldable-getarrayitem-indexerror Constant-fold reading out of constant tuples in PyPy. +.. branch: mro-reorder-numpypy-str +No longer delegate numpy string_ methods to space.StringObject, in numpy +this works by kind of by accident. Support for merging the refactor-str-types +branch diff --git a/pypy/module/cpyext/include/patchlevel.h b/pypy/module/cpyext/include/patchlevel.h --- a/pypy/module/cpyext/include/patchlevel.h +++ b/pypy/module/cpyext/include/patchlevel.h @@ -29,7 +29,7 @@ #define PY_VERSION "2.7.3" /* PyPy version as a string */ -#define PYPY_VERSION "2.1.0-alpha0" +#define PYPY_VERSION "2.2.0-alpha0" /* Subversion Revision number of this file (not of the repository). * Empty since Mercurial migration. */ 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 @@ -379,12 +379,14 @@ return self class W_CharacterBox(W_FlexibleBox): - pass + def convert_to(self, dtype): + # XXX assert dtype is str type + return self + class W_StringBox(W_CharacterBox): def descr__new__string_box(space, w_subtype, w_arg): from pypy.module.micronumpy.interp_dtype import new_string_dtype - arg = space.str_w(space.str(w_arg)) arr = VoidBoxStorage(len(arg), new_string_dtype(space, len(arg))) for i in range(len(arg)): @@ -684,12 +686,12 @@ __module__ = "numpypy", ) -W_StringBox.typedef = TypeDef("string_", (W_BytesObject.typedef, W_CharacterBox.typedef), +W_StringBox.typedef = TypeDef("string_", (W_CharacterBox.typedef, W_BytesObject.typedef), __module__ = "numpypy", __new__ = interp2app(W_StringBox.descr__new__string_box.im_func), ) -W_UnicodeBox.typedef = TypeDef("unicode_", (W_UnicodeObject.typedef, W_CharacterBox.typedef), +W_UnicodeBox.typedef = TypeDef("unicode_", (W_CharacterBox.typedef, W_UnicodeObject.typedef), __module__ = "numpypy", __new__ = interp2app(W_UnicodeBox.descr__new__unicode_box.im_func), ) diff --git a/pypy/module/micronumpy/interp_dtype.py b/pypy/module/micronumpy/interp_dtype.py --- a/pypy/module/micronumpy/interp_dtype.py +++ b/pypy/module/micronumpy/interp_dtype.py @@ -234,6 +234,9 @@ def is_record_type(self): return self.fields is not None + def is_str_type(self): + return self.num == 18 + def is_str_or_unicode(self): return (self.num == 18 or self.num == 19) diff --git a/pypy/module/micronumpy/interp_ufuncs.py b/pypy/module/micronumpy/interp_ufuncs.py --- a/pypy/module/micronumpy/interp_ufuncs.py +++ b/pypy/module/micronumpy/interp_ufuncs.py @@ -328,14 +328,19 @@ w_out = None w_lhs = convert_to_array(space, w_lhs) w_rhs = convert_to_array(space, w_rhs) - if (w_lhs.get_dtype().is_flexible_type() or \ - w_rhs.get_dtype().is_flexible_type()): + w_ldtype = w_lhs.get_dtype() + w_rdtype = w_rhs.get_dtype() + if w_ldtype.is_str_type() and w_rdtype.is_str_type() and \ + self.comparison_func: + pass + elif (w_ldtype.is_flexible_type() or \ + w_rdtype.is_flexible_type()): raise OperationError(space.w_TypeError, space.wrap( 'unsupported operand dtypes %s and %s for "%s"' % \ - (w_rhs.get_dtype().get_name(), w_lhs.get_dtype().get_name(), + (w_rdtype.get_name(), w_ldtype.get_name(), self.name))) calc_dtype = find_binop_result_dtype(space, - w_lhs.get_dtype(), w_rhs.get_dtype(), + w_ldtype, w_rdtype, int_only=self.int_only, promote_to_float=self.promote_to_float, promote_bools=self.promote_bools, diff --git a/pypy/module/micronumpy/stdobjspace.py b/pypy/module/micronumpy/stdobjspace.py deleted file mode 100644 --- a/pypy/module/micronumpy/stdobjspace.py +++ /dev/null @@ -1,11 +0,0 @@ - -from pypy.objspace.std import bytesobject -from pypy.module.micronumpy import interp_boxes - -def delegate_stringbox2stringobj(space, w_box): - return space.wrap(w_box.dtype.itemtype.to_str(w_box)) - -def register_delegates(typeorder): - typeorder[interp_boxes.W_StringBox] = [ - (bytesobject.W_BytesObject, delegate_stringbox2stringobj), - ] diff --git a/pypy/module/micronumpy/test/test_dtypes.py b/pypy/module/micronumpy/test/test_dtypes.py --- a/pypy/module/micronumpy/test/test_dtypes.py +++ b/pypy/module/micronumpy/test/test_dtypes.py @@ -740,6 +740,7 @@ class AppTestStrUnicodeDtypes(BaseNumpyAppTest): def test_str_unicode(self): + skip('numpypy differs from numpy') from numpypy import str_, unicode_, character, flexible, generic assert str_.mro() == [str_, str, basestring, character, flexible, generic, object] diff --git a/pypy/module/micronumpy/test/test_numarray.py b/pypy/module/micronumpy/test/test_numarray.py --- a/pypy/module/micronumpy/test/test_numarray.py +++ b/pypy/module/micronumpy/test/test_numarray.py @@ -2755,6 +2755,19 @@ assert a[2] == 'ab' raises(TypeError, a, 'sum') raises(TypeError, 'a+a') + b = array(['abcdefg', 'ab', 'cd']) + assert a[2] == b[1] + assert bool(a[1]) + c = array(['ab','cdefg','hi','jk']) + # not implemented yet + #c[0] += c[3] + #assert c[0] == 'abjk' + + def test_to_str(self): + from numpypy import array + a = array(['abc','abc', 'def', 'ab'], 'S3') + b = array(['mnopqr','abcdef', 'ab', 'cd']) + assert b[1] != a[1] def test_string_scalar(self): from numpypy import array @@ -2766,8 +2779,7 @@ assert str(a.dtype) == '|S1' a = array('x', dtype='c') assert str(a.dtype) == '|S1' - # XXX can sort flexible types, why not comparison? - #assert a == 'x' + assert a == 'x' def test_flexible_repr(self): from numpypy import array diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py --- a/pypy/module/micronumpy/types.py +++ b/pypy/module/micronumpy/types.py @@ -1689,6 +1689,22 @@ def get_size(self): return self.size +def str_unary_op(func): + specialize.argtype(1)(func) + @functools.wraps(func) + def dispatcher(self, v1): + return func(self, self.to_str(v1)) + return dispatcher + +def str_binary_op(func): + specialize.argtype(1, 2)(func) + @functools.wraps(func) + def dispatcher(self, v1, v2): + return func(self, + self.to_str(v1), + self.to_str(v2) + ) + return dispatcher class StringType(BaseType, BaseStringType): T = lltype.Char @@ -1696,6 +1712,8 @@ @jit.unroll_safe def coerce(self, space, dtype, w_item): from pypy.module.micronumpy.interp_dtype import new_string_dtype + if isinstance(w_item, interp_boxes.W_StringBox): + return w_item arg = space.str_w(space.str(w_item)) arr = VoidBoxStorage(len(arg), new_string_dtype(space, len(arg))) for i in range(len(arg)): @@ -1705,6 +1723,7 @@ @jit.unroll_safe def store(self, arr, i, offset, box): assert isinstance(box, interp_boxes.W_StringBox) + # XXX simplify to range(box.dtype.get_size()) ? for k in range(min(self.size, box.arr.size-offset)): arr.storage[k + i] = box.arr.storage[k + offset] @@ -1718,7 +1737,7 @@ builder = StringBuilder() assert isinstance(item, interp_boxes.W_StringBox) i = item.ofs - end = i+self.size + end = i + item.dtype.get_size() while i < end: assert isinstance(item.arr.storage[i], str) if item.arr.storage[i] == '\x00': @@ -1734,10 +1753,53 @@ builder.append("'") return builder.build() - # XXX move to base class when UnicodeType is supported + # XXX move the rest of this to base class when UnicodeType is supported def to_builtin_type(self, space, box): return space.wrap(self.to_str(box)) + @str_binary_op + def eq(self, v1, v2): + return v1 == v2 + + @str_binary_op + def ne(self, v1, v2): + return v1 != v2 + + @str_binary_op + def lt(self, v1, v2): + return v1 < v2 + + @str_binary_op + def le(self, v1, v2): + return v1 <= v2 + + @str_binary_op + def gt(self, v1, v2): + return v1 > v2 + + @str_binary_op + def ge(self, v1, v2): + return v1 >= v2 + + @str_binary_op + def logical_and(self, v1, v2): + return bool(v1) and bool(v2) + + @str_binary_op + def logical_or(self, v1, v2): + return bool(v1) or bool(v2) + + @str_unary_op + def logical_not(self, v): + return not bool(v) + + @str_binary_op + def logical_xor(self, v1, v2): + return bool(v1) ^ bool(v2) + + def bool(self, v): + return bool(self.to_str(v)) + def build_and_convert(self, space, mydtype, box): assert isinstance(box, interp_boxes.W_GenericBox) if box.get_dtype(space).is_str_or_unicode(): @@ -1753,6 +1815,13 @@ arr.storage[j] = '\x00' return interp_boxes.W_StringBox(arr, 0, arr.dtype) +NonNativeStringType = StringType + +class UnicodeType(BaseType, BaseStringType): + T = lltype.UniChar + +NonNativeUnicodeType = UnicodeType + class VoidType(BaseType, BaseStringType): T = lltype.Char @@ -1798,12 +1867,6 @@ return W_NDimArray(implementation) NonNativeVoidType = VoidType -NonNativeStringType = StringType - -class UnicodeType(BaseType, BaseStringType): - T = lltype.UniChar - -NonNativeUnicodeType = UnicodeType class RecordType(BaseType): diff --git a/pypy/module/sys/version.py b/pypy/module/sys/version.py --- a/pypy/module/sys/version.py +++ b/pypy/module/sys/version.py @@ -11,7 +11,7 @@ #XXX # sync CPYTHON_VERSION with patchlevel.h, package.py CPYTHON_API_VERSION = 1013 #XXX # sync with include/modsupport.h -PYPY_VERSION = (2, 1, 0, "alpha", 0) #XXX # sync patchlevel.h +PYPY_VERSION = (2, 2, 0, "alpha", 0) #XXX # sync patchlevel.h if platform.name == 'msvc': COMPILER_INFO = 'MSC v.%d 32 bit' % (platform.version * 10 + 600) diff --git a/pypy/objspace/std/model.py b/pypy/objspace/std/model.py --- a/pypy/objspace/std/model.py +++ b/pypy/objspace/std/model.py @@ -131,10 +131,6 @@ # when trying to dispatch multimethods. # XXX build these lists a bit more automatically later - if config.objspace.usemodules.micronumpy: - from pypy.module.micronumpy.stdobjspace import register_delegates - register_delegates(self.typeorder) - self.typeorder[boolobject.W_BoolObject] += [ (intobject.W_IntObject, boolobject.delegate_Bool2IntObject), (floatobject.W_FloatObject, floatobject.delegate_Bool2Float), diff --git a/rpython/rtyper/test/test_runicode.py b/rpython/rtyper/test/test_runicode.py --- a/rpython/rtyper/test/test_runicode.py +++ b/rpython/rtyper/test/test_runicode.py @@ -8,7 +8,7 @@ # ====> test_rstr.py -class BaseTestRUnicode(AbstractTestRstr, BaseRtypingTest): +class TestRUnicode(AbstractTestRstr, BaseRtypingTest): const = unicode constchar = unichr _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit