[pypy-svn] r39894 - pypy/branch/pypy-2.5/pypy/module/operator
gbrandl at codespeak.net
gbrandl at codespeak.net
Sun Mar 4 16:06:28 CET 2007
Author: gbrandl
Date: Sun Mar 4 16:06:27 2007
New Revision: 39894
Modified:
pypy/branch/pypy-2.5/pypy/module/operator/__init__.py
pypy/branch/pypy-2.5/pypy/module/operator/app_operator.py
pypy/branch/pypy-2.5/pypy/module/operator/interp_operator.py
Log:
(gbrandl, asigfrid) Some more moves to interp_operator.
Modified: pypy/branch/pypy-2.5/pypy/module/operator/__init__.py
==============================================================================
--- pypy/branch/pypy-2.5/pypy/module/operator/__init__.py (original)
+++ pypy/branch/pypy-2.5/pypy/module/operator/__init__.py Sun Mar 4 16:06:27 2007
@@ -6,13 +6,11 @@
appleveldefs = {}
- app_names = ['__delslice__', '__doc__','__getslice__', '__name__',
- '__repeat__', '__setslice__', '__truediv__','attrgetter',
- 'concat', 'contains', 'countOf', 'delitem',
- 'delslice', 'division', 'getslice', 'indexOf',
- 'isCallable','isMappingType', 'isNumberType', 'isSequenceType',
- 'itemgetter','repeat', 'sequenceIncludes', 'setslice',
- 'truediv']
+ app_names = ['__delslice__', '__getslice__', '__repeat__', '__setslice__',
+ 'attrgetter', 'countOf', 'delslice', 'getslice', 'indexOf',
+ 'isMappingType', 'isNumberType', 'isSequenceType',
+ 'itemgetter','repeat', 'setslice',
+ ]
for name in app_names:
appleveldefs[name] = 'app_operator.%s' % name
@@ -24,14 +22,14 @@
'__lshift__', '__lt__', '__mod__', '__mul__',
'__ne__', '__neg__', '__not__', '__or__',
'__pos__', '__pow__', '__rshift__', '__setitem__',
- '__sub__', '__xor__', 'abs', 'add',
- 'and_', 'div', 'eq', 'floordiv',
+ '__sub__', '__truediv__', '__xor__', 'abs', 'add',
+ 'and_', 'concat', 'contains', 'delitem', 'div', 'eq', 'floordiv',
'ge', 'getitem', 'gt', 'inv',
- 'invert', 'is_', 'is_not', 'le',
+ 'invert', 'is_', 'is_not', 'isCallable', 'le',
'lshift', 'lt', 'mod', 'mul',
'ne', 'neg', 'not_', 'or_',
- 'pos', 'pow', 'rshift', 'setitem',
- 'sub', 'truth', 'xor']
+ 'pos', 'pow', 'rshift', 'setitem', 'sequenceIncludes',
+ 'sub', 'truediv', 'truth', 'xor']
interpleveldefs = {}
for name in interp_names:
Modified: pypy/branch/pypy-2.5/pypy/module/operator/app_operator.py
==============================================================================
--- pypy/branch/pypy-2.5/pypy/module/operator/app_operator.py (original)
+++ pypy/branch/pypy-2.5/pypy/module/operator/app_operator.py Sun Mar 4 16:06:27 2007
@@ -1,9 +1,8 @@
-'''NOT_RPYTHON: Operator interface.
+'''Operator interface.
This module exports a set of operators as functions. E.g. operator.add(x,y) is
equivalent to x+y.
'''
-import __builtin__
def attrgetter(attr):
def f(obj):
@@ -41,10 +40,6 @@
index += 1
raise ValueError, 'sequence.index(x): x not in sequence'
-def isCallable(obj,):
- 'isCallable(a) -- Same as callable(a).'
- return callable(obj)
-
# XXX the following is approximative
def isMappingType(obj,):
'isMappingType(a) -- Return True if a has a mapping type, False otherwise.'
@@ -72,21 +67,8 @@
# protocol. We support any with a __mul__
__repeat__ = repeat
-def sequenceIncludes(a, b):
- 'sequenceIncludes(a, b) -- Same as b in a (note reversed operands; deprecated).'
- for x in a:
- if x == b:
- return True
- return False
-
def setslice(a, b, c, d):
'setslice(a, b, c, d) -- Same as a[b:c] = d.'
a[b:c] = d
__setslice__ = setslice
-exec """from __future__ import division
-def truediv(a, b):
- 'truediv(a, b) -- Same as a / b when __future__.division is in effect.'
- return a / b
-"""
-__truediv__ = truediv
Modified: pypy/branch/pypy-2.5/pypy/module/operator/interp_operator.py
==============================================================================
--- pypy/branch/pypy-2.5/pypy/module/operator/interp_operator.py (original)
+++ pypy/branch/pypy-2.5/pypy/module/operator/interp_operator.py Sun Mar 4 16:06:27 2007
@@ -29,12 +29,13 @@
'contains(a, b) -- Same as b in a (note reversed operands).'
return space.contains(w_obj1, w_obj2)
__contains__ = contains
+sequenceIncludes = contains
# countOf
def delitem(space, w_obj, w_key):
'delitem(a,b) -- Same as del a[b]'
- space.delete(w_obj, w_key)
+ space.delitem(w_obj, w_key)
__delitem__ = delitem
@@ -84,7 +85,9 @@
return space.invert(w_obj)
__invert__ = invert
-# isCallable
+def isCallable(space, w_obj):
+ 'isCallable(a) -- Same as callable(a).'
+ return space.callable(w_obj)
# isMappingType
@@ -92,7 +95,7 @@
# isSequenceType
-def _is(space, w_a, w_b):
+def is_(space, w_a, w_b):
'is_(a,b) -- Same as a is b'
return space.is_(w_a, w_b)
@@ -154,7 +157,7 @@
def pow(space, w_a, w_b):
'pow(a, b) -- Same as a**b.'
- return space.pow(w_a, w_b)
+ return space.pow(w_a, w_b, space.w_None)
__pow__ = pow
# reapeat
@@ -178,9 +181,14 @@
return space.sub(w_a, w_b)
__sub__ = sub
+def truediv(space, w_a, w_b):
+ 'truediv(a, b) -- Same as a / b when __future__.division is in effect.'
+ return space.truediv(w_a, w_b)
+__truediv__ = truediv
+
def truth(space, w_a,):
'truth(a) -- Return True if a is true, False otherwise.'
- return space.is_true(w_a)
+ return space.nonzero(w_a)
def xor(space, w_a, w_b):
'xor(a, b) -- Same as a ^ b.'
More information about the Pypy-commit
mailing list