File tree Expand file tree Collapse file tree 3 files changed +52
-1
lines changed
resources/test/fixtures/ruff Expand file tree Collapse file tree 3 files changed +52
-1
lines changed Original file line number Diff line number Diff line change 13
13
if k in d and d [(k )]:
14
14
pass
15
15
16
+ not ("key" in dct and dct ["key" ])
17
+
18
+ bool ("key" in dct and dct ["key" ])
19
+
16
20
# OK
17
21
v = "k" in d and d ["k" ]
18
22
Original file line number Diff line number Diff line change @@ -1140,6 +1140,13 @@ impl<'a> Visitor<'a> for Checker<'a> {
1140
1140
self . visit_expr ( body) ;
1141
1141
self . visit_expr ( orelse) ;
1142
1142
}
1143
+ Expr :: UnaryOp ( ast:: ExprUnaryOp {
1144
+ op : UnaryOp :: Not ,
1145
+ operand,
1146
+ range : _,
1147
+ } ) => {
1148
+ self . visit_boolean_test ( operand) ;
1149
+ }
1143
1150
Expr :: Call ( ast:: ExprCall {
1144
1151
func,
1145
1152
arguments,
Original file line number Diff line number Diff line change @@ -77,6 +77,46 @@ RUF019.py:13:4: RUF019 [*] Unnecessary key check before dictionary access
77
77
13 | + if d .get ((k )):
78
78
14 14 | pass
79
79
15 15 |
80
- 16 16 | # OK
80
+ 16 16 | not ( " key " in dct and dct [ " key " ])
81
81
82
+ RUF019 .py :16 :6 : RUF019 [* ] Unnecessary key check before dictionary access
83
+ |
84
+ 14 | pass
85
+ 15 |
86
+ 16 | not (" key" in dct and dct [" key" ])
87
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ RUF019
88
+ 17 |
89
+ 18 | bool (" key" in dct and dct [" key" ])
90
+ |
91
+ = help : Replace with ` dict.get`
82
92
93
+ ℹ Safe fix
94
+ 13 13 | if k in d and d [(k )]:
95
+ 14 14 | pass
96
+ 15 15 |
97
+ 16 | - not (" key" in dct and dct [" key" ])
98
+ 16 | + not (dct .get (" key" ))
99
+ 17 17 |
100
+ 18 18 | bool (" key" in dct and dct [" key" ])
101
+ 19 19 |
102
+
103
+ RUF019 .py :18 :6 : RUF019 [* ] Unnecessary key check before dictionary access
104
+ |
105
+ 16 | not (" key" in dct and dct [" key" ])
106
+ 17 |
107
+ 18 | bool (" key" in dct and dct [" key" ])
108
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ RUF019
109
+ 19 |
110
+ 20 | # OK
111
+ |
112
+ = help : Replace with ` dict.get`
113
+
114
+ ℹ Safe fix
115
+ 15 15 |
116
+ 16 16 | not (" key" in dct and dct [" key" ])
117
+ 17 17 |
118
+ 18 | - bool (" key" in dct and dct [" key" ])
119
+ 18 | + bool (dct .get (" key" ))
120
+ 19 19 |
121
+ 20 20 | # OK
122
+ 21 21 | v = " k" in d and d [" k" ]
You can’t perform that action at this time.
0 commit comments