introduce py.builtin.any

--HG--
branch : trunk
This commit is contained in:
holger krekel 2010-10-05 17:21:27 +02:00
parent 6892dc47a3
commit a054b63bac
4 changed files with 15 additions and 0 deletions

View File

@ -11,6 +11,7 @@ Changes between 1.3.4 and 1.4.0.dev0
- major refactoring of internal collection handling
- majorly reduce py.test core code, shift function/python testing to own plugin
- fix issue88 (finding custom test nodes from command line arg)
- introduce py.builtin.any()
Changes between 1.3.3 and 1.3.4
==================================================

View File

@ -102,6 +102,7 @@ py.apipkg.initpkg(__name__, dict(
'enumerate' : '._builtin:enumerate',
'reversed' : '._builtin:reversed',
'sorted' : '._builtin:sorted',
'any' : '._builtin:any',
'set' : '._builtin:set',
'frozenset' : '._builtin:frozenset',
'BaseException' : '._builtin:BaseException',

View File

@ -35,6 +35,15 @@ except NameError:
def __length_hint__(self):
return self.remaining
try:
any = any
except NameError:
def any(iterable):
for x in iterable:
if x:
return True
return False
try:
sorted = sorted
except NameError:

View File

@ -8,6 +8,10 @@ def test_enumerate():
for i,x in enumerate(l):
assert i == x
def test_any():
assert not py.builtin.any([0,False, None])
assert py.builtin.any([0,False, None,1])
def test_BaseException():
assert issubclass(IndexError, py.builtin.BaseException)
assert issubclass(Exception, py.builtin.BaseException)