flake8_simplify 0.20.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- flake8_simplify/__init__.py +177 -0
- flake8_simplify/constants.py +7 -0
- flake8_simplify/rules/__init__.py +0 -0
- flake8_simplify/rules/ast_assign.py +116 -0
- flake8_simplify/rules/ast_bool_op.py +219 -0
- flake8_simplify/rules/ast_call.py +235 -0
- flake8_simplify/rules/ast_classdef.py +24 -0
- flake8_simplify/rules/ast_compare.py +90 -0
- flake8_simplify/rules/ast_expr.py +103 -0
- flake8_simplify/rules/ast_for.py +207 -0
- flake8_simplify/rules/ast_if.py +515 -0
- flake8_simplify/rules/ast_ifexp.py +68 -0
- flake8_simplify/rules/ast_subscript.py +59 -0
- flake8_simplify/rules/ast_try.py +96 -0
- flake8_simplify/rules/ast_unary_op.py +106 -0
- flake8_simplify/rules/ast_with.py +62 -0
- flake8_simplify/utils.py +247 -0
- flake8_simplify-0.20.0.dist-info/LICENSE +21 -0
- flake8_simplify-0.20.0.dist-info/METADATA +656 -0
- flake8_simplify-0.20.0.dist-info/RECORD +22 -0
- flake8_simplify-0.20.0.dist-info/WHEEL +4 -0
- flake8_simplify-0.20.0.dist-info/entry_points.txt +3 -0
|
@@ -0,0 +1,656 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: flake8_simplify
|
|
3
|
+
Version: 0.20.0
|
|
4
|
+
Summary: flake8 plugin which checks for code that can be simplified
|
|
5
|
+
Keywords: flake8
|
|
6
|
+
Author-email: Martin Thoma <info@martin-thoma.de>
|
|
7
|
+
Maintainer-email: Martin Thoma <info@martin-thoma.de>
|
|
8
|
+
Requires-Python: >=3.6.1
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Environment :: Console
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Natural Language :: English
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
+
Classifier: Topic :: Software Development
|
|
23
|
+
Classifier: Framework :: Flake8
|
|
24
|
+
Requires-Dist: astor>=0.1
|
|
25
|
+
Requires-Dist: flake8>=3.7
|
|
26
|
+
Requires-Dist: importlib-metadata>=0.9; python_version < "3.8"
|
|
27
|
+
Project-URL: Homepage, https://github.com/MartinThoma/flake8-simplify
|
|
28
|
+
|
|
29
|
+
[](https://badge.fury.io/py/flake8-simplify)
|
|
30
|
+
[](https://github.com/MartinThoma/flake8-simplify)
|
|
31
|
+
[](https://github.com/MartinThoma/flake8-simplify/actions)
|
|
32
|
+
[](https://github.com/psf/black)
|
|
33
|
+
|
|
34
|
+
# flake8-simplify
|
|
35
|
+
|
|
36
|
+
A [flake8](https://flake8.pycqa.org/en/latest/index.html) plugin that helps you simplify your code.
|
|
37
|
+
|
|
38
|
+
## Installation
|
|
39
|
+
|
|
40
|
+
Install with `pip`:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pip install flake8-simplify
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Python 3.6 to 3.10 are supported.
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
## Usage
|
|
50
|
+
|
|
51
|
+
Just call `flake8 .` in your package or `flake your.py`:
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
$ flake8 .
|
|
55
|
+
./foo/__init__.py:690:12: SIM101 Multiple isinstance-calls which can be merged into a single call for variable 'other'
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
## Rules
|
|
60
|
+
|
|
61
|
+
Python-specific rules:
|
|
62
|
+
|
|
63
|
+
* `SIM101`: Multiple isinstance-calls which can be merged into a single call by
|
|
64
|
+
using a tuple as a second argument ([example](#SIM101))
|
|
65
|
+
* [`SIM104`](https://github.com/MartinThoma/flake8-simplify/issues/4) : Use 'yield from iterable' (introduced in Python 3.3, see [PEP 380](https://docs.python.org/3/whatsnew/3.3.html#pep-380)) ([example](#SIM104))
|
|
66
|
+
* [`SIM105`](https://github.com/MartinThoma/flake8-simplify/issues/5): Use ['contextlib.suppress(...)'](https://docs.python.org/3/library/contextlib.html#contextlib.suppress) instead of try-except-pass ([example](#SIM105))
|
|
67
|
+
* [`SIM107`](https://github.com/MartinThoma/flake8-simplify/issues/9): Don't use `return` in try/except and finally ([example](#SIM107))
|
|
68
|
+
* [`SIM108`](https://github.com/MartinThoma/flake8-simplify/issues/12): Use the ternary operator if it's reasonable ([example](#SIM108))
|
|
69
|
+
* [`SIM109`](https://github.com/MartinThoma/flake8-simplify/issues/11): Use a tuple to compare a value against multiple values ([example](#SIM109))
|
|
70
|
+
* [`SIM110`](https://github.com/MartinThoma/flake8-simplify/issues/15): Use [any(...)](https://docs.python.org/3/library/functions.html#any) ([example](#SIM110))
|
|
71
|
+
* [`SIM111`](https://github.com/MartinThoma/flake8-simplify/issues/15): Use [all(...)](https://docs.python.org/3/library/functions.html#all) ([example](#SIM111))
|
|
72
|
+
* [`SIM113`](https://github.com/MartinThoma/flake8-simplify/issues/18): Use enumerate instead of manually incrementing a counter ([example](#SIM113))
|
|
73
|
+
* [`SIM114`](https://github.com/MartinThoma/flake8-simplify/issues/10): Combine conditions via a logical or to prevent duplicating code ([example](#SIM114))
|
|
74
|
+
* [`SIM115`](https://github.com/MartinThoma/flake8-simplify/issues/17): Use context handler for opening files ([example](#SIM115))
|
|
75
|
+
* [`SIM116`](https://github.com/MartinThoma/flake8-simplify/issues/31): Use a dictionary instead of many if/else equality checks ([example](#SIM116))
|
|
76
|
+
* [`SIM117`](https://github.com/MartinThoma/flake8-simplify/issues/35): Merge with-statements that use the same scope ([example](#SIM117))
|
|
77
|
+
* `SIM119`:  Moved to [flake8-scream](https://github.com/MartinThoma/flake8-scream) due to [issue 63](https://github.com/MartinThoma/flake8-simplify/issues/63)
|
|
78
|
+
* `SIM120` : Use 'class FooBar:' instead of 'class FooBar(object):' ([example](#SIM120))
|
|
79
|
+
* `SIM121`: Reserved for [SIM908](#sim908) once it's stable
|
|
80
|
+
* `SIM125`: Reserved for [SIM905](#sim905) once it's stable
|
|
81
|
+
* `SIM126`: Reserved for [SIM906](#sim906) once it's stable
|
|
82
|
+
* `SIM127`: Reserved for [SIM907](#sim907) once it's stable
|
|
83
|
+
|
|
84
|
+
Simplifying Comparisons:
|
|
85
|
+
|
|
86
|
+
* `SIM201`: Use 'a != b' instead of 'not a == b' ([example](#SIM201))
|
|
87
|
+
* `SIM202`: Use 'a == b' instead of 'not a != b' ([example](#SIM202))
|
|
88
|
+
* `SIM203`: Use 'a not in b' instead of 'not (a in b)' ([example](#SIM203))
|
|
89
|
+
* `SIM204`:  Moved to [flake8-scream](https://github.com/MartinThoma/flake8-scream) due to [issue 116](https://github.com/MartinThoma/flake8-simplify/issues/116)
|
|
90
|
+
* `SIM205`:  Moved to [flake8-scream](https://github.com/MartinThoma/flake8-scream) due to [issue 116](https://github.com/MartinThoma/flake8-simplify/issues/116)
|
|
91
|
+
* `SIM206`:  Moved to [flake8-scream](https://github.com/MartinThoma/flake8-scream) due to [issue 116](https://github.com/MartinThoma/flake8-simplify/issues/116)
|
|
92
|
+
* `SIM207`:  Moved to [flake8-scream](https://github.com/MartinThoma/flake8-scream) due to [issue 116](https://github.com/MartinThoma/flake8-simplify/issues/116)
|
|
93
|
+
* `SIM208`: Use 'a' instead of 'not (not a)' ([example](#SIM208))
|
|
94
|
+
* `SIM210`: Use 'bool(a)' instead of 'True if a else False' ([example](#SIM210))
|
|
95
|
+
* `SIM211`: Use 'not a' instead of 'False if a else True' ([example](#SIM211))
|
|
96
|
+
* [`SIM212`](https://github.com/MartinThoma/flake8-simplify/issues/6): Use 'a if a else b' instead of 'b if not a else a' ([example](#SIM212))
|
|
97
|
+
* [`SIM220`](https://github.com/MartinThoma/flake8-simplify/issues/6): Use 'False' instead of 'a and not a' ([example](#SIM220))
|
|
98
|
+
* [`SIM221`](https://github.com/MartinThoma/flake8-simplify/issues/6): Use 'True' instead of 'a or not a' ([example](#SIM221))
|
|
99
|
+
* [`SIM222`](https://github.com/MartinThoma/flake8-simplify/issues/6): Use 'True' instead of '... or True' ([example](#SIM222))
|
|
100
|
+
* [`SIM223`](https://github.com/MartinThoma/flake8-simplify/issues/6): Use 'False' instead of '... and False' ([example](#SIM223))
|
|
101
|
+
* [`SIM224`](https://github.com/MartinThoma/flake8-simplify/issues/88): Reserved for [SIM901](#sim901) once it's stable
|
|
102
|
+
* [`SIM300`](https://github.com/MartinThoma/flake8-simplify/issues/16): Use 'age == 42' instead of '42 == age' ([example](#SIM300))
|
|
103
|
+
|
|
104
|
+
Simplifying usage of dictionaries:
|
|
105
|
+
|
|
106
|
+
* [`SIM401`](https://github.com/MartinThoma/flake8-simplify/issues/72): Use 'a_dict.get(key, "default_value")' instead of an if-block ([example](#SIM401))
|
|
107
|
+
* [`SIM118`](https://github.com/MartinThoma/flake8-simplify/issues/40): Use 'key in dict' instead of 'key in dict.keys()' ([example](#SIM118))
|
|
108
|
+
|
|
109
|
+
General Code Style:
|
|
110
|
+
|
|
111
|
+
* `SIM102`: Use a single if-statement instead of nested if-statements ([example](#SIM102))
|
|
112
|
+
* [`SIM103`](https://github.com/MartinThoma/flake8-simplify/issues/3): Return the boolean condition directly ([example](#SIM103))
|
|
113
|
+
* [`SIM106`](https://github.com/MartinThoma/flake8-simplify/issues/8): Handle error-cases first ([example](#SIM106)). This rule was removed due to too many false-positives.
|
|
114
|
+
* [`SIM112`](https://github.com/MartinThoma/flake8-simplify/issues/19): Use CAPITAL environment variables ([example](#SIM112))
|
|
115
|
+
* `SIM122` / SIM902:  Moved to [flake8-scream](https://github.com/MartinThoma/flake8-scream) due to [issue 125](https://github.com/MartinThoma/flake8-simplify/issues/125)
|
|
116
|
+
* `SIM123` / SIM902:  Moved to [flake8-scream](https://github.com/MartinThoma/flake8-scream) due to [issue 130](https://github.com/MartinThoma/flake8-simplify/issues/130)
|
|
117
|
+
* `SIM124`: Reserved for SIM909 once it's stable
|
|
118
|
+
|
|
119
|
+
**Experimental rules:**
|
|
120
|
+
|
|
121
|
+
Getting rules right for every possible case is hard. I don't want to disturb
|
|
122
|
+
peoples workflows. For this reason, flake8-simplify introduces new rules with
|
|
123
|
+
the `SIM9` prefix. Every new rule will start with SIM9 and stay there for at
|
|
124
|
+
least 6 months. In this time people can give feedback. Once the rule is stable,
|
|
125
|
+
the code will change to another number.
|
|
126
|
+
|
|
127
|
+
Current experimental rules:
|
|
128
|
+
|
|
129
|
+
* `SIM901`: Use comparisons directly instead of wrapping them in a `bool(...)` call ([example](#SIM901))
|
|
130
|
+
* `SIM904`: Assign values to dictionary directly at initialization ([example](#SIM904))
|
|
131
|
+
* [`SIM905`](https://github.com/MartinThoma/flake8-simplify/issues/86): Split string directly if only constants are used ([example](#SIM905))
|
|
132
|
+
* [`SIM906`](https://github.com/MartinThoma/flake8-simplify/issues/101): Merge nested os.path.join calls ([example](#SIM906))
|
|
133
|
+
* [`SIM907`](https://github.com/MartinThoma/flake8-simplify/issues/64): Use Optional[Type] instead of Union[Type, None] ([example](#SIM907))
|
|
134
|
+
* [`SIM908`](https://github.com/MartinThoma/flake8-simplify/issues/50): Use dict.get(key) ([example](#SIM908))
|
|
135
|
+
* [`SIM909`](https://github.com/MartinThoma/flake8-simplify/issues/114): Avoid reflexive assignments ([example](#SIM909))
|
|
136
|
+
* [`SIM910`](https://github.com/MartinThoma/flake8-simplify/issues/171): Avoid to use `dict.get(key, None)` ([example](#SIM910))
|
|
137
|
+
|
|
138
|
+
## Disabling Rules
|
|
139
|
+
|
|
140
|
+
You might have good reasons to
|
|
141
|
+
[ignore some flake8 rules](https://flake8.pycqa.org/en/3.1.1/user/ignoring-errors.html).
|
|
142
|
+
To do that, use the standard Flake8 configuration. For example, within the `setup.cfg` file:
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
[flake8]
|
|
146
|
+
ignore = SIM106, SIM113, SIM119, SIM9
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
## Examples
|
|
151
|
+
|
|
152
|
+
### SIM101
|
|
153
|
+
|
|
154
|
+
```python
|
|
155
|
+
# Bad
|
|
156
|
+
isinstance(a, int) or isinstance(a, float)
|
|
157
|
+
|
|
158
|
+
# Good
|
|
159
|
+
isinstance(a, (int, float))
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### SIM102
|
|
163
|
+
|
|
164
|
+
```python
|
|
165
|
+
# Bad
|
|
166
|
+
if a:
|
|
167
|
+
if b:
|
|
168
|
+
c
|
|
169
|
+
|
|
170
|
+
# Good
|
|
171
|
+
if a and b:
|
|
172
|
+
c
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### SIM105
|
|
176
|
+
|
|
177
|
+
```python
|
|
178
|
+
# Bad
|
|
179
|
+
try:
|
|
180
|
+
foo()
|
|
181
|
+
except ValueError:
|
|
182
|
+
pass
|
|
183
|
+
|
|
184
|
+
# Good
|
|
185
|
+
from contextlib import suppress
|
|
186
|
+
|
|
187
|
+
with suppress(ValueError):
|
|
188
|
+
foo()
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Please note that `contextlib.suppress` is roughly 3x slower than `try/except`
|
|
192
|
+
([source](https://github.com/MartinThoma/flake8-simplify/issues/91)).
|
|
193
|
+
|
|
194
|
+
### SIM107
|
|
195
|
+
|
|
196
|
+
```python
|
|
197
|
+
# Bad: This example returns 3!
|
|
198
|
+
def foo():
|
|
199
|
+
try:
|
|
200
|
+
1 / 0
|
|
201
|
+
return "1"
|
|
202
|
+
except:
|
|
203
|
+
return "2"
|
|
204
|
+
finally:
|
|
205
|
+
return "3"
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
# Good
|
|
209
|
+
def foo():
|
|
210
|
+
return_value = None
|
|
211
|
+
try:
|
|
212
|
+
1 / 0
|
|
213
|
+
return_value = "1"
|
|
214
|
+
except:
|
|
215
|
+
return_value = "2"
|
|
216
|
+
finally:
|
|
217
|
+
return_value = "3" # you might also want to check if "except" happened
|
|
218
|
+
return return_value
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### SIM108
|
|
222
|
+
|
|
223
|
+
```python
|
|
224
|
+
# Bad
|
|
225
|
+
if a:
|
|
226
|
+
b = c
|
|
227
|
+
else:
|
|
228
|
+
b = d
|
|
229
|
+
|
|
230
|
+
# Good
|
|
231
|
+
b = c if a else d
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### SIM109
|
|
235
|
+
|
|
236
|
+
```python
|
|
237
|
+
# Bad
|
|
238
|
+
if a == b or a == c:
|
|
239
|
+
d
|
|
240
|
+
|
|
241
|
+
# Good
|
|
242
|
+
if a in (b, c):
|
|
243
|
+
d
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
### SIM110
|
|
247
|
+
|
|
248
|
+
```python
|
|
249
|
+
# Bad
|
|
250
|
+
for x in iterable:
|
|
251
|
+
if check(x):
|
|
252
|
+
return True
|
|
253
|
+
return False
|
|
254
|
+
|
|
255
|
+
# Good
|
|
256
|
+
return any(check(x) for x in iterable)
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### SIM111
|
|
260
|
+
|
|
261
|
+
```python
|
|
262
|
+
# Bad
|
|
263
|
+
for x in iterable:
|
|
264
|
+
if check(x):
|
|
265
|
+
return False
|
|
266
|
+
return True
|
|
267
|
+
|
|
268
|
+
# Good
|
|
269
|
+
return all(not check(x) for x in iterable)
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
### SIM112
|
|
273
|
+
|
|
274
|
+
```python
|
|
275
|
+
# Bad
|
|
276
|
+
os.environ["foo"]
|
|
277
|
+
os.environ.get("bar")
|
|
278
|
+
|
|
279
|
+
# Good
|
|
280
|
+
os.environ["FOO"]
|
|
281
|
+
os.environ.get("BAR")
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
### SIM113
|
|
285
|
+
|
|
286
|
+
Using [`enumerate`](https://docs.python.org/3/library/functions.html#enumerate) in simple cases like the loops below is a tiny bit easier to read as the reader does not have to figure out where / when the loop variable is incremented (or if it is incremented in multiple places).
|
|
287
|
+
|
|
288
|
+
```python
|
|
289
|
+
# Bad
|
|
290
|
+
idx = 0
|
|
291
|
+
for el in iterable:
|
|
292
|
+
...
|
|
293
|
+
idx += 1
|
|
294
|
+
|
|
295
|
+
# Good
|
|
296
|
+
for idx, el in enumerate(iterable):
|
|
297
|
+
...
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
### SIM114
|
|
301
|
+
|
|
302
|
+
```python
|
|
303
|
+
# Bad
|
|
304
|
+
if a:
|
|
305
|
+
b
|
|
306
|
+
elif c:
|
|
307
|
+
b
|
|
308
|
+
|
|
309
|
+
# Good
|
|
310
|
+
if a or c:
|
|
311
|
+
b
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
### SIM115
|
|
315
|
+
|
|
316
|
+
```python
|
|
317
|
+
# Bad
|
|
318
|
+
f = open(...)
|
|
319
|
+
... # (do something with f)
|
|
320
|
+
f.close()
|
|
321
|
+
|
|
322
|
+
# Good
|
|
323
|
+
with open(...) as f:
|
|
324
|
+
... # (do something with f)
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
### SIM116
|
|
328
|
+
|
|
329
|
+
```python
|
|
330
|
+
# Bad
|
|
331
|
+
if a == "foo":
|
|
332
|
+
return "bar"
|
|
333
|
+
elif a == "bar":
|
|
334
|
+
return "baz"
|
|
335
|
+
elif a == "boo":
|
|
336
|
+
return "ooh"
|
|
337
|
+
else:
|
|
338
|
+
return 42
|
|
339
|
+
|
|
340
|
+
# Good
|
|
341
|
+
mapping = {"foo": "bar", "bar": "baz", "boo": "ooh"}
|
|
342
|
+
return mapping.get(a, 42)
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
### SIM117
|
|
346
|
+
|
|
347
|
+
```python
|
|
348
|
+
# Bad
|
|
349
|
+
with A() as a:
|
|
350
|
+
with B() as b:
|
|
351
|
+
print("hello")
|
|
352
|
+
|
|
353
|
+
# Good
|
|
354
|
+
with A() as a, B() as b:
|
|
355
|
+
print("hello")
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
Thank you for pointing this one out, [Aaron Gokaslan](https://github.com/Skylion007)!
|
|
359
|
+
|
|
360
|
+
### SIM118
|
|
361
|
+
|
|
362
|
+
```python
|
|
363
|
+
# Bad
|
|
364
|
+
key in a_dict.keys()
|
|
365
|
+
|
|
366
|
+
# Good
|
|
367
|
+
key in a_dict
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
Thank you for pointing this one out, [Aaron Gokaslan](https://github.com/Skylion007)!
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
### SIM120
|
|
374
|
+
|
|
375
|
+
```python
|
|
376
|
+
# Bad
|
|
377
|
+
class FooBar(object):
|
|
378
|
+
...
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
# Good
|
|
382
|
+
class FooBar:
|
|
383
|
+
...
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
Both notations are equivalent in Python 3, but the second one is shorter.
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
### SIM201
|
|
390
|
+
|
|
391
|
+
```python
|
|
392
|
+
# Bad
|
|
393
|
+
not a == b
|
|
394
|
+
|
|
395
|
+
# Good
|
|
396
|
+
a != b
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
### SIM202
|
|
400
|
+
|
|
401
|
+
```python
|
|
402
|
+
# Bad
|
|
403
|
+
not a != b
|
|
404
|
+
|
|
405
|
+
# Good
|
|
406
|
+
a == b
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
### SIM203
|
|
410
|
+
|
|
411
|
+
```python
|
|
412
|
+
# Bad
|
|
413
|
+
not a in b
|
|
414
|
+
|
|
415
|
+
# Good
|
|
416
|
+
a not in b
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
### SIM208
|
|
421
|
+
|
|
422
|
+
```python
|
|
423
|
+
# Bad
|
|
424
|
+
not (not a)
|
|
425
|
+
|
|
426
|
+
# Good
|
|
427
|
+
a
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
### SIM210
|
|
431
|
+
|
|
432
|
+
```python
|
|
433
|
+
# Bad
|
|
434
|
+
True if a else False
|
|
435
|
+
|
|
436
|
+
# Good
|
|
437
|
+
bool(a)
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
### SIM211
|
|
441
|
+
|
|
442
|
+
```python
|
|
443
|
+
# Bad
|
|
444
|
+
False if a else True
|
|
445
|
+
|
|
446
|
+
# Good
|
|
447
|
+
not a
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
### SIM212
|
|
451
|
+
|
|
452
|
+
```python
|
|
453
|
+
# Bad
|
|
454
|
+
b if not a else a
|
|
455
|
+
|
|
456
|
+
# Good
|
|
457
|
+
a if a else b
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
### SIM220
|
|
461
|
+
|
|
462
|
+
```python
|
|
463
|
+
# Bad
|
|
464
|
+
a and not a
|
|
465
|
+
|
|
466
|
+
# Good
|
|
467
|
+
False
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
### SIM221
|
|
471
|
+
|
|
472
|
+
```python
|
|
473
|
+
# Bad
|
|
474
|
+
a or not a
|
|
475
|
+
|
|
476
|
+
# Good
|
|
477
|
+
True
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
### SIM222
|
|
481
|
+
|
|
482
|
+
```python
|
|
483
|
+
# Bad
|
|
484
|
+
... or True
|
|
485
|
+
|
|
486
|
+
# Good
|
|
487
|
+
True
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
### SIM223
|
|
491
|
+
|
|
492
|
+
```python
|
|
493
|
+
# Bad
|
|
494
|
+
... and False
|
|
495
|
+
|
|
496
|
+
# Good
|
|
497
|
+
False
|
|
498
|
+
```
|
|
499
|
+
|
|
500
|
+
### SIM300
|
|
501
|
+
|
|
502
|
+
```python
|
|
503
|
+
# Bad; This is called a "Yoda-Condition"
|
|
504
|
+
42 == age
|
|
505
|
+
|
|
506
|
+
# Good
|
|
507
|
+
age == 42
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
### SIM401
|
|
511
|
+
|
|
512
|
+
```python
|
|
513
|
+
# Bad
|
|
514
|
+
if key in a_dict:
|
|
515
|
+
value = a_dict[key]
|
|
516
|
+
else:
|
|
517
|
+
value = "default_value"
|
|
518
|
+
|
|
519
|
+
# Good
|
|
520
|
+
thing = a_dict.get(key, "default_value")
|
|
521
|
+
```
|
|
522
|
+
|
|
523
|
+
### SIM901
|
|
524
|
+
|
|
525
|
+
This rule will be renamed to `SIM224` after its 6-month trial period is over.
|
|
526
|
+
Please report any issues you encounter with this rule!
|
|
527
|
+
|
|
528
|
+
The trial period starts on 23rd of January and will end on 23rd of August 2022.
|
|
529
|
+
|
|
530
|
+
```python
|
|
531
|
+
# Bad
|
|
532
|
+
bool(a == b)
|
|
533
|
+
|
|
534
|
+
# Good
|
|
535
|
+
a == b
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
|
|
539
|
+
### SIM904
|
|
540
|
+
|
|
541
|
+
This rule will be renamed to `SIM224` after its 6-month trial period is over.
|
|
542
|
+
Please report any issues you encounter with this rule!
|
|
543
|
+
|
|
544
|
+
The trial period starts on 12th of February and will end on 12th of September 2022.
|
|
545
|
+
|
|
546
|
+
|
|
547
|
+
```python
|
|
548
|
+
# Bad
|
|
549
|
+
a = {}
|
|
550
|
+
a["b"] = "c"
|
|
551
|
+
|
|
552
|
+
# Good
|
|
553
|
+
a = {"b": "c"}
|
|
554
|
+
```
|
|
555
|
+
|
|
556
|
+
### SIM905
|
|
557
|
+
|
|
558
|
+
This rule will be renamed to `SIM225` after its 6-month trial period is over.
|
|
559
|
+
Please report any issues you encounter with this rule!
|
|
560
|
+
|
|
561
|
+
The trial period starts on 13th of February and will end on 13th of September 2022.
|
|
562
|
+
|
|
563
|
+
```python
|
|
564
|
+
# Bad
|
|
565
|
+
domains = "de com net org".split()
|
|
566
|
+
|
|
567
|
+
# Good
|
|
568
|
+
domains = ["de", "com", "net", "org"]
|
|
569
|
+
```
|
|
570
|
+
|
|
571
|
+
### SIM906
|
|
572
|
+
|
|
573
|
+
This rule will be renamed to `SIM126` after its 6-month trial period is over.
|
|
574
|
+
Please report any issues you encounter with this rule!
|
|
575
|
+
|
|
576
|
+
The trial period starts on 20th of February and will end on 20th of September 2022.
|
|
577
|
+
|
|
578
|
+
```python
|
|
579
|
+
# Bad
|
|
580
|
+
os.path.join(a, os.path.join(b, c))
|
|
581
|
+
|
|
582
|
+
# Good
|
|
583
|
+
os.path.join(a, b, c)
|
|
584
|
+
```
|
|
585
|
+
|
|
586
|
+
### SIM907
|
|
587
|
+
|
|
588
|
+
This rule will be renamed to `SIM127` after its 6-month trial period is over.
|
|
589
|
+
Please report any issues you encounter with this rule!
|
|
590
|
+
|
|
591
|
+
The trial period starts on 28th of March and will end on 28th of September 2022.
|
|
592
|
+
|
|
593
|
+
```python
|
|
594
|
+
# Bad
|
|
595
|
+
def foo(a: Union[int, None]) -> Union[int, None]:
|
|
596
|
+
return a
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
# Good
|
|
600
|
+
def foo(a: Optional[int]) -> Optional[int]:
|
|
601
|
+
return a
|
|
602
|
+
```
|
|
603
|
+
|
|
604
|
+
### SIM908
|
|
605
|
+
|
|
606
|
+
This rule will be renamed to `SIM121` after its 6-month trial period is over.
|
|
607
|
+
Please report any issues you encounter with this rule!
|
|
608
|
+
|
|
609
|
+
The trial period starts on 28th of March and will end on 28th of September 2022.
|
|
610
|
+
|
|
611
|
+
```python
|
|
612
|
+
# Bad
|
|
613
|
+
name = "some_default"
|
|
614
|
+
if "some_key" in some_dict:
|
|
615
|
+
name = some_dict["some_key"]
|
|
616
|
+
|
|
617
|
+
# Good
|
|
618
|
+
name = some_dict.get("some_key", "some_default")
|
|
619
|
+
```
|
|
620
|
+
|
|
621
|
+
### SIM909
|
|
622
|
+
|
|
623
|
+
Thank you Ryan Delaney for the idea!
|
|
624
|
+
|
|
625
|
+
This rule will be renamed to `SIM124` after its 6-month trial period is over.
|
|
626
|
+
Please report any issues you encounter with this rule!
|
|
627
|
+
|
|
628
|
+
The trial period starts on 28th of March and will end on 28th of September 2022.
|
|
629
|
+
|
|
630
|
+
```python
|
|
631
|
+
# Bad
|
|
632
|
+
foo = foo
|
|
633
|
+
|
|
634
|
+
# Good: Nothing. Reflexive assignments have no purpose.
|
|
635
|
+
```
|
|
636
|
+
|
|
637
|
+
or
|
|
638
|
+
|
|
639
|
+
```python
|
|
640
|
+
# Bad
|
|
641
|
+
foo = foo = 42
|
|
642
|
+
|
|
643
|
+
# Good
|
|
644
|
+
foo = 42
|
|
645
|
+
```
|
|
646
|
+
|
|
647
|
+
### SIM910
|
|
648
|
+
|
|
649
|
+
```python
|
|
650
|
+
# Bad
|
|
651
|
+
dict.get(key, None)
|
|
652
|
+
|
|
653
|
+
# Good
|
|
654
|
+
dict.get(key)
|
|
655
|
+
```
|
|
656
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
flake8_simplify/__init__.py,sha256=9CSeCj--jmuKnX1oj9DvlfpaJmtwd99Xez9YyQs_EhQ,5448
|
|
2
|
+
flake8_simplify/constants.py,sha256=wGxxagBGut67NRb7MfS7irgYw1QfdOczGMMDaw1xyQM,253
|
|
3
|
+
flake8_simplify/utils.py,sha256=VNUFBhspyN89rSU1voQ3QVvOupqUfokO2reBzMgclpc,7319
|
|
4
|
+
flake8_simplify/rules/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
flake8_simplify/rules/ast_assign.py,sha256=4NnEhmUF7Bug5gBLNNrDysY7LHVp18RL-sjv2Q6ZtKQ,2951
|
|
6
|
+
flake8_simplify/rules/ast_bool_op.py,sha256=OFBwgX0GmgDVJnpXN69aueXZJB98IOCRmCOGLBMmjX4,6780
|
|
7
|
+
flake8_simplify/rules/ast_call.py,sha256=LrQmdKyhvwTt9-F1_UMf2EXMl0UDldh8T_vZ5zgXtfM,6613
|
|
8
|
+
flake8_simplify/rules/ast_classdef.py,sha256=1pd43FKX7lZGpYmVYfDK7JYFyIpO0Q1ZAICCcytUVjU,629
|
|
9
|
+
flake8_simplify/rules/ast_compare.py,sha256=mUlnC_cCfzB5HPHXMmubHE6mbFDH4OSDGOPJ_5FSDeU,2451
|
|
10
|
+
flake8_simplify/rules/ast_expr.py,sha256=5bZHWdL3C2u_R_6NVIV95bCYDyv32HLt2pCSzUx4x-8,3601
|
|
11
|
+
flake8_simplify/rules/ast_for.py,sha256=1KSmeFFzaMAgb-7Wff5oyulLpKCoA_LFL98d7biCYHo,6156
|
|
12
|
+
flake8_simplify/rules/ast_if.py,sha256=MkaWjJkFwYxMsztM6uzGsWF8aL2lfSIrIgRmGhBsWLs,16598
|
|
13
|
+
flake8_simplify/rules/ast_ifexp.py,sha256=yhieqVFa6n5YxCrYOhkUHC4HUMM9Nlt9lVORejNfRG4,2254
|
|
14
|
+
flake8_simplify/rules/ast_subscript.py,sha256=ZsHEpFtu5Wce_2YubxwGrKoQkru0MvvrsU1jahz7QmM,1582
|
|
15
|
+
flake8_simplify/rules/ast_try.py,sha256=tO2QFAr_nJPBwWQOJGbL3CZNVn4dBcR5iWavMYt7I2o,2560
|
|
16
|
+
flake8_simplify/rules/ast_unary_op.py,sha256=RP9IoKnLo5tfHVvnu-bSE0B8a0lASi0P68mqVqhrmhY,3300
|
|
17
|
+
flake8_simplify/rules/ast_with.py,sha256=drq44uhmrc2vGsXlQNgcLGQEZkwMSvZ5JLeUddLq0Hk,2034
|
|
18
|
+
flake8_simplify-0.20.0.dist-info/entry_points.txt,sha256=F3y-Ib_M-GveLqehRGSRaUmQQQ-WZP6U2vLOgrkFjho,47
|
|
19
|
+
flake8_simplify-0.20.0.dist-info/LICENSE,sha256=FHaa7FZJ75FBDAZvfzdy5vlfg9R6M_XyI1sNp_BW2cg,1069
|
|
20
|
+
flake8_simplify-0.20.0.dist-info/WHEEL,sha256=rSgq_JpHF9fHR1lx53qwg_1-2LypZE_qmcuXbVUq948,81
|
|
21
|
+
flake8_simplify-0.20.0.dist-info/METADATA,sha256=HITbEsUBz-ssN_AJQawcZSG_Y9W7qybDOqhfQoY-iqE,16489
|
|
22
|
+
flake8_simplify-0.20.0.dist-info/RECORD,,
|