[pypy-svn] r10097 - in pypy/dist/pypy/interpreter: . test
arigo at codespeak.net
arigo at codespeak.net
Tue Mar 22 23:51:29 CET 2005
Author: arigo
Date: Tue Mar 22 23:51:29 2005
New Revision: 10097
Modified:
pypy/dist/pypy/interpreter/function.py
pypy/dist/pypy/interpreter/test/test_function.py
pypy/dist/pypy/interpreter/typedef.py
Log:
Method.__eq__(), Method.__ne__(), Code.__ne__().
Modified: pypy/dist/pypy/interpreter/function.py
==============================================================================
--- pypy/dist/pypy/interpreter/function.py (original)
+++ pypy/dist/pypy/interpreter/function.py Tue Mar 22 23:51:29 2005
@@ -196,6 +196,15 @@
else:
return space.get(w_result, w_self)
+ def descr_method_eq(self, w_other):
+ space = self.space
+ other = space.interpclass_w(w_other)
+ if not isinstance(other, Method):
+ return space.w_False
+ if not space.is_w(self.w_instance, other.w_instance):
+ return space.w_False
+ return space.eq(self.w_function, other.w_function)
+
class StaticMethod(Wrappable):
"""A static method. Note that there is one class staticmethod at
app-level too currently; this is only used for __new__ methods."""
Modified: pypy/dist/pypy/interpreter/test/test_function.py
==============================================================================
--- pypy/dist/pypy/interpreter/test/test_function.py (original)
+++ pypy/dist/pypy/interpreter/test/test_function.py Tue Mar 22 23:51:29 2005
@@ -180,6 +180,19 @@
d = D()
assert d.m() == d
+ def test_method_eq(self):
+ class C:
+ def m(): pass
+ c = C()
+ assert C.m == C.m
+ assert c.m == c.m
+ assert not (C.m == c.m)
+ assert not (c.m == C.m)
+ c2 = C()
+ assert (c.m == c2.m) is False
+ assert (c.m != c2.m) is True
+ assert (c.m != c.m) is False
+
class TestMethod:
def setup_method(self, method):
def c(self, bar):
Modified: pypy/dist/pypy/interpreter/typedef.py
==============================================================================
--- pypy/dist/pypy/interpreter/typedef.py (original)
+++ pypy/dist/pypy/interpreter/typedef.py Tue Mar 22 23:51:29 2005
@@ -266,6 +266,13 @@
def descr_set_dict(space, obj, w_dict):
obj.setdict(w_dict)
+def generic_ne(space, w_obj1, w_obj2):
+ if space.eq_w(w_obj1, w_obj2):
+ return space.w_False
+ else:
+ return space.w_True
+descr_generic_ne = interp2app(generic_ne)
+
# co_xxx interface emulation for built-in code objects
def fget_co_varnames(space, w_code):
code = space.interpclass_w(w_code)
@@ -306,6 +313,7 @@
PyCode.typedef = TypeDef('code',
__new__ = interp2app(PyCode.descr_code__new__.im_func),
__eq__ = interp2app(PyCode.descr_code__eq__),
+ __ne__ = descr_generic_ne,
co_argcount = interp_attrproperty('co_argcount', cls=PyCode),
co_nlocals = interp_attrproperty('co_nlocals', cls=PyCode),
co_stacksize = interp_attrproperty('co_stacksize', cls=PyCode),
@@ -385,6 +393,8 @@
im_self = interp_attrproperty_w('w_instance', cls=Method),
im_class = interp_attrproperty_w('w_class', cls=Method),
__getattribute__ = interp2app(Method.descr_method_getattribute),
+ __eq__ = interp2app(Method.descr_method_eq),
+ __ne__ = descr_generic_ne,
# XXX getattribute/setattribute etc.pp
)
More information about the Pypy-commit
mailing list