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
40d3a67a
Commit
40d3a67a
authored
Dec 09, 2007
by
Amaury Forgeot d'Arc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #1573, second attempt:
"def f(*, **kw)" now raises a SyntaxError.
parent
3279b5df
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
13 deletions
+9
-13
Lib/test/test_ast.py
Lib/test/test_ast.py
+0
-3
Lib/test/test_keywordonlyarg.py
Lib/test/test_keywordonlyarg.py
+1
-7
Python/ast.c
Python/ast.c
+8
-3
No files found.
Lib/test/test_ast.py
View file @
40d3a67a
...
@@ -58,9 +58,6 @@ exec_tests = [
...
@@ -58,9 +58,6 @@ exec_tests = [
"break"
,
"break"
,
# Continue
# Continue
"continue"
,
"continue"
,
# kw only funcs
"def f(*, kw=1): pass"
,
"def f(*, **kw): pass"
,
]
]
# These are compiled through "single"
# These are compiled through "single"
...
...
Lib/test/test_keywordonlyarg.py
View file @
40d3a67a
...
@@ -48,6 +48,7 @@ class KeywordOnlyArgTestCase(unittest.TestCase):
...
@@ -48,6 +48,7 @@ class KeywordOnlyArgTestCase(unittest.TestCase):
self
.
assertRaisesSyntaxError
(
"def f(p1, *, p1=100):
\
n
pass
\
n
"
)
self
.
assertRaisesSyntaxError
(
"def f(p1, *, p1=100):
\
n
pass
\
n
"
)
self
.
assertRaisesSyntaxError
(
"def f(p1, *k1, k1=100):
\
n
pass
\
n
"
)
self
.
assertRaisesSyntaxError
(
"def f(p1, *k1, k1=100):
\
n
pass
\
n
"
)
self
.
assertRaisesSyntaxError
(
"def f(p1, *, k1, k1=100):
\
n
pass
\
n
"
)
self
.
assertRaisesSyntaxError
(
"def f(p1, *, k1, k1=100):
\
n
pass
\
n
"
)
self
.
assertRaisesSyntaxError
(
"def f(p1, *, **k1):
\
n
pass
\
n
"
)
self
.
assertRaisesSyntaxError
(
"def f(p1, *, k1, **k1):
\
n
pass
\
n
"
)
self
.
assertRaisesSyntaxError
(
"def f(p1, *, k1, **k1):
\
n
pass
\
n
"
)
self
.
assertRaisesSyntaxError
(
"def f(p1, *, None, **k1):
\
n
pass
\
n
"
)
self
.
assertRaisesSyntaxError
(
"def f(p1, *, None, **k1):
\
n
pass
\
n
"
)
self
.
assertRaisesSyntaxError
(
"def f(p, *, (k1, k2), **kw):
\
n
pass
\
n
"
)
self
.
assertRaisesSyntaxError
(
"def f(p, *, (k1, k2), **kw):
\
n
pass
\
n
"
)
...
@@ -144,13 +145,6 @@ class KeywordOnlyArgTestCase(unittest.TestCase):
...
@@ -144,13 +145,6 @@ class KeywordOnlyArgTestCase(unittest.TestCase):
except
TypeError
:
except
TypeError
:
pass
pass
def
test_doublestar_only
(
self
):
def
f
(
*
,
**
kw
):
return
kw
self
.
assertEqual
(
f
(),
{})
self
.
assertEqual
(
f
(
k1
=
1
,
k2
=
2
),
{
'k1'
:
1
,
'k2'
:
2
})
def
test_kwonly_methods
(
self
):
def
test_kwonly_methods
(
self
):
class
Example
:
class
Example
:
def
f
(
self
,
*
,
k1
=
1
,
k2
=
2
):
def
f
(
self
,
*
,
k1
=
1
,
k2
=
2
):
...
...
Python/ast.c
View file @
40d3a67a
...
@@ -649,8 +649,12 @@ handle_keywordonly_args(struct compiling *c, const node *n, int start,
...
@@ -649,8 +649,12 @@ handle_keywordonly_args(struct compiling *c, const node *n, int start,
arg_ty
arg
;
arg_ty
arg
;
int
i
=
start
;
int
i
=
start
;
int
j
=
0
;
/* index for kwdefaults and kwonlyargs */
int
j
=
0
;
/* index for kwdefaults and kwonlyargs */
assert
((
kwonlyargs
!=
NULL
&&
kwdefaults
!=
NULL
)
||
TYPE
(
CHILD
(
n
,
i
))
==
DOUBLESTAR
);
if
(
kwonlyargs
==
NULL
)
{
ast_error
(
CHILD
(
n
,
start
),
"named arguments must follow bare *"
);
return
-
1
;
}
assert
(
kwdefaults
!=
NULL
);
while
(
i
<
NCH
(
n
))
{
while
(
i
<
NCH
(
n
))
{
ch
=
CHILD
(
n
,
i
);
ch
=
CHILD
(
n
,
i
);
switch
(
TYPE
(
ch
))
{
switch
(
TYPE
(
ch
))
{
...
@@ -814,7 +818,8 @@ ast_for_arguments(struct compiling *c, const node *n)
...
@@ -814,7 +818,8 @@ ast_for_arguments(struct compiling *c, const node *n)
break
;
break
;
case
STAR
:
case
STAR
:
if
(
i
+
1
>=
NCH
(
n
))
{
if
(
i
+
1
>=
NCH
(
n
))
{
ast_error
(
CHILD
(
n
,
i
),
"no name for vararg"
);
ast_error
(
CHILD
(
n
,
i
),
"named arguments must follow bare *"
);
goto
error
;
goto
error
;
}
}
ch
=
CHILD
(
n
,
i
+
1
);
/* tfpdef or COMMA */
ch
=
CHILD
(
n
,
i
+
1
);
/* tfpdef or COMMA */
...
...
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