mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-08 13:45:01 +08:00
Add positional only arguments to grammar
This commit is contained in:
@@ -20,13 +20,25 @@ async_funcdef: 'async' funcdef
|
|||||||
funcdef: 'def' NAME parameters ['->' test] ':' suite
|
funcdef: 'def' NAME parameters ['->' test] ':' suite
|
||||||
|
|
||||||
parameters: '(' [typedargslist] ')'
|
parameters: '(' [typedargslist] ')'
|
||||||
typedargslist: (tfpdef ['=' test] (',' tfpdef ['=' test])* [',' [
|
typedargslist: (
|
||||||
|
(tfpdef ['=' test] (',' tfpdef ['=' test])* ',' '/' [',' [ tfpdef ['=' test] (
|
||||||
|
',' tfpdef ['=' test])* ([',' [
|
||||||
|
'*' [tfpdef] (',' tfpdef ['=' test])* [',' ['**' tfpdef [',']]]
|
||||||
|
| '**' tfpdef [',']]])
|
||||||
|
| '*' [tfpdef] (',' tfpdef ['=' test])* ([',' ['**' tfpdef [',']]])
|
||||||
|
| '**' tfpdef [',']]] )
|
||||||
|
| (tfpdef ['=' test] (',' tfpdef ['=' test])* [',' [
|
||||||
'*' [tfpdef] (',' tfpdef ['=' test])* [',' ['**' tfpdef [',']]]
|
'*' [tfpdef] (',' tfpdef ['=' test])* [',' ['**' tfpdef [',']]]
|
||||||
| '**' tfpdef [',']]]
|
| '**' tfpdef [',']]]
|
||||||
| '*' [tfpdef] (',' tfpdef ['=' test])* [',' ['**' tfpdef [',']]]
|
| '*' [tfpdef] (',' tfpdef ['=' test])* [',' ['**' tfpdef [',']]]
|
||||||
| '**' tfpdef [','])
|
| '**' tfpdef [','])
|
||||||
|
)
|
||||||
tfpdef: NAME [':' test]
|
tfpdef: NAME [':' test]
|
||||||
varargslist: (vfpdef ['=' test] (',' vfpdef ['=' test])* [',' [
|
varargslist: vfpdef ['=' test ](',' vfpdef ['=' test])* ',' '/' [',' [ (vfpdef ['=' test] (',' vfpdef ['=' test])* [',' [
|
||||||
|
'*' [vfpdef] (',' vfpdef ['=' test])* [',' ['**' vfpdef [',']]]
|
||||||
|
| '**' vfpdef [',']]]
|
||||||
|
| '*' [vfpdef] (',' vfpdef ['=' test])* [',' ['**' vfpdef [',']]]
|
||||||
|
| '**' vfpdef [',']) ]] | (vfpdef ['=' test] (',' vfpdef ['=' test])* [',' [
|
||||||
'*' [vfpdef] (',' vfpdef ['=' test])* [',' ['**' vfpdef [',']]]
|
'*' [vfpdef] (',' vfpdef ['=' test])* [',' ['**' vfpdef [',']]]
|
||||||
| '**' vfpdef [',']]]
|
| '**' vfpdef [',']]]
|
||||||
| '*' [vfpdef] (',' vfpdef ['=' test])* [',' ['**' vfpdef [',']]]
|
| '*' [vfpdef] (',' vfpdef ['=' test])* [',' ['**' vfpdef [',']]]
|
||||||
|
|||||||
@@ -193,3 +193,18 @@ def test_no_error_nodes(each_version):
|
|||||||
|
|
||||||
def test_named_expression(works_ge_py38):
|
def test_named_expression(works_ge_py38):
|
||||||
works_ge_py38.parse("(a := 1, a + 1)")
|
works_ge_py38.parse("(a := 1, a + 1)")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
'param_code', [
|
||||||
|
'a=1, /',
|
||||||
|
'a, /',
|
||||||
|
'a=1, /, b=3',
|
||||||
|
'a, /, b',
|
||||||
|
'a, /, b',
|
||||||
|
'a, /, *, b',
|
||||||
|
'a, /, **kwargs',
|
||||||
|
]
|
||||||
|
)
|
||||||
|
def test_positional_only_arguments(works_ge_py38, param_code):
|
||||||
|
works_ge_py38.parse("def x(%s): pass" % param_code)
|
||||||
|
|||||||
Reference in New Issue
Block a user