flake8_simplify 0.20.0__tar.gz → 0.22.0__tar.gz
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-0.20.0 → flake8_simplify-0.22.0}/.flake8 +1 -0
- flake8_simplify-0.22.0/.github/dependabot.yml +9 -0
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/.github/workflows/lint.yml +2 -2
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/.github/workflows/unit-test.yml +4 -3
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/.gitignore +2 -0
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/.pre-commit-config.yaml +30 -23
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/CHANGELOG.md +7 -0
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/PKG-INFO +7 -4
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/README.md +3 -1
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/flake8_simplify/__init__.py +2 -0
- flake8_simplify-0.22.0/flake8_simplify/constants.py +12 -0
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/flake8_simplify/rules/ast_call.py +70 -4
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/flake8_simplify/rules/ast_for.py +6 -4
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/flake8_simplify/rules/ast_if.py +10 -10
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/flake8_simplify/utils.py +1 -1
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/pyproject.toml +3 -3
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/requirements/dev.txt +40 -43
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/requirements/lint.txt +31 -32
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/tests/test_900_rules.py +31 -0
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/tox.ini +1 -1
- flake8_simplify-0.20.0/flake8_simplify/constants.py +0 -7
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/.coveragerc +0 -0
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/.github/ISSUE_TEMPLATE/adjust-rule.md +0 -0
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/.github/ISSUE_TEMPLATE/rule-request.md +0 -0
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/.isort.cfg +0 -0
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/LICENSE +0 -0
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/Makefile +0 -0
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/flake8_simplify/rules/__init__.py +0 -0
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/flake8_simplify/rules/ast_assign.py +0 -0
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/flake8_simplify/rules/ast_bool_op.py +0 -0
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/flake8_simplify/rules/ast_classdef.py +0 -0
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/flake8_simplify/rules/ast_compare.py +0 -0
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/flake8_simplify/rules/ast_expr.py +0 -0
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/flake8_simplify/rules/ast_ifexp.py +0 -0
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/flake8_simplify/rules/ast_subscript.py +0 -0
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/flake8_simplify/rules/ast_try.py +0 -0
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/flake8_simplify/rules/ast_unary_op.py +0 -0
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/flake8_simplify/rules/ast_with.py +0 -0
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/mutmut-test.sh +0 -0
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/requirements/dev.in +0 -0
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/requirements/lint.in +0 -0
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/tests/__init__.py +0 -0
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/tests/test_100_rules.py +0 -0
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/tests/test_200_rules.py +0 -0
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/tests/test_300_rules.py +0 -0
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/tests/test_400_rules.py +0 -0
- {flake8_simplify-0.20.0 → flake8_simplify-0.22.0}/tests/test_simplify.py +0 -0
|
@@ -18,9 +18,9 @@ jobs:
|
|
|
18
18
|
python-version: [3.8]
|
|
19
19
|
|
|
20
20
|
steps:
|
|
21
|
-
- uses: actions/checkout@
|
|
21
|
+
- uses: actions/checkout@v4
|
|
22
22
|
- name: Set up Python ${{ matrix.python-version }}
|
|
23
|
-
uses: actions/setup-python@
|
|
23
|
+
uses: actions/setup-python@v5
|
|
24
24
|
with:
|
|
25
25
|
python-version: ${{ matrix.python-version }}
|
|
26
26
|
- name: Install dependencies
|
|
@@ -15,14 +15,15 @@ jobs:
|
|
|
15
15
|
runs-on: ubuntu-latest
|
|
16
16
|
strategy:
|
|
17
17
|
matrix:
|
|
18
|
-
python-version: [3.
|
|
18
|
+
python-version: [3.8, 3.9, "3.10", 3.11, 3.12]
|
|
19
19
|
|
|
20
20
|
steps:
|
|
21
|
-
- uses: actions/checkout@
|
|
21
|
+
- uses: actions/checkout@v4
|
|
22
22
|
- name: Set up Python ${{ matrix.python-version }}
|
|
23
|
-
uses: actions/setup-python@
|
|
23
|
+
uses: actions/setup-python@v5
|
|
24
24
|
with:
|
|
25
25
|
python-version: ${{ matrix.python-version }}
|
|
26
|
+
allow-prereleases: true
|
|
26
27
|
- name: Install dependencies
|
|
27
28
|
run: |
|
|
28
29
|
python -m pip install --upgrade pip
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# pre-commit run --all-files
|
|
2
2
|
repos:
|
|
3
3
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
4
|
-
rev: v4.
|
|
4
|
+
rev: v4.4.0
|
|
5
5
|
hooks:
|
|
6
6
|
- id: check-ast
|
|
7
7
|
- id: check-byte-order-marker
|
|
@@ -12,33 +12,40 @@ repos:
|
|
|
12
12
|
- id: end-of-file-fixer
|
|
13
13
|
- id: trailing-whitespace
|
|
14
14
|
- id: mixed-line-ending
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
# - id: flake8
|
|
19
|
-
- repo: https://github.com/pre-commit/mirrors-mypy
|
|
20
|
-
rev: v0.942
|
|
21
|
-
hooks:
|
|
22
|
-
- id: mypy
|
|
23
|
-
- repo: https://github.com/asottile/seed-isort-config
|
|
24
|
-
rev: v2.2.0
|
|
25
|
-
hooks:
|
|
26
|
-
- id: seed-isort-config
|
|
27
|
-
- repo: https://github.com/pre-commit/mirrors-isort
|
|
28
|
-
rev: v5.10.1
|
|
29
|
-
hooks:
|
|
30
|
-
- id: isort
|
|
15
|
+
args: ['--fix=lf']
|
|
16
|
+
- id: check-added-large-files
|
|
17
|
+
args: ['--maxkb=500']
|
|
31
18
|
- repo: https://github.com/psf/black
|
|
32
|
-
rev:
|
|
19
|
+
rev: 23.9.1
|
|
33
20
|
hooks:
|
|
34
21
|
- id: black
|
|
22
|
+
args: [--target-version, py36]
|
|
23
|
+
- repo: https://github.com/asottile/blacken-docs
|
|
24
|
+
rev: 1.16.0
|
|
25
|
+
hooks:
|
|
26
|
+
- id: blacken-docs
|
|
27
|
+
additional_dependencies: [black==22.1.0]
|
|
28
|
+
- repo: https://github.com/charliermarsh/ruff-pre-commit
|
|
29
|
+
rev: v0.0.290
|
|
30
|
+
hooks:
|
|
31
|
+
- id: ruff
|
|
32
|
+
args: ['--fix']
|
|
35
33
|
- repo: https://github.com/asottile/pyupgrade
|
|
36
|
-
rev:
|
|
34
|
+
rev: v3.12.0
|
|
37
35
|
hooks:
|
|
38
36
|
- id: pyupgrade
|
|
39
37
|
args: [--py36-plus]
|
|
40
|
-
- repo: https://github.com/
|
|
41
|
-
rev:
|
|
38
|
+
- repo: https://github.com/pycqa/flake8
|
|
39
|
+
rev: 6.1.0
|
|
42
40
|
hooks:
|
|
43
|
-
- id:
|
|
44
|
-
|
|
41
|
+
- id: flake8
|
|
42
|
+
args: ["--ignore", "E,W,F"]
|
|
43
|
+
|
|
44
|
+
- repo: https://github.com/pre-commit/mirrors-mypy
|
|
45
|
+
rev: 'v1.5.1'
|
|
46
|
+
hooks:
|
|
47
|
+
- id: mypy
|
|
48
|
+
- repo: https://github.com/pre-commit/mirrors-isort
|
|
49
|
+
rev: v5.10.1
|
|
50
|
+
hooks:
|
|
51
|
+
- id: isort
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: flake8_simplify
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.22.0
|
|
4
4
|
Summary: flake8 plugin which checks for code that can be simplified
|
|
5
5
|
Keywords: flake8
|
|
6
6
|
Author-email: Martin Thoma <info@martin-thoma.de>
|
|
@@ -15,12 +15,13 @@ Classifier: Natural Language :: English
|
|
|
15
15
|
Classifier: Operating System :: OS Independent
|
|
16
16
|
Classifier: Programming Language :: Python :: 3
|
|
17
17
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.7
|
|
19
18
|
Classifier: Programming Language :: Python :: 3.8
|
|
20
19
|
Classifier: Programming Language :: Python :: 3.9
|
|
21
20
|
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
22
|
Classifier: Topic :: Software Development
|
|
23
23
|
Classifier: Framework :: Flake8
|
|
24
|
+
License-File: LICENSE
|
|
24
25
|
Requires-Dist: astor>=0.1
|
|
25
26
|
Requires-Dist: flake8>=3.7
|
|
26
27
|
Requires-Dist: importlib-metadata>=0.9; python_version < "3.8"
|
|
@@ -43,7 +44,7 @@ Install with `pip`:
|
|
|
43
44
|
pip install flake8-simplify
|
|
44
45
|
```
|
|
45
46
|
|
|
46
|
-
Python 3.
|
|
47
|
+
Python 3.8 to 3.11 are supported.
|
|
47
48
|
|
|
48
49
|
|
|
49
50
|
## Usage
|
|
@@ -105,6 +106,7 @@ Simplifying usage of dictionaries:
|
|
|
105
106
|
|
|
106
107
|
* [`SIM401`](https://github.com/MartinThoma/flake8-simplify/issues/72): Use 'a_dict.get(key, "default_value")' instead of an if-block ([example](#SIM401))
|
|
107
108
|
* [`SIM118`](https://github.com/MartinThoma/flake8-simplify/issues/40): Use 'key in dict' instead of 'key in dict.keys()' ([example](#SIM118))
|
|
109
|
+
* `SIM119` Reserved for [SIM911](#sim911) once it's stable
|
|
108
110
|
|
|
109
111
|
General Code Style:
|
|
110
112
|
|
|
@@ -134,6 +136,7 @@ Current experimental rules:
|
|
|
134
136
|
* [`SIM908`](https://github.com/MartinThoma/flake8-simplify/issues/50): Use dict.get(key) ([example](#SIM908))
|
|
135
137
|
* [`SIM909`](https://github.com/MartinThoma/flake8-simplify/issues/114): Avoid reflexive assignments ([example](#SIM909))
|
|
136
138
|
* [`SIM910`](https://github.com/MartinThoma/flake8-simplify/issues/171): Avoid to use `dict.get(key, None)` ([example](#SIM910))
|
|
139
|
+
* [`SIM911`](https://github.com/MartinThoma/flake8-simplify/issues/161): Avoid using `zip(dict.keys(), dict.values())` ([example](#SIM911))
|
|
137
140
|
|
|
138
141
|
## Disabling Rules
|
|
139
142
|
|
|
@@ -15,7 +15,7 @@ Install with `pip`:
|
|
|
15
15
|
pip install flake8-simplify
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
Python 3.
|
|
18
|
+
Python 3.8 to 3.11 are supported.
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
## Usage
|
|
@@ -77,6 +77,7 @@ Simplifying usage of dictionaries:
|
|
|
77
77
|
|
|
78
78
|
* [`SIM401`](https://github.com/MartinThoma/flake8-simplify/issues/72): Use 'a_dict.get(key, "default_value")' instead of an if-block ([example](#SIM401))
|
|
79
79
|
* [`SIM118`](https://github.com/MartinThoma/flake8-simplify/issues/40): Use 'key in dict' instead of 'key in dict.keys()' ([example](#SIM118))
|
|
80
|
+
* `SIM119` Reserved for [SIM911](#sim911) once it's stable
|
|
80
81
|
|
|
81
82
|
General Code Style:
|
|
82
83
|
|
|
@@ -106,6 +107,7 @@ Current experimental rules:
|
|
|
106
107
|
* [`SIM908`](https://github.com/MartinThoma/flake8-simplify/issues/50): Use dict.get(key) ([example](#SIM908))
|
|
107
108
|
* [`SIM909`](https://github.com/MartinThoma/flake8-simplify/issues/114): Avoid reflexive assignments ([example](#SIM909))
|
|
108
109
|
* [`SIM910`](https://github.com/MartinThoma/flake8-simplify/issues/171): Avoid to use `dict.get(key, None)` ([example](#SIM910))
|
|
110
|
+
* [`SIM911`](https://github.com/MartinThoma/flake8-simplify/issues/161): Avoid using `zip(dict.keys(), dict.values())` ([example](#SIM911))
|
|
109
111
|
|
|
110
112
|
## Disabling Rules
|
|
111
113
|
|
|
@@ -20,6 +20,7 @@ from flake8_simplify.rules.ast_call import (
|
|
|
20
20
|
get_sim905,
|
|
21
21
|
get_sim906,
|
|
22
22
|
get_sim910,
|
|
23
|
+
get_sim911,
|
|
23
24
|
)
|
|
24
25
|
from flake8_simplify.rules.ast_classdef import get_sim120
|
|
25
26
|
from flake8_simplify.rules.ast_compare import get_sim118, get_sim300
|
|
@@ -76,6 +77,7 @@ class Visitor(ast.NodeVisitor):
|
|
|
76
77
|
self.errors += get_sim905(node)
|
|
77
78
|
self.errors += get_sim906(node)
|
|
78
79
|
self.errors += get_sim910(Call(node))
|
|
80
|
+
self.errors += get_sim911(node)
|
|
79
81
|
self.generic_visit(node)
|
|
80
82
|
|
|
81
83
|
def visit_With(self, node: ast.With) -> Any:
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Core Library
|
|
2
|
+
import ast
|
|
3
|
+
|
|
4
|
+
# ast.Constant in Python 3.8, ast.NameConstant in Python 3.6 and 3.7
|
|
5
|
+
if hasattr(ast, 'NameConstant'):
|
|
6
|
+
BOOL_CONST_TYPES = (ast.Constant, ast.NameConstant)
|
|
7
|
+
AST_CONST_TYPES = (ast.Constant, ast.NameConstant, ast.Str, ast.Num)
|
|
8
|
+
STR_TYPES = (ast.Constant, ast.Str)
|
|
9
|
+
else:
|
|
10
|
+
BOOL_CONST_TYPES = (ast.Constant,)
|
|
11
|
+
AST_CONST_TYPES = (ast.Constant,)
|
|
12
|
+
STR_TYPES = (ast.Constant,)
|
|
@@ -99,14 +99,14 @@ def get_sim905(node: ast.Call) -> List[Tuple[int, int, str]]:
|
|
|
99
99
|
if not (
|
|
100
100
|
isinstance(node.func, ast.Attribute)
|
|
101
101
|
and node.func.attr == "split"
|
|
102
|
-
and isinstance(node.func.value,
|
|
102
|
+
and isinstance(node.func.value, ast.Constant) and isinstance(node.func.value.value, str)
|
|
103
103
|
):
|
|
104
104
|
return errors
|
|
105
105
|
|
|
106
106
|
if isinstance(node.func.value, ast.Constant):
|
|
107
107
|
value = node.func.value.value
|
|
108
108
|
else:
|
|
109
|
-
value = node.func.value.
|
|
109
|
+
value = node.func.value.value
|
|
110
110
|
|
|
111
111
|
expected = json.dumps(value.split())
|
|
112
112
|
actual = to_source(node.func.value) + ".split()"
|
|
@@ -161,8 +161,8 @@ def get_sim906(node: ast.Call) -> List[Tuple[int, int, str]]:
|
|
|
161
161
|
names = names + get_os_path_join_args(arg)
|
|
162
162
|
elif isinstance(arg, ast.Name):
|
|
163
163
|
names.append(arg.id)
|
|
164
|
-
elif isinstance(arg, ast.
|
|
165
|
-
names.append(f"'{arg.
|
|
164
|
+
elif isinstance(arg, ast.Constant) and isinstance(arg.value, str):
|
|
165
|
+
names.append(f"'{arg.value}'")
|
|
166
166
|
else:
|
|
167
167
|
logger.debug(
|
|
168
168
|
f"Unexpected os.path.join arg: {arg} -- {to_source(arg)}"
|
|
@@ -233,3 +233,69 @@ def get_sim910(node: Call) -> List[Tuple[int, int, str]]:
|
|
|
233
233
|
)
|
|
234
234
|
)
|
|
235
235
|
return errors
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
def get_sim911(node: ast.AST) -> List[Tuple[int, int, str]]:
|
|
239
|
+
"""
|
|
240
|
+
Find nodes representing the expression "zip(_.keys(), _.values())".
|
|
241
|
+
|
|
242
|
+
Returns a list of tuples containing the line number and column offset
|
|
243
|
+
of each identified node.
|
|
244
|
+
|
|
245
|
+
Expr(
|
|
246
|
+
value=Call(
|
|
247
|
+
func=Name(id='zip', ctx=Load()),
|
|
248
|
+
args=[
|
|
249
|
+
Call(
|
|
250
|
+
func=Attribute(
|
|
251
|
+
value=Name(id='_', ctx=Load()),
|
|
252
|
+
attr='keys',
|
|
253
|
+
ctx=Load()),
|
|
254
|
+
args=[],
|
|
255
|
+
keywords=[]),
|
|
256
|
+
Call(
|
|
257
|
+
func=Attribute(
|
|
258
|
+
value=Name(id='_', ctx=Load()),
|
|
259
|
+
attr='values',
|
|
260
|
+
ctx=Load()),
|
|
261
|
+
args=[],
|
|
262
|
+
keywords=[])],
|
|
263
|
+
keywords=[
|
|
264
|
+
keyword(
|
|
265
|
+
arg='strict',
|
|
266
|
+
value=Constant(value=False))
|
|
267
|
+
]
|
|
268
|
+
)
|
|
269
|
+
)
|
|
270
|
+
"""
|
|
271
|
+
RULE = (
|
|
272
|
+
"SIM911 Use '{name}.items()' instead of "
|
|
273
|
+
"'zip({name}.keys(), {name}.values())'"
|
|
274
|
+
)
|
|
275
|
+
errors: List[Tuple[int, int, str]] = []
|
|
276
|
+
|
|
277
|
+
if isinstance(node, ast.Call) and (
|
|
278
|
+
isinstance(node.func, ast.Name)
|
|
279
|
+
and node.func.id == "zip"
|
|
280
|
+
and len(node.args) == 2
|
|
281
|
+
):
|
|
282
|
+
first_arg, second_arg = node.args
|
|
283
|
+
if (
|
|
284
|
+
isinstance(first_arg, ast.Call)
|
|
285
|
+
and isinstance(first_arg.func, ast.Attribute)
|
|
286
|
+
and isinstance(first_arg.func.value, ast.Name)
|
|
287
|
+
and first_arg.func.attr == "keys"
|
|
288
|
+
and isinstance(second_arg, ast.Call)
|
|
289
|
+
and isinstance(second_arg.func, ast.Attribute)
|
|
290
|
+
and isinstance(second_arg.func.value, ast.Name)
|
|
291
|
+
and second_arg.func.attr == "values"
|
|
292
|
+
and first_arg.func.value.id == second_arg.func.value.id
|
|
293
|
+
):
|
|
294
|
+
errors.append(
|
|
295
|
+
(
|
|
296
|
+
node.lineno,
|
|
297
|
+
node.col_offset,
|
|
298
|
+
RULE.format(name=first_arg.func.value.id),
|
|
299
|
+
)
|
|
300
|
+
)
|
|
301
|
+
return errors
|
|
@@ -50,10 +50,12 @@ def get_sim104(node: ast.For) -> List[Tuple[int, int, str]]:
|
|
|
50
50
|
return errors
|
|
51
51
|
|
|
52
52
|
parent = getattr(node, "parent", None)
|
|
53
|
-
while (
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
while (
|
|
54
|
+
parent
|
|
55
|
+
and hasattr(parent, "parent")
|
|
56
|
+
and parent.parent is not parent
|
|
57
|
+
and not isinstance(parent, ast.AsyncFunctionDef)
|
|
58
|
+
):
|
|
57
59
|
parent = getattr(parent, "parent", None)
|
|
58
60
|
|
|
59
61
|
if isinstance(parent, ast.AsyncFunctionDef): # type: ignore
|
|
@@ -41,8 +41,8 @@ def get_sim102(node: ast.If) -> List[Tuple[int, int, str]]:
|
|
|
41
41
|
and isinstance(node.test.left, ast.Name)
|
|
42
42
|
and node.test.left.id == "__name__"
|
|
43
43
|
and len(node.test.comparators) == 1
|
|
44
|
-
and isinstance(node.test.comparators[0], ast.
|
|
45
|
-
and node.test.comparators[0].
|
|
44
|
+
and isinstance(node.test.comparators[0], ast.Constant) and isinstance(node.test.comparators[0].value, str)
|
|
45
|
+
and node.test.comparators[0].value == "__main__"
|
|
46
46
|
)
|
|
47
47
|
if is_main_check:
|
|
48
48
|
return errors
|
|
@@ -248,14 +248,14 @@ def get_sim116(node: ast.If) -> List[Tuple[int, int, str]]:
|
|
|
248
248
|
assert isinstance(child, ast.If), "hint for mypy"
|
|
249
249
|
else_value: Optional[str] = None
|
|
250
250
|
key_value_pairs: Dict[Any, Any]
|
|
251
|
-
if isinstance(node.test.comparators[0], ast.
|
|
251
|
+
if isinstance(node.test.comparators[0], ast.Constant) and isinstance(node.test.comparators[0].value, str):
|
|
252
252
|
value = to_source(node.body[0].value)
|
|
253
253
|
if value[0] == '"' and value[-1] == '"':
|
|
254
254
|
value = value[1:-1]
|
|
255
|
-
key_value_pairs = {node.test.comparators[0].
|
|
256
|
-
elif isinstance(node.test.comparators[0], ast.
|
|
255
|
+
key_value_pairs = {node.test.comparators[0].value: value}
|
|
256
|
+
elif isinstance(node.test.comparators[0], ast.Constant) and isinstance(node.test.comparators[0].value, (int, float, complex)):
|
|
257
257
|
key_value_pairs = {
|
|
258
|
-
node.test.comparators[0].
|
|
258
|
+
node.test.comparators[0].value: to_source(node.body[0].value)
|
|
259
259
|
}
|
|
260
260
|
else:
|
|
261
261
|
key_value_pairs = {
|
|
@@ -281,10 +281,10 @@ def get_sim116(node: ast.If) -> List[Tuple[int, int, str]]:
|
|
|
281
281
|
# See https://github.com/MartinThoma/flake8-simplify/issues/113
|
|
282
282
|
return errors
|
|
283
283
|
key: Any
|
|
284
|
-
if isinstance(child.test.comparators[0], ast.
|
|
285
|
-
key = child.test.comparators[0].
|
|
286
|
-
elif isinstance(child.test.comparators[0], ast.
|
|
287
|
-
key = child.test.comparators[0].
|
|
284
|
+
if isinstance(child.test.comparators[0], ast.Constant) and isinstance(child.test.comparators[0].value, str):
|
|
285
|
+
key = child.test.comparators[0].value
|
|
286
|
+
elif isinstance(child.test.comparators[0], ast.Constant) and isinstance(child.test.comparators[0].value, (int, float, complex)):
|
|
287
|
+
key = child.test.comparators[0].value
|
|
288
288
|
else:
|
|
289
289
|
key = child.test.comparators[0].value
|
|
290
290
|
|
|
@@ -182,7 +182,7 @@ def get_if_body_pairs(node: ast.If) -> List[Tuple[ast.expr, List[ast.stmt]]]:
|
|
|
182
182
|
def is_constant_increase(expr: ast.AugAssign) -> bool:
|
|
183
183
|
return isinstance(expr.op, ast.Add) and (
|
|
184
184
|
(isinstance(expr.value, ast.Constant) and expr.value.value == 1)
|
|
185
|
-
or (isinstance(expr.value, ast.
|
|
185
|
+
or (isinstance(expr.value, ast.Constant) and isinstance(expr.value.value, (int, float, complex)) and expr.value.value == 1)
|
|
186
186
|
)
|
|
187
187
|
|
|
188
188
|
|
|
@@ -6,7 +6,7 @@ requires = [
|
|
|
6
6
|
|
|
7
7
|
[project]
|
|
8
8
|
name = "flake8_simplify"
|
|
9
|
-
version = "0.
|
|
9
|
+
version = "0.22.0"
|
|
10
10
|
description = "flake8 plugin which checks for code that can be simplified"
|
|
11
11
|
keywords = [
|
|
12
12
|
"flake8",
|
|
@@ -29,10 +29,10 @@ classifiers = [
|
|
|
29
29
|
"Operating System :: OS Independent",
|
|
30
30
|
"Programming Language :: Python :: 3",
|
|
31
31
|
"Programming Language :: Python :: 3 :: Only",
|
|
32
|
-
"Programming Language :: Python :: 3.7",
|
|
33
32
|
"Programming Language :: Python :: 3.8",
|
|
34
33
|
"Programming Language :: Python :: 3.9",
|
|
35
34
|
"Programming Language :: Python :: 3.10",
|
|
35
|
+
"Programming Language :: Python :: 3.11",
|
|
36
36
|
"Topic :: Software Development",
|
|
37
37
|
"Framework :: Flake8",
|
|
38
38
|
]
|
|
@@ -57,7 +57,7 @@ namespaces = false
|
|
|
57
57
|
|
|
58
58
|
[tool.black]
|
|
59
59
|
line-length = 79
|
|
60
|
-
target-version = ['
|
|
60
|
+
target-version = ['py38']
|
|
61
61
|
|
|
62
62
|
[tool.mutmut]
|
|
63
63
|
backup = "False"
|
|
@@ -4,87 +4,84 @@
|
|
|
4
4
|
#
|
|
5
5
|
# pip-compile requirements/dev.in
|
|
6
6
|
#
|
|
7
|
-
|
|
8
|
-
# via
|
|
9
|
-
certifi==
|
|
7
|
+
build==1.0.3
|
|
8
|
+
# via pip-tools
|
|
9
|
+
certifi==2023.7.22
|
|
10
10
|
# via requests
|
|
11
|
-
cfgv==3.
|
|
11
|
+
cfgv==3.4.0
|
|
12
12
|
# via pre-commit
|
|
13
|
-
charset-normalizer==2.0
|
|
13
|
+
charset-normalizer==3.2.0
|
|
14
14
|
# via requests
|
|
15
|
-
click==8.
|
|
15
|
+
click==8.1.7
|
|
16
16
|
# via pip-tools
|
|
17
|
-
coverage[toml]==
|
|
17
|
+
coverage[toml]==7.3.1
|
|
18
18
|
# via pytest-cov
|
|
19
|
-
distlib==0.3.
|
|
19
|
+
distlib==0.3.7
|
|
20
20
|
# via virtualenv
|
|
21
|
-
docutils==0.
|
|
21
|
+
docutils==0.20.1
|
|
22
22
|
# via flit
|
|
23
|
-
|
|
23
|
+
exceptiongroup==1.1.3
|
|
24
|
+
# via pytest
|
|
25
|
+
filelock==3.12.4
|
|
24
26
|
# via virtualenv
|
|
25
|
-
flit==3.
|
|
27
|
+
flit==3.9.0
|
|
26
28
|
# via -r requirements/dev.in
|
|
27
|
-
flit-core==3.
|
|
29
|
+
flit-core==3.9.0
|
|
28
30
|
# via flit
|
|
29
|
-
identify==2.
|
|
31
|
+
identify==2.5.29
|
|
30
32
|
# via pre-commit
|
|
31
|
-
idna==3.
|
|
33
|
+
idna==3.4
|
|
32
34
|
# via requests
|
|
33
|
-
iniconfig==
|
|
35
|
+
iniconfig==2.0.0
|
|
34
36
|
# via pytest
|
|
35
|
-
jinja2==3.1.
|
|
37
|
+
jinja2==3.1.2
|
|
36
38
|
# via junit2html
|
|
37
|
-
junit2html==30.
|
|
39
|
+
junit2html==30.1.3
|
|
38
40
|
# via -r requirements/dev.in
|
|
39
|
-
markupsafe==2.1.
|
|
41
|
+
markupsafe==2.1.3
|
|
40
42
|
# via jinja2
|
|
41
|
-
nodeenv==1.
|
|
43
|
+
nodeenv==1.8.0
|
|
42
44
|
# via pre-commit
|
|
43
|
-
packaging==
|
|
44
|
-
# via
|
|
45
|
-
|
|
46
|
-
#
|
|
47
|
-
pip-tools==
|
|
45
|
+
packaging==23.1
|
|
46
|
+
# via
|
|
47
|
+
# build
|
|
48
|
+
# pytest
|
|
49
|
+
pip-tools==7.3.0
|
|
48
50
|
# via -r requirements/dev.in
|
|
49
|
-
platformdirs==
|
|
51
|
+
platformdirs==3.10.0
|
|
50
52
|
# via virtualenv
|
|
51
|
-
pluggy==1.
|
|
53
|
+
pluggy==1.3.0
|
|
52
54
|
# via pytest
|
|
53
|
-
pre-commit==
|
|
55
|
+
pre-commit==3.4.0
|
|
54
56
|
# via -r requirements/dev.in
|
|
55
|
-
|
|
56
|
-
# via
|
|
57
|
-
|
|
58
|
-
# via packaging
|
|
59
|
-
pytest==7.1.1
|
|
57
|
+
pyproject-hooks==1.0.0
|
|
58
|
+
# via build
|
|
59
|
+
pytest==7.4.2
|
|
60
60
|
# via
|
|
61
61
|
# -r requirements/dev.in
|
|
62
62
|
# pytest-cov
|
|
63
63
|
# pytest-timeout
|
|
64
|
-
pytest-cov==
|
|
64
|
+
pytest-cov==4.1.0
|
|
65
65
|
# via -r requirements/dev.in
|
|
66
66
|
pytest-timeout==2.1.0
|
|
67
67
|
# via -r requirements/dev.in
|
|
68
|
-
pyyaml==6.0
|
|
68
|
+
pyyaml==6.0.1
|
|
69
69
|
# via pre-commit
|
|
70
|
-
requests==2.
|
|
70
|
+
requests==2.31.0
|
|
71
71
|
# via flit
|
|
72
|
-
six==1.16.0
|
|
73
|
-
# via virtualenv
|
|
74
|
-
toml==0.10.2
|
|
75
|
-
# via pre-commit
|
|
76
72
|
tomli==2.0.1
|
|
77
73
|
# via
|
|
74
|
+
# build
|
|
78
75
|
# coverage
|
|
79
|
-
#
|
|
76
|
+
# pip-tools
|
|
80
77
|
# pytest
|
|
81
78
|
tomli-w==1.0.0
|
|
82
79
|
# via flit
|
|
83
|
-
urllib3==
|
|
80
|
+
urllib3==2.0.5
|
|
84
81
|
# via requests
|
|
85
|
-
virtualenv==20.
|
|
82
|
+
virtualenv==20.24.5
|
|
86
83
|
# via pre-commit
|
|
87
|
-
wheel==0.
|
|
84
|
+
wheel==0.41.2
|
|
88
85
|
# via
|
|
89
86
|
# -r requirements/dev.in
|
|
90
87
|
# pip-tools
|
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
#
|
|
2
|
-
# This file is autogenerated by pip-compile with
|
|
3
|
-
#
|
|
2
|
+
# This file is autogenerated by pip-compile with Python 3.10
|
|
3
|
+
# by the following command:
|
|
4
4
|
#
|
|
5
5
|
# pip-compile requirements/lint.in
|
|
6
6
|
#
|
|
7
|
-
attrs==
|
|
7
|
+
attrs==23.1.0
|
|
8
8
|
# via
|
|
9
9
|
# flake8-bugbear
|
|
10
10
|
# flake8-eradicate
|
|
11
|
-
|
|
12
|
-
black==22.1.0
|
|
11
|
+
black==23.9.1
|
|
13
12
|
# via -r requirements/lint.in
|
|
14
|
-
click==8.
|
|
13
|
+
click==8.1.7
|
|
15
14
|
# via black
|
|
16
|
-
eradicate==2.
|
|
15
|
+
eradicate==2.3.0
|
|
17
16
|
# via flake8-eradicate
|
|
18
|
-
flake8==
|
|
17
|
+
flake8==6.1.0
|
|
19
18
|
# via
|
|
20
19
|
# -r requirements/lint.in
|
|
21
20
|
# flake8-bugbear
|
|
@@ -26,59 +25,59 @@ flake8==4.0.1
|
|
|
26
25
|
# flake8-isort
|
|
27
26
|
# flake8-raise
|
|
28
27
|
# flake8-string-format
|
|
29
|
-
flake8-bugbear==
|
|
28
|
+
flake8-bugbear==23.9.16
|
|
30
29
|
# via -r requirements/lint.in
|
|
31
|
-
flake8-builtins==1.
|
|
30
|
+
flake8-builtins==2.1.0
|
|
32
31
|
# via -r requirements/lint.in
|
|
33
|
-
flake8-comprehensions==3.
|
|
32
|
+
flake8-comprehensions==3.14.0
|
|
34
33
|
# via -r requirements/lint.in
|
|
35
|
-
flake8-eradicate==1.
|
|
34
|
+
flake8-eradicate==1.5.0
|
|
36
35
|
# via -r requirements/lint.in
|
|
37
|
-
flake8-executable==2.1.
|
|
36
|
+
flake8-executable==2.1.3
|
|
38
37
|
# via -r requirements/lint.in
|
|
39
|
-
flake8-implicit-str-concat==0.
|
|
38
|
+
flake8-implicit-str-concat==0.4.0
|
|
40
39
|
# via -r requirements/lint.in
|
|
41
|
-
flake8-isort==
|
|
40
|
+
flake8-isort==6.1.0
|
|
42
41
|
# via -r requirements/lint.in
|
|
43
|
-
flake8-plugin-utils==1.3.
|
|
42
|
+
flake8-plugin-utils==1.3.3
|
|
44
43
|
# via flake8-pytest-style
|
|
45
|
-
flake8-pytest-style==1.
|
|
44
|
+
flake8-pytest-style==1.7.2
|
|
46
45
|
# via -r requirements/lint.in
|
|
47
46
|
flake8-raise==0.0.5
|
|
48
47
|
# via -r requirements/lint.in
|
|
49
48
|
flake8-string-format==0.3.0
|
|
50
49
|
# via -r requirements/lint.in
|
|
51
|
-
isort==5.
|
|
50
|
+
isort==5.12.0
|
|
52
51
|
# via flake8-isort
|
|
53
|
-
mccabe==0.
|
|
52
|
+
mccabe==0.7.0
|
|
54
53
|
# via
|
|
55
54
|
# -r requirements/lint.in
|
|
56
55
|
# flake8
|
|
57
|
-
|
|
58
|
-
# via flake8-implicit-str-concat
|
|
59
|
-
mypy==0.942
|
|
56
|
+
mypy==1.5.1
|
|
60
57
|
# via -r requirements/lint.in
|
|
61
|
-
mypy-extensions==0.
|
|
58
|
+
mypy-extensions==1.0.0
|
|
62
59
|
# via
|
|
63
60
|
# black
|
|
64
61
|
# mypy
|
|
65
|
-
|
|
62
|
+
packaging==23.1
|
|
66
63
|
# via black
|
|
67
|
-
|
|
64
|
+
pathspec==0.11.2
|
|
68
65
|
# via black
|
|
69
|
-
|
|
66
|
+
platformdirs==3.10.0
|
|
67
|
+
# via black
|
|
68
|
+
pycodestyle==2.11.0
|
|
70
69
|
# via flake8
|
|
71
|
-
pydocstyle==6.
|
|
70
|
+
pydocstyle==6.3.0
|
|
72
71
|
# via -r requirements/lint.in
|
|
73
|
-
pyflakes==
|
|
72
|
+
pyflakes==3.1.0
|
|
74
73
|
# via flake8
|
|
75
74
|
snowballstemmer==2.2.0
|
|
76
75
|
# via pydocstyle
|
|
77
|
-
testfixtures==6.18.5
|
|
78
|
-
# via flake8-isort
|
|
79
76
|
tomli==2.0.1
|
|
80
77
|
# via
|
|
81
78
|
# black
|
|
82
79
|
# mypy
|
|
83
|
-
typing-extensions==4.
|
|
84
|
-
# via
|
|
80
|
+
typing-extensions==4.8.0
|
|
81
|
+
# via
|
|
82
|
+
# black
|
|
83
|
+
# mypy
|
|
@@ -204,3 +204,34 @@ def test_sim910(s, msg):
|
|
|
204
204
|
expected = {msg} if msg is not None else set()
|
|
205
205
|
results = _results(s)
|
|
206
206
|
assert results == expected
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
@pytest.mark.parametrize(
|
|
210
|
+
("s", "expected"),
|
|
211
|
+
(
|
|
212
|
+
(
|
|
213
|
+
"zip(d.keys(), d.values())",
|
|
214
|
+
{
|
|
215
|
+
"1:0 SIM911 Use 'd.items()' instead of 'zip(d.keys(), d.values())'"
|
|
216
|
+
},
|
|
217
|
+
),
|
|
218
|
+
(
|
|
219
|
+
"zip(d.keys(), d.keys())",
|
|
220
|
+
None,
|
|
221
|
+
),
|
|
222
|
+
(
|
|
223
|
+
"zip(d1.keys(), d2.values())",
|
|
224
|
+
None,
|
|
225
|
+
),
|
|
226
|
+
(
|
|
227
|
+
"zip(d1.keys(), values)",
|
|
228
|
+
None,
|
|
229
|
+
),
|
|
230
|
+
(
|
|
231
|
+
"zip(keys, values)",
|
|
232
|
+
None,
|
|
233
|
+
),
|
|
234
|
+
),
|
|
235
|
+
)
|
|
236
|
+
def test_sim911(s, expected):
|
|
237
|
+
assert _results(s) == (expected or set())
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|