File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change 4
4
from lark import Tree , Token
5
5
6
6
from ..common .utils import find_name_token_among_children
7
+ from ..formatter .expression_utils import remove_outer_parentheses
7
8
8
9
from .problem import Problem
9
10
@@ -62,9 +63,10 @@ def _expression_not_assigned_check(parse_tree: Tree) -> List[Problem]:
62
63
problems = []
63
64
for expr_stmt in parse_tree .find_data ("expr_stmt" ):
64
65
expr = expr_stmt .children [0 ]
65
- child = expr .children [0 ]
66
- if not isinstance (child , Tree ) or child .data not in [
66
+ actual_expression = remove_outer_parentheses ( expr .children [0 ])
67
+ if not isinstance (actual_expression , Tree ) or actual_expression .data not in [
67
68
"assnmnt_expr" ,
69
+ "await_expr" ,
68
70
"standalone_call" ,
69
71
"getattr_call" ,
70
72
"string" ,
@@ -75,8 +77,8 @@ def _expression_not_assigned_check(parse_tree: Tree) -> List[Problem]:
75
77
description = (
76
78
"expression is not asigned, and hence it can be removed"
77
79
),
78
- line = child .line ,
79
- column = child .column ,
80
+ line = actual_expression .line ,
81
+ column = actual_expression .column ,
80
82
)
81
83
)
82
84
return problems
Original file line number Diff line number Diff line change 29
29
"""
30
30
func foo():
31
31
'''docstr'''
32
+ """ ,
33
+ """
34
+ func foo():
35
+ await get_tree().create_timer(2.0).timeout
36
+ """ ,
32
37
"""
38
+ func foo():
39
+ ('''docstr''')
40
+ """ ,
33
41
])
34
42
def test_expression_not_assigned_ok (code ):
35
43
simple_ok_check (code )
@@ -42,6 +50,9 @@ def test_expression_not_assigned_ok(code):
42
50
"""func foo():
43
51
true
44
52
""" ,
53
+ """func foo():
54
+ (true)
55
+ """ ,
45
56
])
46
57
def test_expression_not_assigned_nok (code ):
47
58
simple_nok_check (code , 'expression-not-assigned' )
You can’t perform that action at this time.
0 commit comments