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
da6129e8
Commit
da6129e8
authored
May 18, 2019
by
Pablo Galindo
Committed by
GitHub
May 18, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-36961: Handle positional-only arguments in uparse.c (GH-13412)
parent
fa19a25c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
6 deletions
+28
-6
Lib/test/test_future.py
Lib/test/test_future.py
+12
-0
Python/ast_unparse.c
Python/ast_unparse.c
+16
-6
No files found.
Lib/test/test_future.py
View file @
da6129e8
...
...
@@ -183,6 +183,18 @@ class AnnotationsFutureTestCase(unittest.TestCase):
eq
(
'lambda a, b, c=True: a'
)
eq
(
"lambda a, b, c=True, *, d=1 << v2, e='str': a"
)
eq
(
"lambda a, b, c=True, *vararg, d, e='str', **kwargs: a + b"
)
eq
(
"lambda a, /, b, c=True, *vararg, d, e='str', **kwargs: a + b"
)
eq
(
'lambda x, /: x'
)
eq
(
'lambda x=1, /: x'
)
eq
(
'lambda x, /, y: x + y'
)
eq
(
'lambda x=1, /, y=2: x + y'
)
eq
(
'lambda x, /, y=1: x + y'
)
eq
(
'lambda x, /, y=1, *, z=3: x + y + z'
)
eq
(
'lambda x=1, /, y=2, *, z=3: x + y + z'
)
eq
(
'lambda x=1, /, y=2, *, z: x + y + z'
)
eq
(
'lambda x=1, y=2, z=3, /, w=4, *, l, l2: x + y + z + w + l + l2'
)
eq
(
'lambda x=1, y=2, z=3, /, w=4, *, l, l2, **kwargs: x + y + z + w + l + l2'
)
eq
(
'lambda x, /, y=1, *, z: x + y + z'
)
eq
(
'lambda x: lambda y: x + y'
)
eq
(
'1 if True else 2'
)
eq
(
'str or None if int or True else str or bytes or None'
)
...
...
Python/ast_unparse.c
View file @
da6129e8
...
...
@@ -193,22 +193,30 @@ static int
append_ast_args
(
_PyUnicodeWriter
*
writer
,
arguments_ty
args
)
{
bool
first
;
Py_ssize_t
i
,
di
,
arg_count
,
default_count
;
Py_ssize_t
i
,
di
,
arg_count
,
posonlyarg_count
,
default_count
;
first
=
true
;
/* positional arguments with defaults */
/* positional-only and positional arguments with defaults */
posonlyarg_count
=
asdl_seq_LEN
(
args
->
posonlyargs
);
arg_count
=
asdl_seq_LEN
(
args
->
args
);
default_count
=
asdl_seq_LEN
(
args
->
defaults
);
for
(
i
=
0
;
i
<
arg_count
;
i
++
)
{
for
(
i
=
0
;
i
<
posonlyarg_count
+
arg_count
;
i
++
)
{
APPEND_STR_IF_NOT_FIRST
(
", "
);
APPEND
(
arg
,
(
arg_ty
)
asdl_seq_GET
(
args
->
args
,
i
));
if
(
i
<
posonlyarg_count
){
APPEND
(
arg
,
(
arg_ty
)
asdl_seq_GET
(
args
->
posonlyargs
,
i
));
}
else
{
APPEND
(
arg
,
(
arg_ty
)
asdl_seq_GET
(
args
->
args
,
i
-
posonlyarg_count
));
}
di
=
i
-
arg_count
+
default_count
;
di
=
i
-
posonlyarg_count
-
arg_count
+
default_count
;
if
(
di
>=
0
)
{
APPEND_STR
(
"="
);
APPEND_EXPR
((
expr_ty
)
asdl_seq_GET
(
args
->
defaults
,
di
),
PR_TEST
);
}
if
(
posonlyarg_count
&&
i
+
1
==
posonlyarg_count
)
{
APPEND_STR
(
", /"
);
}
}
/* vararg, or bare '*' if no varargs but keyword-only arguments present */
...
...
@@ -251,7 +259,9 @@ static int
append_ast_lambda
(
_PyUnicodeWriter
*
writer
,
expr_ty
e
,
int
level
)
{
APPEND_STR_IF
(
level
>
PR_TEST
,
"("
);
APPEND_STR
(
asdl_seq_LEN
(
e
->
v
.
Lambda
.
args
->
args
)
?
"lambda "
:
"lambda"
);
Py_ssize_t
n_positional
=
(
asdl_seq_LEN
(
e
->
v
.
Lambda
.
args
->
args
)
+
asdl_seq_LEN
(
e
->
v
.
Lambda
.
args
->
posonlyargs
));
APPEND_STR
(
n_positional
?
"lambda "
:
"lambda"
);
APPEND
(
args
,
e
->
v
.
Lambda
.
args
);
APPEND_STR
(
": "
);
APPEND_EXPR
(
e
->
v
.
Lambda
.
body
,
PR_TEST
);
...
...
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