flake8_simplify 0.21.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.
Files changed (47) hide show
  1. flake8_simplify-0.22.0/.github/dependabot.yml +9 -0
  2. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/.github/workflows/lint.yml +2 -2
  3. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/.github/workflows/unit-test.yml +2 -2
  4. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/.pre-commit-config.yaml +9 -5
  5. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/PKG-INFO +3 -2
  6. flake8_simplify-0.22.0/flake8_simplify/constants.py +12 -0
  7. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/flake8_simplify/rules/ast_call.py +4 -4
  8. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/flake8_simplify/rules/ast_if.py +10 -10
  9. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/flake8_simplify/utils.py +1 -1
  10. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/pyproject.toml +1 -1
  11. flake8_simplify-0.21.0/flake8_simplify/constants.py +0 -7
  12. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/.coveragerc +0 -0
  13. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/.flake8 +0 -0
  14. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/.github/ISSUE_TEMPLATE/adjust-rule.md +0 -0
  15. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/.github/ISSUE_TEMPLATE/rule-request.md +0 -0
  16. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/.gitignore +0 -0
  17. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/.isort.cfg +0 -0
  18. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/CHANGELOG.md +0 -0
  19. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/LICENSE +0 -0
  20. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/Makefile +0 -0
  21. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/README.md +0 -0
  22. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/flake8_simplify/__init__.py +0 -0
  23. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/flake8_simplify/rules/__init__.py +0 -0
  24. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/flake8_simplify/rules/ast_assign.py +0 -0
  25. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/flake8_simplify/rules/ast_bool_op.py +0 -0
  26. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/flake8_simplify/rules/ast_classdef.py +0 -0
  27. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/flake8_simplify/rules/ast_compare.py +0 -0
  28. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/flake8_simplify/rules/ast_expr.py +0 -0
  29. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/flake8_simplify/rules/ast_for.py +0 -0
  30. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/flake8_simplify/rules/ast_ifexp.py +0 -0
  31. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/flake8_simplify/rules/ast_subscript.py +0 -0
  32. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/flake8_simplify/rules/ast_try.py +0 -0
  33. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/flake8_simplify/rules/ast_unary_op.py +0 -0
  34. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/flake8_simplify/rules/ast_with.py +0 -0
  35. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/mutmut-test.sh +0 -0
  36. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/requirements/dev.in +0 -0
  37. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/requirements/dev.txt +0 -0
  38. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/requirements/lint.in +0 -0
  39. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/requirements/lint.txt +0 -0
  40. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/tests/__init__.py +0 -0
  41. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/tests/test_100_rules.py +0 -0
  42. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/tests/test_200_rules.py +0 -0
  43. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/tests/test_300_rules.py +0 -0
  44. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/tests/test_400_rules.py +0 -0
  45. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/tests/test_900_rules.py +0 -0
  46. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/tests/test_simplify.py +0 -0
  47. {flake8_simplify-0.21.0 → flake8_simplify-0.22.0}/tox.ini +0 -0
@@ -0,0 +1,9 @@
1
+ # Set update schedule for GitHub Actions
2
+
3
+ version: 2
4
+ updates:
5
+
6
+ - package-ecosystem: "github-actions"
7
+ directory: "/"
8
+ schedule:
9
+ interval: "daily"
@@ -18,9 +18,9 @@ jobs:
18
18
  python-version: [3.8]
19
19
 
20
20
  steps:
21
- - uses: actions/checkout@v3
21
+ - uses: actions/checkout@v4
22
22
  - name: Set up Python ${{ matrix.python-version }}
23
- uses: actions/setup-python@v4
23
+ uses: actions/setup-python@v5
24
24
  with:
25
25
  python-version: ${{ matrix.python-version }}
26
26
  - name: Install dependencies
@@ -18,9 +18,9 @@ jobs:
18
18
  python-version: [3.8, 3.9, "3.10", 3.11, 3.12]
19
19
 
20
20
  steps:
21
- - uses: actions/checkout@v3
21
+ - uses: actions/checkout@v4
22
22
  - name: Set up Python ${{ matrix.python-version }}
23
- uses: actions/setup-python@v4
23
+ uses: actions/setup-python@v5
24
24
  with:
25
25
  python-version: ${{ matrix.python-version }}
26
26
  allow-prereleases: true
@@ -12,16 +12,14 @@ repos:
12
12
  - id: end-of-file-fixer
13
13
  - id: trailing-whitespace
14
14
  - id: mixed-line-ending
15
+ args: ['--fix=lf']
15
16
  - id: check-added-large-files
16
17
  args: ['--maxkb=500']
17
- # - repo: https://gitlab.com/pycqa/flake8
18
- # rev: 3.8.3
19
- # hooks:
20
- # - id: flake8
21
18
  - repo: https://github.com/psf/black
22
19
  rev: 23.9.1
23
20
  hooks:
24
21
  - id: black
22
+ args: [--target-version, py36]
25
23
  - repo: https://github.com/asottile/blacken-docs
26
24
  rev: 1.16.0
27
25
  hooks:
@@ -37,8 +35,14 @@ repos:
37
35
  hooks:
38
36
  - id: pyupgrade
39
37
  args: [--py36-plus]
38
+ - repo: https://github.com/pycqa/flake8
39
+ rev: 6.1.0
40
+ hooks:
41
+ - id: flake8
42
+ args: ["--ignore", "E,W,F"]
43
+
40
44
  - repo: https://github.com/pre-commit/mirrors-mypy
41
- rev: v1.5.1
45
+ rev: 'v1.5.1'
42
46
  hooks:
43
47
  - id: mypy
44
48
  - repo: https://github.com/pre-commit/mirrors-isort
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: flake8_simplify
3
- Version: 0.21.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>
@@ -21,6 +21,7 @@ Classifier: Programming Language :: Python :: 3.10
21
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"
@@ -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, (ast.Str, ast.Constant))
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.s
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.Str):
165
- names.append(f"'{arg.s}'")
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)}"
@@ -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.Str)
45
- and node.test.comparators[0].s == "__main__"
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.Str):
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].s: value}
256
- elif isinstance(node.test.comparators[0], ast.Num):
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].n: to_source(node.body[0].value)
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.Str):
285
- key = child.test.comparators[0].s
286
- elif isinstance(child.test.comparators[0], ast.Num):
287
- key = child.test.comparators[0].n
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.Num) and expr.value.n == 1)
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.21.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",
@@ -1,7 +0,0 @@
1
- # Core Library
2
- import ast
3
-
4
- # ast.Constant in Python 3.8, ast.NameConstant in Python 3.6 and 3.7
5
- BOOL_CONST_TYPES = (ast.Constant, ast.NameConstant)
6
- AST_CONST_TYPES = (ast.Constant, ast.NameConstant, ast.Str, ast.Num)
7
- STR_TYPES = (ast.Constant, ast.Str)