flake8_simplify 0.20.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 (45) hide show
  1. flake8_simplify-0.20.0/.coveragerc +22 -0
  2. flake8_simplify-0.20.0/.flake8 +5 -0
  3. flake8_simplify-0.20.0/.github/ISSUE_TEMPLATE/adjust-rule.md +25 -0
  4. flake8_simplify-0.20.0/.github/ISSUE_TEMPLATE/rule-request.md +22 -0
  5. flake8_simplify-0.20.0/.github/workflows/lint.yml +36 -0
  6. flake8_simplify-0.20.0/.github/workflows/unit-test.yml +33 -0
  7. flake8_simplify-0.20.0/.gitignore +140 -0
  8. flake8_simplify-0.20.0/.isort.cfg +11 -0
  9. flake8_simplify-0.20.0/.pre-commit-config.yaml +44 -0
  10. flake8_simplify-0.20.0/CHANGELOG.md +102 -0
  11. flake8_simplify-0.20.0/LICENSE +21 -0
  12. flake8_simplify-0.20.0/Makefile +26 -0
  13. flake8_simplify-0.20.0/PKG-INFO +656 -0
  14. flake8_simplify-0.20.0/README.md +627 -0
  15. flake8_simplify-0.20.0/flake8_simplify/__init__.py +177 -0
  16. flake8_simplify-0.20.0/flake8_simplify/constants.py +7 -0
  17. flake8_simplify-0.20.0/flake8_simplify/rules/__init__.py +0 -0
  18. flake8_simplify-0.20.0/flake8_simplify/rules/ast_assign.py +116 -0
  19. flake8_simplify-0.20.0/flake8_simplify/rules/ast_bool_op.py +219 -0
  20. flake8_simplify-0.20.0/flake8_simplify/rules/ast_call.py +235 -0
  21. flake8_simplify-0.20.0/flake8_simplify/rules/ast_classdef.py +24 -0
  22. flake8_simplify-0.20.0/flake8_simplify/rules/ast_compare.py +90 -0
  23. flake8_simplify-0.20.0/flake8_simplify/rules/ast_expr.py +103 -0
  24. flake8_simplify-0.20.0/flake8_simplify/rules/ast_for.py +207 -0
  25. flake8_simplify-0.20.0/flake8_simplify/rules/ast_if.py +515 -0
  26. flake8_simplify-0.20.0/flake8_simplify/rules/ast_ifexp.py +68 -0
  27. flake8_simplify-0.20.0/flake8_simplify/rules/ast_subscript.py +59 -0
  28. flake8_simplify-0.20.0/flake8_simplify/rules/ast_try.py +96 -0
  29. flake8_simplify-0.20.0/flake8_simplify/rules/ast_unary_op.py +106 -0
  30. flake8_simplify-0.20.0/flake8_simplify/rules/ast_with.py +62 -0
  31. flake8_simplify-0.20.0/flake8_simplify/utils.py +247 -0
  32. flake8_simplify-0.20.0/mutmut-test.sh +3 -0
  33. flake8_simplify-0.20.0/pyproject.toml +89 -0
  34. flake8_simplify-0.20.0/requirements/dev.in +8 -0
  35. flake8_simplify-0.20.0/requirements/dev.txt +94 -0
  36. flake8_simplify-0.20.0/requirements/lint.in +15 -0
  37. flake8_simplify-0.20.0/requirements/lint.txt +84 -0
  38. flake8_simplify-0.20.0/tests/__init__.py +13 -0
  39. flake8_simplify-0.20.0/tests/test_100_rules.py +523 -0
  40. flake8_simplify-0.20.0/tests/test_200_rules.py +71 -0
  41. flake8_simplify-0.20.0/tests/test_300_rules.py +19 -0
  42. flake8_simplify-0.20.0/tests/test_400_rules.py +131 -0
  43. flake8_simplify-0.20.0/tests/test_900_rules.py +206 -0
  44. flake8_simplify-0.20.0/tests/test_simplify.py +114 -0
  45. flake8_simplify-0.20.0/tox.ini +18 -0
