Author: Manuel Jacob
Branch: remove-list-smm-2
Changeset: r64275:d97aaa5083b8
Date: 2013-05-18 11:44 +0200
http://bitbucket.org/pypy/pypy/changeset/d97aaa5083b8/
Log: Move the negate helper into the new module pypy.objspace.std.util.
diff --git a/pypy/objspace/std/dictmultiobject.py
b/pypy/objspace/std/dictmultiobject.py
--- a/pypy/objspace/std/dictmultiobject.py
+++ b/pypy/objspace/std/dictmultiobject.py
@@ -4,6 +4,7 @@
from pypy.interpreter.mixedmodule import MixedModule
from pypy.interpreter.signature import Signature
from pypy.objspace.std.stdtypedef import StdTypeDef
+from pypy.objspace.std.util import negate
from rpython.rlib import rerased, jit
from rpython.rlib.debug import mark_dict_non_null
@@ -40,19 +41,6 @@
w_dct.length() <= UNROLL_CUTOFF)
-def negate(f):
- def _negator(self, space, w_other):
- # no need to use space.is_ / space.not_
- tmp = f(self, space, w_other)
- if tmp is space.w_NotImplemented:
- return space.w_NotImplemented
- elif tmp is space.w_False:
- return space.w_True
- else:
- return space.w_False
- _negator.func_name = 'negate-%s' % f.func_name
- return _negator
-
class W_DictMultiObject(W_Root):
@staticmethod
def allocate_and_init_instance(space, w_type=None, module=False,
diff --git a/pypy/objspace/std/util.py b/pypy/objspace/std/util.py
new file mode 100644
--- /dev/null
+++ b/pypy/objspace/std/util.py
@@ -0,0 +1,18 @@
+def negate(f):
+ """Create a function which calls `f` and negates its result. When the
+ result is ``space.w_NotImplemented``, ``space.w_NotImplemented`` is
+ returned. This is useful for complementing e.g. the __ne__ descriptor if
+ your type already defines a __eq__ descriptor.
+ """
+ def _negator(self, space, w_other):
+ # no need to use space.is_ / space.not_
+ tmp = f(self, space, w_other)
+ if tmp is space.w_NotImplemented:
+ return space.w_NotImplemented
+ elif tmp is space.w_False:
+ return space.w_True
+ else:
+ return space.w_False
+ _negator.func_name = 'negate-%s' % f.func_name
+ return _negator
+
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit