mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-07 05:14:29 +08:00
Unparenthesized lambda no longer allowed in comp_if since Python 3.9
This commit is contained in:
@@ -97,9 +97,7 @@ suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT
|
|||||||
|
|
||||||
namedexpr_test: test [':=' test]
|
namedexpr_test: test [':=' test]
|
||||||
test: or_test ['if' or_test 'else' test] | lambdef
|
test: or_test ['if' or_test 'else' test] | lambdef
|
||||||
test_nocond: or_test | lambdef_nocond
|
|
||||||
lambdef: 'lambda' [varargslist] ':' test
|
lambdef: 'lambda' [varargslist] ':' test
|
||||||
lambdef_nocond: 'lambda' [varargslist] ':' test_nocond
|
|
||||||
or_test: and_test ('or' and_test)*
|
or_test: and_test ('or' and_test)*
|
||||||
and_test: not_test ('and' not_test)*
|
and_test: not_test ('and' not_test)*
|
||||||
not_test: 'not' not_test | comparison
|
not_test: 'not' not_test | comparison
|
||||||
@@ -155,7 +153,7 @@ argument: ( test [comp_for] |
|
|||||||
comp_iter: comp_for | comp_if
|
comp_iter: comp_for | comp_if
|
||||||
sync_comp_for: 'for' exprlist 'in' or_test [comp_iter]
|
sync_comp_for: 'for' exprlist 'in' or_test [comp_iter]
|
||||||
comp_for: ['async'] sync_comp_for
|
comp_for: ['async'] sync_comp_for
|
||||||
comp_if: 'if' test_nocond [comp_iter]
|
comp_if: 'if' or_test [comp_iter]
|
||||||
|
|
||||||
# not used in grammar, but may appear in "node" passed from Parser to Compiler
|
# not used in grammar, but may appear in "node" passed from Parser to Compiler
|
||||||
encoding_decl: NAME
|
encoding_decl: NAME
|
||||||
|
|||||||
@@ -97,9 +97,7 @@ suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT
|
|||||||
|
|
||||||
namedexpr_test: test [':=' test]
|
namedexpr_test: test [':=' test]
|
||||||
test: or_test ['if' or_test 'else' test] | lambdef
|
test: or_test ['if' or_test 'else' test] | lambdef
|
||||||
test_nocond: or_test | lambdef_nocond
|
|
||||||
lambdef: 'lambda' [varargslist] ':' test
|
lambdef: 'lambda' [varargslist] ':' test
|
||||||
lambdef_nocond: 'lambda' [varargslist] ':' test_nocond
|
|
||||||
or_test: and_test ('or' and_test)*
|
or_test: and_test ('or' and_test)*
|
||||||
and_test: not_test ('and' not_test)*
|
and_test: not_test ('and' not_test)*
|
||||||
not_test: 'not' not_test | comparison
|
not_test: 'not' not_test | comparison
|
||||||
@@ -155,7 +153,7 @@ argument: ( test [comp_for] |
|
|||||||
comp_iter: comp_for | comp_if
|
comp_iter: comp_for | comp_if
|
||||||
sync_comp_for: 'for' exprlist 'in' or_test [comp_iter]
|
sync_comp_for: 'for' exprlist 'in' or_test [comp_iter]
|
||||||
comp_for: ['async'] sync_comp_for
|
comp_for: ['async'] sync_comp_for
|
||||||
comp_if: 'if' test_nocond [comp_iter]
|
comp_if: 'if' or_test [comp_iter]
|
||||||
|
|
||||||
# not used in grammar, but may appear in "node" passed from Parser to Compiler
|
# not used in grammar, but may appear in "node" passed from Parser to Compiler
|
||||||
encoding_decl: NAME
|
encoding_decl: NAME
|
||||||
|
|||||||
@@ -494,3 +494,14 @@ def test_valid_empty_assignment(code):
|
|||||||
)
|
)
|
||||||
def test_valid_del(code):
|
def test_valid_del(code):
|
||||||
assert not _get_error_list(code)
|
assert not _get_error_list(code)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
('source', 'version', 'no_errors'), [
|
||||||
|
('[x for x in range(10) if lambda: 1]', '3.8', True),
|
||||||
|
('[x for x in range(10) if lambda: 1]', '3.9', False),
|
||||||
|
('[x for x in range(10) if (lambda: 1)]', '3.9', True),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
def test_lambda_in_comp_if(source, version, no_errors):
|
||||||
|
assert bool(_get_error_list(source, version=version)) ^ no_errors
|
||||||
|
|||||||
Reference in New Issue
Block a user