@@ -0,0 +1,22 @@
1
+ [run]
2
+ branch = True
3
+ omit = setup.py,tests/*
4
+
5
+ [report]
6
+ # Regexes for lines to exclude from consideration
7
+ exclude_lines =
8
+ # Have to re-enable the standard pragma
9
+ pragma: no cover
10
+
11
+ # Don't complain about missing debug-only code:
12
+ def __repr__
13
+ def __str__
14
+ if self\.debug
15
+
16
+ # Don't complain if tests don't hit defensive assertion code:
17
+ raise AssertionError
18
+ raise NotImplementedError
19
+
20
+ # Don't complain if non-runnable code isn't run:
21
+ if 0:
22
+ if __name__ == .__main__.:
@@ -0,0 +1,5 @@
1
+ [flake8]
2
+ ignore = E203, W503, PT007
3
+ exclude = build/*
4
+ per-file-ignores =
5
+ tests/*: ASS001
@@ -0,0 +1,25 @@
1
+ ---
2
+ name: Adjust rule
3
+ about: Ask for an adjustment of an existing rule
4
+ title: "[Adjust Rule]"
5
+ labels: enhancement
6
+ assignees: MartinThoma
7
+
8
+ ---
9
+
10
+ ## Desired change
11
+
12
+ * **Rule(s)**: SIM986, SIM987
13
+ * **Adjustment**: In which way should it/they be adjusted?
14
+
15
+ ## Explanation
16
+
17
+ Why is the adjustment necessary / better?
18
+
19
+ ## Example
20
+
21
+ This is an example where the mentioned rule(s) would currently be suboptimal:
22
+
23
+ ```python
24
+ # Your code goes here
25
+ ```
@@ -0,0 +1,22 @@
1
+ ---
2
+ name: Rule request
3
+ about: Suggest a new rule to add to flake8-simplify
4
+ title: "[New Rule]"
5
+ labels: enhancement
6
+ assignees: MartinThoma
7
+
8
+ ---
9
+
10
+ ## Explanation
11
+
12
+ Explain briefly why you think this makes the code simpler.
13
+
14
+ ## Example
15
+
16
+ ```python
17
+ # Bad
18
+ ... # your bad code goes here
19
+
20
+ # Good
21
+ ... # your improved code goes here
22
+ ```
@@ -0,0 +1,36 @@
1
+ # This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2
+ # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3
+
4
+ name: Lint
5
+
6
+ on:
7
+ push:
8
+ branches: [ master ]
9
+ pull_request:
10
+ branches: [ master ]
11
+
12
+ jobs:
13
+ build:
14
+
15
+ runs-on: ubuntu-latest
16
+ strategy:
17
+ matrix:
18
+ python-version: [3.8]
19
+
20
+ steps:
21
+ - uses: actions/checkout@v3
22
+ - name: Set up Python ${{ matrix.python-version }}
23
+ uses: actions/setup-python@v4
24
+ with:
25
+ python-version: ${{ matrix.python-version }}
26
+ - name: Install dependencies
27
+ run: |
28
+ python -m pip install --upgrade pip
29
+ pip install -r requirements/lint.txt
30
+ pip install .
31
+ - name: Test with mypy
32
+ run: |
33
+ mypy flake8_simplify
34
+ - name: Test with flake8
35
+ run: |
36
+ flake8 .
@@ -0,0 +1,33 @@
1
+ # This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2
+ # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3
+
4
+ name: Unit Tests
5
+
6
+ on:
7
+ push:
8
+ branches: [ master ]
9
+ pull_request:
10
+ branches: [ master ]
11
+
12
+ jobs:
13
+ build:
14
+
15
+ runs-on: ubuntu-latest
16
+ strategy:
17
+ matrix:
18
+ python-version: [3.7, 3.8, 3.9, "3.10", 3.11]
19
+
20
+ steps:
21
+ - uses: actions/checkout@v3
22
+ - name: Set up Python ${{ matrix.python-version }}
23
+ uses: actions/setup-python@v4
24
+ with:
25
+ python-version: ${{ matrix.python-version }}
26
+ - name: Install dependencies
27
+ run: |
28
+ python -m pip install --upgrade pip
29
+ pip install -r requirements/dev.txt
30
+ pip install .
31
+ - name: Test with pytest
32
+ run: |
33
+ pytest -vv
@@ -0,0 +1,140 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ pip-wheel-metadata/
24
+ share/python-wheels/
25
+ *.egg-info/
26
+ .installed.cfg
27
+ *.egg
28
+ MANIFEST
29
+
30
+ # PyInstaller
31
+ # Usually these files are written by a python script from a template
32
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
33
+ *.manifest
34
+ *.spec
35
+
36
+ # Installer logs
37
+ pip-log.txt
38
+ pip-delete-this-directory.txt
39
+
40
+ # Unit test / coverage reports
41
+ htmlcov/
42
+ .tox/
43
+ .nox/
44
+ .coverage
45
+ .coverage.*
46
+ .cache
47
+ nosetests.xml
48
+ coverage.xml
49
+ *.cover
50
+ *.py,cover
51
+ .hypothesis/
52
+ .pytest_cache/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ target/
76
+
77
+ # Jupyter Notebook
78
+ .ipynb_checkpoints
79
+
80
+ # IPython
81
+ profile_default/
82
+ ipython_config.py
83
+
84
+ # pyenv
85
+ .python-version
86
+
87
+ # pipenv
88
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
90
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
91
+ # install all needed dependencies.
92
+ #Pipfile.lock
93
+
94
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow
95
+ __pypackages__/
96
+
97
+ # Celery stuff
98
+ celerybeat-schedule
99
+ celerybeat.pid
100
+
101
+ # SageMath parsed files
102
+ *.sage.py
103
+
104
+ # Environments
105
+ .env
106
+ .venv
107
+ env/
108
+ venv/
109
+ ENV/
110
+ env.bak/
111
+ venv.bak/
112
+
113
+ # Spyder project settings
114
+ .spyderproject
115
+ .spyproject
116
+
117
+ # Rope project settings
118
+ .ropeproject
119
+
120
+ # mkdocs documentation
121
+ /site
122
+
123
+ # mypy
124
+ .mypy_cache/
125
+ .dmypy.json
126
+ dmypy.json
127
+
128
+ # Pyre type checker
129
+ .pyre/
130
+
131
+ # mutmut
132
+ .mutmut-cache
133
+ mutmut-results.xml
134
+ mutmut-results.html
135
+ tests/reports/
136
+
137
+ .vscode/
138
+ *.code-workspace
139
+
140
+ html/
@@ -0,0 +1,11 @@
1
+ [settings]
2
+ line_length=79
3
+ indent=' '
4
+ multi_line_output=3
5
+ length_sort=0
6
+ import_heading_stdlib=Core Library
7
+ import_heading_firstparty=First party
8
+ import_heading_thirdparty=Third party
9
+ import_heading_localfolder=Local
10
+ known_third_party =astor,pytest
11
+ include_trailing_comma=True
@@ -0,0 +1,44 @@
1
+ # pre-commit run --all-files
2
+ repos:
3
+ - repo: https://github.com/pre-commit/pre-commit-hooks
4
+ rev: v4.1.0
5
+ hooks:
6
+ - id: check-ast
7
+ - id: check-byte-order-marker
8
+ - id: check-case-conflict
9
+ - id: check-docstring-first
10
+ - id: check-yaml
11
+ - id: debug-statements
12
+ - id: end-of-file-fixer
13
+ - id: trailing-whitespace
14
+ - id: mixed-line-ending
15
+ # - repo: https://gitlab.com/pycqa/flake8
16
+ # rev: 3.8.3
17
+ # hooks:
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
31
+ - repo: https://github.com/psf/black
32
+ rev: 22.1.0
33
+ hooks:
34
+ - id: black
35
+ - repo: https://github.com/asottile/pyupgrade
36
+ rev: v2.31.1
37
+ hooks:
38
+ - id: pyupgrade
39
+ args: [--py36-plus]
40
+ - repo: https://github.com/asottile/blacken-docs
41
+ rev: v1.12.1
42
+ hooks:
43
+ - id: blacken-docs
44
+ additional_dependencies: [black==22.1.0]
@@ -0,0 +1,102 @@
1
+ Release History
2
+ ===============
3
+
4
+ ### 0.20.0
5
+ Release on 30.03.2023
6
+
7
+ New rules:
8
+
9
+ * SIM910: dict.get(key, None) → dict.get(key)
10
+
11
+ ### 0.19.3
12
+ Released on 28.07.2022
13
+
14
+ * SIM104: Remove false-positives in case the loop is not a direct child of
15
+ an async function (#147) by @wyuenho
16
+
17
+ ### 0.19.2
18
+ Released on 29.03.2022
19
+
20
+ Removed rules due to false-positives:
21
+
22
+ * SIM903: Positional-only parameters cannot be identified in the AST
23
+ * SIM909: Class attribute assignments are not reflexive assignments
24
+
25
+ ### 0.19.1
26
+ Released on 29.03.2022
27
+
28
+ Removed rules due to false-positives:
29
+
30
+ * SIM902: Positional-only parameters cannot be identified in the AST
31
+ * SIM908: Ensure that the assigned name is equal to the name in the if.test
32
+
33
+ ### 0.19.0
34
+ Released on 28.03.2022
35
+
36
+ New rules:
37
+
38
+ * SIM902: Use keyword-argument instead of magic boolean
39
+ * SIM903: Use keyword-argument instead of magic number
40
+ * SIM907: Use Optional[Type] instead of Union[Type, None]
41
+ * SIM908: Use ".get" instead of "if X in dict: dict[X]"
42
+ * SIM909: Avoid reflexive assignments
43
+
44
+ Removed rules due to false-positives:
45
+
46
+ * SIM119: Hinting to dataclasses in a proper way is hard
47
+
48
+ Fixed false-positives:
49
+
50
+ * SIM108: Encourage the use of a terniary operator only when it is
51
+ actually possible
52
+ * SIM111: Recommending to use all/any only if there is no side-effect after
53
+ the for-loop
54
+ * SIM116: When a function is called, we cannot simply convert the
55
+ if-else block to a dictionary
56
+
57
+ ### 0.18.2
58
+ Released on 26.03.2022
59
+
60
+ Removed rules due to false-positives:
61
+
62
+ * SIM204: Use 'a >= b' instead of 'not (a < b)'
63
+ * SIM205: Use 'a > b' instead of 'not (a <= b)'
64
+ * SIM206: Use 'a <= b' instead of 'not (a > b)'
65
+ * SIM207: Use 'a < b' instead of 'not (a <= b)'
66
+
67
+ Fixed false-positives:
68
+
69
+ * SIM113: Use enumerate instead of manually incrementing a counter
70
+
71
+ Maintenance:
72
+
73
+ * Split a way-too-big module into smaller modules
74
+
75
+ ### 0.18.1
76
+ Released on 24.02.2022
77
+
78
+ Only distribute the `flake8_simplify` package. `0.18.0` did also distribute
79
+ the `tests` package which caused issues in some systems.
80
+
81
+ ### 0.18.0
82
+ Released on 20.02.2022
83
+
84
+ New rules since 0.17.0:
85
+
86
+ * SIM906: Merge nested os.path.join calls
87
+
88
+ Maintenance:
89
+
90
+ * Restructure repository to simplify future development. It's time for more
91
+ than one file.
92
+
93
+ ### 0.17.1
94
+ Released on 16.02.2022
95
+
96
+ * SIM904: Removed false-positives that happened when a dictionary value was
97
+ derived from another value of the same dictionary.
98
+
99
+ ### 0.17.0
100
+ Released on 13.02.2022
101
+
102
+ * SIM905: Added
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Martin Thoma
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,26 @@
1
+ maint:
2
+ pre-commit autoupdate && pre-commit run --all-files
3
+ pip-compile -U requirements/lint.in
4
+ pip-compile -U requirements/dev.in
5
+
6
+ lint:
7
+ mypy flake8_simplify --strict
8
+ flake8 .
9
+
10
+ upload:
11
+ make clean
12
+ flit publish
13
+
14
+ clean:
15
+ pyclean .
16
+ rm -rf *.pyc build dist tests/reports docs/build .pytest_cache .tox .coverage html/
17
+
18
+ mutmut-run:
19
+ mutmut run --paths-to-mutate flake8_simplify.py
20
+
21
+ mutmut-results:
22
+ mutmut html
23
+
24
+ bandit:
25
+ # Python3 only: B322 is save
26
+ bandit -r mpu -s B322