Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
cython
Commits
927e1a4d
Commit
927e1a4d
authored
Feb 06, 2013
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
match simple keyword arguments that are passed into cdef function calls out-of-order
parent
af7fa72e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
5 deletions
+25
-5
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+21
-2
tests/run/simplify_calls.pyx
tests/run/simplify_calls.pyx
+4
-3
No files found.
Cython/Compiler/ExprNodes.py
View file @
927e1a4d
...
@@ -4380,8 +4380,8 @@ class GeneralCallNode(CallNode):
...
@@ -4380,8 +4380,8 @@ class GeneralCallNode(CallNode):
unmatched_args
=
declared_args
[
len
(
args
):]
unmatched_args
=
declared_args
[
len
(
args
):]
matched_kwargs
=
set
()
matched_kwargs
=
set
()
args
=
list
(
args
)
args
=
list
(
args
)
# TODO: match keywords out-of-order and move values
#
into ordered temps if necessary
#
match keywords that are passed in order
for
decl_arg
,
arg
in
zip
(
unmatched_args
,
kwargs
.
key_value_pairs
):
for
decl_arg
,
arg
in
zip
(
unmatched_args
,
kwargs
.
key_value_pairs
):
name
=
arg
.
key
.
value
name
=
arg
.
key
.
value
if
name
in
matched_pos_args
:
if
name
in
matched_pos_args
:
...
@@ -4392,6 +4392,25 @@ class GeneralCallNode(CallNode):
...
@@ -4392,6 +4392,25 @@ class GeneralCallNode(CallNode):
args
.
append
(
arg
.
value
)
args
.
append
(
arg
.
value
)
else
:
else
:
break
break
# match simple keyword arguments that are passed out of order
if
len
(
kwargs
.
key_value_pairs
)
>
len
(
matched_kwargs
):
unmatched_args
=
declared_args
[
len
(
args
):]
keywords
=
dict
([
(
arg
.
key
.
value
,
arg
.
value
)
for
arg
in
kwargs
.
key_value_pairs
])
for
decl_arg
in
unmatched_args
:
name
=
decl_arg
.
name
arg_value
=
keywords
.
get
(
name
)
if
arg_value
and
arg_value
.
is_simple
():
matched_kwargs
.
add
(
name
)
args
.
append
(
arg_value
)
else
:
# first missing keyword argument
break
# TODO: match keywords out-of-order and move values
# into ordered temps if necessary
if
not
matched_kwargs
:
if
not
matched_kwargs
:
return
return
self
.
positional_args
.
args
=
args
self
.
positional_args
.
args
=
args
...
...
tests/run/simplify_calls.pyx
View file @
927e1a4d
...
@@ -33,7 +33,6 @@ def cfunc_some_keywords():
...
@@ -33,7 +33,6 @@ def cfunc_some_keywords():
return
cfunc
(
1
,
2
,
c
=
3
,
d
=
4
)
return
cfunc
(
1
,
2
,
c
=
3
,
d
=
4
)
'''
@
cython
.
test_fail_if_path_exists
(
'//GeneralCallNode'
)
@
cython
.
test_fail_if_path_exists
(
'//GeneralCallNode'
)
@
cython
.
test_assert_path_exists
(
'//SimpleCallNode'
)
@
cython
.
test_assert_path_exists
(
'//SimpleCallNode'
)
def
cfunc_some_keywords_unordered
():
def
cfunc_some_keywords_unordered
():
...
@@ -41,8 +40,10 @@ def cfunc_some_keywords_unordered():
...
@@ -41,8 +40,10 @@ def cfunc_some_keywords_unordered():
>>> cfunc_some_keywords_unordered()
>>> cfunc_some_keywords_unordered()
(1, 2, 3, 4)
(1, 2, 3, 4)
"""
"""
return cfunc(1, 2, d=4, d=3)
return
cfunc
(
1
,
2
,
d
=
4
,
c
=
3
)
'''
@cython.test_fail_if_path_exists('//GeneralCallNode')
@cython.test_fail_if_path_exists('//GeneralCallNode')
@cython.test_assert_path_exists('//SimpleCallNode')
@cython.test_assert_path_exists('//SimpleCallNode')
def cfunc_some_keywords_unordered_sideeffect():
def cfunc_some_keywords_unordered_sideeffect():
...
@@ -53,7 +54,7 @@ def cfunc_some_keywords_unordered_sideeffect():
...
@@ -53,7 +54,7 @@ def cfunc_some_keywords_unordered_sideeffect():
>>> sideeffect
>>> sideeffect
[4, 3]
[4, 3]
"""
"""
return cfunc(1, 2, d=side_effect(4),
d
=side_effect(3))
return cfunc(1, 2, d=side_effect(4),
c
=side_effect(3))
'''
'''
...
...
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