Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
2724ab99
Commit
2724ab99
authored
Mar 19, 2008
by
David Wolever
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added zip, map, filter to future_bultins (#2171)
parent
fbe7c559
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
4 deletions
+49
-4
Lib/test/test_future_builtins.py
Lib/test/test_future_builtins.py
+13
-1
Lib/test/test_py3kwarn.py
Lib/test/test_py3kwarn.py
+11
-0
Modules/future_builtins.c
Modules/future_builtins.c
+14
-1
Modules/itertoolsmodule.c
Modules/itertoolsmodule.c
+11
-2
No files found.
Lib/test/test_future_builtins.py
View file @
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
View file @
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
View file @
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
View file @
2724ab99
...
...
@@ -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
)
...
...
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