[pypy-commit] pypy default: obscure dtype equality
fijal
noreply at buildbot.pypy.org
Thu Jan 26 18:21:59 CET 2012
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch:
Changeset: r51804:b4faea8e796e
Date: 2012-01-26 19:21 +0200
http://bitbucket.org/pypy/pypy/changeset/b4faea8e796e/
Log: obscure dtype equality
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
@@ -89,6 +89,19 @@
def descr_get_shape(self, space):
return space.newtuple([])
+ def eq(self, space, w_other):
+ if space.is_w(self, w_other):
+ return True
+ if space.isinstance_w(w_other, space.w_str):
+ return self.name == space.str_w(w_other)
+ return False
+
+ def descr_eq(self, space, w_other):
+ return space.wrap(self.eq(space, w_other))
+
+ def descr_ne(self, space, w_other):
+ return space.wrap(not self.eq(space, w_other))
+
def is_int_type(self):
return self.kind == SIGNEDLTR or self.kind == UNSIGNEDLTR
@@ -101,6 +114,8 @@
__str__= interp2app(W_Dtype.descr_str),
__repr__ = interp2app(W_Dtype.descr_repr),
+ __eq__ = interp2app(W_Dtype.descr_eq),
+ __ne__ = interp2app(W_Dtype.descr_ne),
num = interp_attrproperty("num", cls=W_Dtype),
kind = interp_attrproperty("kind", cls=W_Dtype),
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
@@ -9,6 +9,9 @@
assert d.num == 0
assert d.kind == 'b'
assert dtype('int8').num == 1
+ assert dtype('int8') == 'int8'
+ assert 'int8' == dtype('int8')
+ assert dtype('int8') != 3
assert dtype(d) is d
assert dtype(None) is dtype(float)
raises(TypeError, dtype, 1042)
More information about the pypy-commit
mailing list