Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
96229b19
Kaydet (Commit)
96229b19
authored
Mar 11, 2005
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add two new functions, any() and all().
üst
26e512a0
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
129 additions
and
0 deletions
+129
-0
libfuncs.tex
Doc/lib/libfuncs.tex
+26
-0
test_builtin.py
Lib/test/test_builtin.py
+36
-0
NEWS
Misc/NEWS
+2
-0
bltinmodule.c
Python/bltinmodule.c
+65
-0
No files found.
Doc/lib/libfuncs.tex
Dosyayı görüntüle @
96229b19
...
@@ -60,6 +60,32 @@ def my_import(name):
...
@@ -60,6 +60,32 @@ def my_import(name):
complex number, its magnitude is returned.
complex number, its magnitude is returned.
\end{funcdesc}
\end{funcdesc}
\begin{funcdesc}
{
all
}{
iterable
}
Return True if all elements of the
\var
{
iterable
}
are true.
Equivalent to:
\begin{verbatim}
def all(iterable):
for element in iterable:
if not element:
return False
return True
\end{verbatim}
\versionadded
{
2.5
}
\end{funcdesc}
\begin{funcdesc}
{
any
}{
iterable
}
Return True if any element of the
\var
{
iterable
}
is true.
Equivalent to:
\begin{verbatim}
def any(iterable):
for element in iterable:
if element:
return True
return False
\end{verbatim}
\versionadded
{
2.5
}
\end{funcdesc}
\begin{funcdesc}
{
basestring
}{}
\begin{funcdesc}
{
basestring
}{}
This abstract type is the superclass for
\class
{
str
}
and
\class
{
unicode
}
.
This abstract type is the superclass for
\class
{
str
}
and
\class
{
unicode
}
.
It cannot be called or instantiated, but it can be used to test whether
It cannot be called or instantiated, but it can be used to test whether
...
...
Lib/test/test_builtin.py
Dosyayı görüntüle @
96229b19
...
@@ -92,6 +92,14 @@ if have_unicode:
...
@@ -92,6 +92,14 @@ if have_unicode:
(
unichr
(
0x200
),
ValueError
),
(
unichr
(
0x200
),
ValueError
),
]
]
class
TestFailingBool
:
def
__nonzero__
(
self
):
raise
RuntimeError
class
TestFailingIter
:
def
__iter__
(
self
):
raise
RuntimeError
class
BuiltinTest
(
unittest
.
TestCase
):
class
BuiltinTest
(
unittest
.
TestCase
):
def
test_import
(
self
):
def
test_import
(
self
):
...
@@ -117,6 +125,34 @@ class BuiltinTest(unittest.TestCase):
...
@@ -117,6 +125,34 @@ class BuiltinTest(unittest.TestCase):
# str
# str
self
.
assertRaises
(
TypeError
,
abs
,
'a'
)
self
.
assertRaises
(
TypeError
,
abs
,
'a'
)
def
test_all
(
self
):
self
.
assertEqual
(
all
([
2
,
4
,
6
]),
True
)
self
.
assertEqual
(
all
([
2
,
None
,
6
]),
False
)
self
.
assertRaises
(
RuntimeError
,
all
,
[
2
,
TestFailingBool
(),
6
])
self
.
assertRaises
(
RuntimeError
,
all
,
TestFailingIter
())
self
.
assertRaises
(
TypeError
,
all
,
10
)
# Non-iterable
self
.
assertRaises
(
TypeError
,
all
)
# No args
self
.
assertRaises
(
TypeError
,
all
,
[
2
,
4
,
6
],
[])
# Too many args
self
.
assertEqual
(
all
([]),
True
)
# Empty iterator
S
=
[
50
,
60
]
self
.
assertEqual
(
all
(
x
>
42
for
x
in
S
),
True
)
S
=
[
50
,
40
,
60
]
self
.
assertEqual
(
all
(
x
>
42
for
x
in
S
),
False
)
def
test_any
(
self
):
self
.
assertEqual
(
any
([
None
,
None
,
None
]),
False
)
self
.
assertEqual
(
any
([
None
,
4
,
None
]),
True
)
self
.
assertRaises
(
RuntimeError
,
any
,
[
None
,
TestFailingBool
(),
6
])
self
.
assertRaises
(
RuntimeError
,
all
,
TestFailingIter
())
self
.
assertRaises
(
TypeError
,
any
,
10
)
# Non-iterable
self
.
assertRaises
(
TypeError
,
any
)
# No args
self
.
assertRaises
(
TypeError
,
any
,
[
2
,
4
,
6
],
[])
# Too many args
self
.
assertEqual
(
any
([]),
False
)
# Empty iterator
S
=
[
40
,
60
,
30
]
self
.
assertEqual
(
any
(
x
>
42
for
x
in
S
),
True
)
S
=
[
10
,
20
,
30
]
self
.
assertEqual
(
any
(
x
>
42
for
x
in
S
),
False
)
def
test_apply
(
self
):
def
test_apply
(
self
):
def
f0
(
*
args
):
def
f0
(
*
args
):
self
.
assertEqual
(
args
,
())
self
.
assertEqual
(
args
,
())
...
...
Misc/NEWS
Dosyayı görüntüle @
96229b19
...
@@ -10,6 +10,8 @@ What's New in Python 2.5 alpha 1?
...
@@ -10,6 +10,8 @@ What's New in Python 2.5 alpha 1?
Core and builtins
Core and builtins
-----------------
-----------------
- Added two new builtins, any() and all().
- Defining a class with empty parentheses is now allowed
- Defining a class with empty parentheses is now allowed
(e.g., ``class C(): pass`` is no longer a syntax error)
(e.g., ``class C(): pass`` is no longer a syntax error)
...
...
Python/bltinmodule.c
Dosyayı görüntüle @
96229b19
...
@@ -68,6 +68,69 @@ PyDoc_STRVAR(abs_doc,
...
@@ -68,6 +68,69 @@ PyDoc_STRVAR(abs_doc,
\n
\
\n
\
Return the absolute value of the argument."
);
Return the absolute value of the argument."
);
static
PyObject
*
builtin_all
(
PyObject
*
self
,
PyObject
*
v
)
{
PyObject
*
it
,
*
item
;
it
=
PyObject_GetIter
(
v
);
if
(
it
==
NULL
)
return
NULL
;
while
((
item
=
PyIter_Next
(
it
))
!=
NULL
)
{
int
cmp
=
PyObject_IsTrue
(
item
);
Py_DECREF
(
item
);
if
(
cmp
<
0
)
{
Py_DECREF
(
it
);
return
NULL
;
}
if
(
cmp
==
0
)
{
Py_DECREF
(
it
);
Py_RETURN_FALSE
;
}
}
Py_DECREF
(
it
);
if
(
PyErr_Occurred
())
return
NULL
;
Py_RETURN_TRUE
;
}
PyDoc_STRVAR
(
all_doc
,
"all(iterable) -> bool
\n
\
\n
\
Return True if bool(x) is True for all values x in the iterable."
);
static
PyObject
*
builtin_any
(
PyObject
*
self
,
PyObject
*
v
)
{
PyObject
*
it
,
*
item
;
it
=
PyObject_GetIter
(
v
);
if
(
it
==
NULL
)
return
NULL
;
while
((
item
=
PyIter_Next
(
it
))
!=
NULL
)
{
int
cmp
=
PyObject_IsTrue
(
item
);
Py_DECREF
(
item
);
if
(
cmp
<
0
)
{
Py_DECREF
(
it
);
return
NULL
;
}
if
(
cmp
==
1
)
{
Py_DECREF
(
it
);
Py_RETURN_TRUE
;
}
}
Py_DECREF
(
it
);
if
(
PyErr_Occurred
())
return
NULL
;
Py_RETURN_FALSE
;
}
PyDoc_STRVAR
(
any_doc
,
"any(iterable) -> bool
\n
\
\n
\
Return True if bool(x) is True for any x in the iterable."
);
static
PyObject
*
static
PyObject
*
builtin_apply
(
PyObject
*
self
,
PyObject
*
args
)
builtin_apply
(
PyObject
*
self
,
PyObject
*
args
)
...
@@ -2125,6 +2188,8 @@ in length to the length of the shortest argument sequence.");
...
@@ -2125,6 +2188,8 @@ in length to the length of the shortest argument sequence.");
static
PyMethodDef
builtin_methods
[]
=
{
static
PyMethodDef
builtin_methods
[]
=
{
{
"__import__"
,
builtin___import__
,
METH_VARARGS
,
import_doc
},
{
"__import__"
,
builtin___import__
,
METH_VARARGS
,
import_doc
},
{
"abs"
,
builtin_abs
,
METH_O
,
abs_doc
},
{
"abs"
,
builtin_abs
,
METH_O
,
abs_doc
},
{
"all"
,
builtin_all
,
METH_O
,
all_doc
},
{
"any"
,
builtin_any
,
METH_O
,
any_doc
},
{
"apply"
,
builtin_apply
,
METH_VARARGS
,
apply_doc
},
{
"apply"
,
builtin_apply
,
METH_VARARGS
,
apply_doc
},
{
"callable"
,
builtin_callable
,
METH_O
,
callable_doc
},
{
"callable"
,
builtin_callable
,
METH_O
,
callable_doc
},
{
"chr"
,
builtin_chr
,
METH_VARARGS
,
chr_doc
},
{
"chr"
,
builtin_chr
,
METH_VARARGS
,
chr_doc
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment