[pypy-commit] pypy numpy-record-dtypes: make string and unicode boxes instantiatable, but completely unusable
fijal
noreply at buildbot.pypy.org
Sat Mar 3 07:27:41 CET 2012
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: numpy-record-dtypes
Changeset: r53133:9b0ff4af758c
Date: 2012-03-02 22:27 -0800
http://bitbucket.org/pypy/pypy/changeset/9b0ff4af758c/
Log: make string and unicode boxes instantiatable, but completely
unusable
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -1335,7 +1335,7 @@
if not self.is_true(self.isinstance(w_obj, self.w_str)):
raise OperationError(self.w_TypeError,
self.wrap('argument must be a string'))
- return self.str_w(w_obj)
+ return self.str_w(w_obj)
def unicode_w(self, w_obj):
return w_obj.unicode_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
@@ -4,7 +4,7 @@
from pypy.interpreter.typedef import TypeDef
from pypy.objspace.std.floattype import float_typedef
from pypy.objspace.std.stringtype import str_typedef
-from pypy.objspace.std.unicodetype import unicode_typedef
+from pypy.objspace.std.unicodetype import unicode_typedef, unicode_from_object
from pypy.objspace.std.inttype import int_typedef
from pypy.rlib.rarithmetic import LONG_BIT
from pypy.tool.sourcetools import func_with_new_name
@@ -242,15 +242,17 @@
arr.storage[i] = arg[i]
return W_StringBox(arr, 0)
+
class W_UnicodeBox(W_CharacterBox):
def descr__new__(space, w_subtype, w_arg):
from pypy.module.micronumpy.interp_numarray import W_NDimArray
from pypy.module.micronumpy.interp_dtype import new_unicode_dtype
- arg = space.unicode_w(space.unicode(w_arg))
+ arg = space.unicode_w(unicode_from_object(space, w_arg))
arr = W_NDimArray([1], new_unicode_dtype(space, len(arg)))
- for i in range(len(arg)):
- arr.setitem(i, arg[i])
+ # XXX not this way, we need store
+ #for i in range(len(arg)):
+ # arr.storage[i] = arg[i]
return W_UnicodeBox(arr, 0)
W_GenericBox.typedef = TypeDef("generic",
@@ -424,6 +426,8 @@
W_StringBox.typedef = TypeDef("string_", (str_typedef, W_CharacterBox.typedef),
__module__ = "numpypy",
__new__ = interp2app(W_StringBox.descr__new__.im_func),
+ __eq__ = interp2app(W_StringBox.descr_eq),
+ __ne__ = interp2app(W_StringBox.descr_ne),
)
W_UnicodeBox.typedef = TypeDef("unicode_", (unicode_typedef, W_CharacterBox.typedef),
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
@@ -525,11 +525,11 @@
def test_string_boxes(self):
from _numpypy import str_
- assert str_(3) == '3'
+ assert isinstance(str_(3), str_)
def test_unicode_boxes(self):
- from _numpypy import str_
- assert str_(3) == '3'
+ from _numpypy import unicode_
+ assert isinstance(unicode_(3), unicode)
class AppTestRecordDtypes(BaseNumpyAppTest):
def test_create(self):
More information about the pypy-commit
mailing list