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
Gwenaël Samain
cython
Commits
8c5adff1
Commit
8c5adff1
authored
Nov 02, 2010
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix *args/**kwargs in lambda function declaration: was messed up with annotation syntax
parent
915d8861
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
5 deletions
+37
-5
Cython/Compiler/Parsing.py
Cython/Compiler/Parsing.py
+5
-5
tests/run/lambda_T195.pyx
tests/run/lambda_T195.pyx
+32
-0
No files found.
Cython/Compiler/Parsing.py
View file @
8c5adff1
...
...
@@ -2568,23 +2568,23 @@ def p_varargslist(s, terminator=')', annotated=1):
if
s
.
sy
==
'*'
:
s
.
next
()
if
s
.
sy
==
'IDENT'
:
star_arg
=
p_py_arg_decl
(
s
)
star_arg
=
p_py_arg_decl
(
s
,
annotated
=
annotated
)
if
s
.
sy
==
','
:
s
.
next
()
args
.
extend
(
p_c_arg_list
(
s
,
in_pyfunc
=
1
,
nonempty_declarators
=
1
,
kw_only
=
1
))
nonempty_declarators
=
1
,
kw_only
=
1
,
annotated
=
annotated
))
elif
s
.
sy
!=
terminator
:
s
.
error
(
"Syntax error in Python function argument list"
)
if
s
.
sy
==
'**'
:
s
.
next
()
starstar_arg
=
p_py_arg_decl
(
s
)
starstar_arg
=
p_py_arg_decl
(
s
,
annotated
=
annotated
)
return
(
args
,
star_arg
,
starstar_arg
)
def
p_py_arg_decl
(
s
):
def
p_py_arg_decl
(
s
,
annotated
=
1
):
pos
=
s
.
position
()
name
=
p_ident
(
s
)
annotation
=
None
if
s
.
sy
==
':'
:
if
annotated
and
s
.
sy
==
':'
:
s
.
next
()
annotation
=
p_test
(
s
)
return
Nodes
.
PyArgDeclNode
(
pos
,
name
=
name
,
annotation
=
annotation
)
...
...
tests/run/lambda_T195.pyx
View file @
8c5adff1
...
...
@@ -76,3 +76,35 @@ def make_typed_lambda_lambda(int x):
"""
return
lambda
int
y
:
\
lambda
int
z
:
x
+
y
+
z
def
pass_lambda
(
f
):
"""
>>> def f(a, lfunc): return lfunc(a,2)
>>> pass_lambda(f)
12
"""
return
f
(
1
,
lambda
a
,
b
:
a
*
10
+
b
)
def
pass_lambda_with_args
(
f
):
"""
>>> def f(a, lfunc): return lfunc(a,2,3)
>>> pass_lambda_with_args(f)
123
"""
return
f
(
1
,
lambda
a
,
*
args
:
(
a
*
10
+
args
[
0
])
*
10
+
args
[
1
])
def
pass_lambda_with_args_kwargs
(
f
):
"""
>>> def f(a, lfunc): return lfunc(a,2,3, b=4)
>>> pass_lambda_with_args_kwargs(f)
1234
"""
return
f
(
1
,
lambda
a
,
*
args
,
**
kwargs
:
((
a
*
10
+
args
[
0
])
*
10
+
args
[
1
])
*
10
+
kwargs
[
'b'
])
def
pass_lambda_with_args_kwargs_kwonly_args
(
f
):
"""
>>> def f(a, lfunc): return lfunc(a,2,3, b=4, c=5)
>>> pass_lambda_with_args_kwargs_kwonly_args(f)
12345
"""
return
f
(
1
,
lambda
a
,
*
args
,
b
,
**
kwargs
:
(((
a
*
10
+
args
[
0
])
*
10
+
args
[
1
])
*
10
+
b
)
*
10
+
kwargs
[
'c'
])
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