[pypy-svn] r41584 - pypy/dist/pypy/module/__builtin__
cfbolz at codespeak.net
cfbolz at codespeak.net
Wed Mar 28 18:23:30 CEST 2007
Author: cfbolz
Date: Wed Mar 28 18:23:28 2007
New Revision: 41584
Modified:
pypy/dist/pypy/module/__builtin__/__init__.py
pypy/dist/pypy/module/__builtin__/app_functional.py
pypy/dist/pypy/module/__builtin__/functional.py
Log:
move any and all to interp-level. Thanks danhs.
Modified: pypy/dist/pypy/module/__builtin__/__init__.py
==============================================================================
--- pypy/dist/pypy/module/__builtin__/__init__.py (original)
+++ pypy/dist/pypy/module/__builtin__/__init__.py Wed Mar 28 18:23:28 2007
@@ -44,8 +44,6 @@
# is still needed and should stay where it is.
'min' : 'app_functional.min',
'max' : 'app_functional.max',
- 'all' : 'app_functional.all',
- 'any' : 'app_functional.any',
'enumerate' : 'app_functional.enumerate',
'xrange' : 'app_functional.xrange',
'_install_pickle_support_for_xrange_iterator':
@@ -129,6 +127,8 @@
'__import__' : 'importing.importhook',
'range' : 'functional.range_int',
+ 'all' : 'functional.all',
+ 'any' : 'functional.any',
# float->string helper
'_formatd' : 'special._formatd'
}
Modified: pypy/dist/pypy/module/__builtin__/app_functional.py
==============================================================================
--- pypy/dist/pypy/module/__builtin__/app_functional.py (original)
+++ pypy/dist/pypy/module/__builtin__/app_functional.py Wed Mar 28 18:23:28 2007
@@ -273,22 +273,6 @@
def __iter__(self):
return self
-# ____________________________________________________________
-
-def all( it ):
- "Return True if bool(x) is True for all values x in the given iterable."
- for i in it:
- if not i:
- return False
- return True
-
-def any( it ):
- "Return True if bool(x) is True for any value x in the given iterable."
- for i in it:
- if i:
- return True
- return False
-
# ____________________________________________________________
Modified: pypy/dist/pypy/module/__builtin__/functional.py
==============================================================================
--- pypy/dist/pypy/module/__builtin__/functional.py (original)
+++ pypy/dist/pypy/module/__builtin__/functional.py Wed Mar 28 18:23:28 2007
@@ -1,15 +1,6 @@
"""
Interp-level definition of frequently used functionals.
-Candidates implemented
-
- range yes
- zip no
- min no
- max no
- enumerate no
- xrange no
-
"""
from pypy.interpreter.error import OperationError
@@ -113,3 +104,34 @@
impl = RangeImplementation(space, start, step, howmany)
return W_ListMultiObject(space, impl)
+
+
+
+def all(space, w_S):
+ w_iter = space.iter(w_S)
+ while True:
+ try:
+ w_next = space.next(w_iter)
+ except OperationError, e:
+ if not e.match(space, space.w_StopIteration):
+ raise # re-raise other app-level exceptions
+ break
+ if not space.is_true(w_next):
+ return space.w_False
+ return space.w_True
+all.unwrap_spec = [ObjSpace, W_Root]
+
+
+def any(space, w_S):
+ w_iter = space.iter(w_S)
+ while True:
+ try:
+ w_next = space.next(w_iter)
+ except OperationError, e:
+ if not e.match(space, space.w_StopIteration):
+ raise # re-raise other app-level exceptions
+ break
+ if space.is_true(w_next):
+ return space.w_True
+ return space.w_False
+any.unwrap_spec = [ObjSpace, W_Root]
More information about the Pypy-commit
mailing list