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
2724ab99
Kaydet (Commit)
2724ab99
authored
Mar 19, 2008
tarafından
David Wolever
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Added zip, map, filter to future_bultins (#2171)
üst
fbe7c559
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
4 deletions
+49
-4
test_future_builtins.py
Lib/test/test_future_builtins.py
+13
-1
test_py3kwarn.py
Lib/test/test_py3kwarn.py
+11
-0
future_builtins.c
Modules/future_builtins.c
+14
-1
itertoolsmodule.c
Modules/itertoolsmodule.c
+11
-2
No files found.
Lib/test/test_future_builtins.py
Dosyayı görüntüle @
2724ab99
import
test.test_support
,
unittest
# we're testing the behavior of these future builtins:
from
future_builtins
import
hex
,
oct
from
future_builtins
import
hex
,
oct
,
map
,
zip
,
filter
from
test
import
test_support
class
BuiltinTest
(
unittest
.
TestCase
):
def
test_hex
(
self
):
...
...
@@ -20,6 +21,17 @@ class BuiltinTest(unittest.TestCase):
self
.
assertEqual
(
oct
(
-
100L
),
'-0o144'
)
self
.
assertRaises
(
TypeError
,
oct
,
())
def
test_itertools
(
self
):
from
itertools
import
imap
,
izip
,
ifilter
# We will assume that the itertools functions work, so provided
# that we've got identical coppies, we will work!
self
.
assertEqual
(
map
,
imap
)
self
.
assertEqual
(
zip
,
izip
)
self
.
assertEqual
(
filter
,
ifilter
)
# Testing that filter(None, stuff) raises a warning lives in
# test_py3kwarn.py
def
test_main
(
verbose
=
None
):
test
.
test_support
.
run_unittest
(
BuiltinTest
)
...
...
Lib/test/test_py3kwarn.py
Dosyayı görüntüle @
2724ab99
...
...
@@ -50,6 +50,17 @@ class TestPy3KWarnings(unittest.TestCase):
with
catch_warning
()
as
w
:
self
.
assertWarning
(
cell0
<
cell1
,
w
,
expected
)
def
test_filter
(
self
):
from
itertools
import
ifilter
from
future_builtins
import
filter
expected
=
'ifilter with None as a first argument is not supported '
\
'in 3.x. Use a list comprehension instead.'
with
catch_warning
()
as
w
:
self
.
assertWarning
(
ifilter
(
None
,
[]),
w
,
expected
)
with
catch_warning
()
as
w
:
self
.
assertWarning
(
filter
(
None
,
[]),
w
,
expected
)
def
test_code_inequality_comparisons
(
self
):
expected
=
'code inequality comparisons not supported in 3.x.'
def
f
(
x
):
...
...
Modules/future_builtins.c
Dosyayı görüntüle @
2724ab99
...
...
@@ -59,11 +59,24 @@ static PyMethodDef module_functions[] = {
PyMODINIT_FUNC
initfuture_builtins
(
void
)
{
PyObject
*
m
;
PyObject
*
m
,
*
itertools
,
*
iter_func
;
char
*
it_funcs
[]
=
{
"imap"
,
"ifilter"
,
"izip"
,
NULL
};
char
**
cur_func
;
m
=
Py_InitModule3
(
"future_builtins"
,
module_functions
,
module_doc
);
if
(
m
==
NULL
)
return
;
itertools
=
PyImport_ImportModuleNoBlock
(
"itertools"
);
if
(
itertools
==
NULL
)
return
;
for
(
cur_func
=
it_funcs
;
*
cur_func
;
++
cur_func
){
iter_func
=
PyObject_GetAttrString
(
itertools
,
*
cur_func
);
if
(
iter_func
==
NULL
)
return
;
PyModule_AddObject
(
m
,
*
cur_func
+
1
,
iter_func
);
}
Py_DECREF
(
itertools
);
/* any other initialization needed */
}
Modules/itertoolsmodule.c
Dosyayı görüntüle @
2724ab99
...
...
@@ -2542,7 +2542,7 @@ ifilter_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
ifilterobject
*
lz
;
if
(
Py_Py3kWarningFlag
&&
PyErr_Warn
(
PyExc_DeprecationWarning
,
PyErr_Warn
(
PyExc_DeprecationWarning
,
"In 3.x, itertools.ifilter() was moved to builtin filter()."
)
<
0
)
return
NULL
;
...
...
@@ -2552,6 +2552,15 @@ ifilter_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
if
(
!
PyArg_UnpackTuple
(
args
,
"ifilter"
,
2
,
2
,
&
func
,
&
seq
))
return
NULL
;
if
(
func
==
Py_None
)
{
if
(
Py_Py3kWarningFlag
&&
PyErr_Warn
(
PyExc_DeprecationWarning
,
"ifilter with None as a first argument "
"is not supported in 3.x. Use a list "
"comprehension instead."
)
<
0
)
return
NULL
;
}
/* Get iterator. */
it
=
PyObject_GetIter
(
seq
);
if
(
it
==
NULL
)
...
...
@@ -3602,7 +3611,7 @@ inititertools(void)
&
izip_type
,
&
iziplongest_type
,
&
permutations_type
,
&
product_type
,
&
product_type
,
&
repeat_type
,
&
groupby_type
,
NULL
...
...
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