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
b4cbc98c
Kaydet (Commit)
b4cbc98c
authored
Şub 28, 2008
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add alternate constructor for itertools.chain().
üst
05bf6338
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
1 deletion
+34
-1
test_itertools.py
Lib/test/test_itertools.py
+7
-0
NEWS
Misc/NEWS
+2
-0
itertoolsmodule.c
Modules/itertoolsmodule.c
+25
-1
No files found.
Lib/test/test_itertools.py
Dosyayı görüntüle @
b4cbc98c
...
@@ -52,6 +52,13 @@ class TestBasicOps(unittest.TestCase):
...
@@ -52,6 +52,13 @@ class TestBasicOps(unittest.TestCase):
self
.
assertEqual
(
take
(
4
,
chain
(
'abc'
,
'def'
)),
list
(
'abcd'
))
self
.
assertEqual
(
take
(
4
,
chain
(
'abc'
,
'def'
)),
list
(
'abcd'
))
self
.
assertRaises
(
TypeError
,
list
,
chain
(
2
,
3
))
self
.
assertRaises
(
TypeError
,
list
,
chain
(
2
,
3
))
def
test_chain_from_iterable
(
self
):
self
.
assertEqual
(
list
(
chain
.
from_iterable
([
'abc'
,
'def'
])),
list
(
'abcdef'
))
self
.
assertEqual
(
list
(
chain
.
from_iterable
([
'abc'
])),
list
(
'abc'
))
self
.
assertEqual
(
list
(
chain
.
from_iterable
([
''
])),
[])
self
.
assertEqual
(
take
(
4
,
chain
.
from_iterable
([
'abc'
,
'def'
])),
list
(
'abcd'
))
self
.
assertRaises
(
TypeError
,
list
,
chain
.
from_iterable
([
2
,
3
]))
def
test_combinations
(
self
):
def
test_combinations
(
self
):
self
.
assertRaises
(
TypeError
,
combinations
,
'abc'
)
# missing r argument
self
.
assertRaises
(
TypeError
,
combinations
,
'abc'
)
# missing r argument
self
.
assertRaises
(
TypeError
,
combinations
,
'abc'
,
2
,
1
)
# too many arguments
self
.
assertRaises
(
TypeError
,
combinations
,
'abc'
,
2
,
1
)
# too many arguments
...
...
Misc/NEWS
Dosyayı görüntüle @
b4cbc98c
...
@@ -1247,6 +1247,8 @@ Extension Modules
...
@@ -1247,6 +1247,8 @@ Extension Modules
- itertools.starmap() now accepts any iterable input. Previously, it required
- itertools.starmap() now accepts any iterable input. Previously, it required
the function inputs to be tuples.
the function inputs to be tuples.
- itertools.chain() now has an alterate constructor, chain.from_iterable().
- Issue #1646: Make socket support TIPC. The socket module now has support
- Issue #1646: Make socket support TIPC. The socket module now has support
for TIPC under Linux, see http://tipc.sf.net/ for more information.
for TIPC under Linux, see http://tipc.sf.net/ for more information.
...
...
Modules/itertoolsmodule.c
Dosyayı görüntüle @
b4cbc98c
...
@@ -1638,6 +1638,18 @@ chain_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
...
@@ -1638,6 +1638,18 @@ chain_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return
chain_new_internal
(
type
,
source
);
return
chain_new_internal
(
type
,
source
);
}
}
static
PyObject
*
chain_new_from_iterable
(
PyTypeObject
*
type
,
PyObject
*
arg
)
{
PyObject
*
source
;
source
=
PyObject_GetIter
(
arg
);
if
(
source
==
NULL
)
return
NULL
;
return
chain_new_internal
(
type
,
source
);
}
static
void
static
void
chain_dealloc
(
chainobject
*
lz
)
chain_dealloc
(
chainobject
*
lz
)
{
{
...
@@ -1696,6 +1708,18 @@ Return a chain object whose .next() method returns elements from the\n\
...
@@ -1696,6 +1708,18 @@ Return a chain object whose .next() method returns elements from the\n\
first iterable until it is exhausted, then elements from the next
\n
\
first iterable until it is exhausted, then elements from the next
\n
\
iterable, until all of the iterables are exhausted."
);
iterable, until all of the iterables are exhausted."
);
PyDoc_STRVAR
(
chain_from_iterable_doc
,
"chain.from_iterable(iterable) --> chain object
\n
\
\n
\
Alternate chain() contructor taking a single iterable argument
\n
\
that evaluates lazily."
);
static
PyMethodDef
chain_methods
[]
=
{
{
"from_iterable"
,
(
PyCFunction
)
chain_new_from_iterable
,
METH_O
|
METH_CLASS
,
chain_from_iterable_doc
},
{
NULL
,
NULL
}
/* sentinel */
};
static
PyTypeObject
chain_type
=
{
static
PyTypeObject
chain_type
=
{
PyVarObject_HEAD_INIT
(
NULL
,
0
)
PyVarObject_HEAD_INIT
(
NULL
,
0
)
"itertools.chain"
,
/* tp_name */
"itertools.chain"
,
/* tp_name */
...
@@ -1726,7 +1750,7 @@ static PyTypeObject chain_type = {
...
@@ -1726,7 +1750,7 @@ static PyTypeObject chain_type = {
0
,
/* tp_weaklistoffset */
0
,
/* tp_weaklistoffset */
PyObject_SelfIter
,
/* tp_iter */
PyObject_SelfIter
,
/* tp_iter */
(
iternextfunc
)
chain_next
,
/* tp_iternext */
(
iternextfunc
)
chain_next
,
/* tp_iternext */
0
,
/* tp_methods */
chain_methods
,
/* tp_methods */
0
,
/* tp_members */
0
,
/* tp_members */
0
,
/* tp_getset */
0
,
/* tp_getset */
0
,
/* tp_base */
0
,
/* tp_base */
...
...
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