deadcode 2.3.1__tar.gz → 2.4.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.
- {deadcode-2.3.1 → deadcode-2.4.0}/PKG-INFO +17 -12
- {deadcode-2.3.1 → deadcode-2.4.0}/README.md +15 -8
- deadcode-2.4.0/deadcode/__init__.py +6 -0
- {deadcode-2.3.1 → deadcode-2.4.0}/deadcode/actions/fix_or_show_unused_code.py +21 -15
- deadcode-2.4.0/deadcode/actions/get_unused_names_error_message.py +37 -0
- {deadcode-2.3.1 → deadcode-2.4.0}/deadcode/actions/parse_arguments.py +7 -5
- {deadcode-2.3.1 → deadcode-2.4.0}/deadcode/data_types.py +2 -1
- {deadcode-2.3.1 → deadcode-2.4.0}/deadcode/utils/fix_indent.py +1 -0
- {deadcode-2.3.1 → deadcode-2.4.0}/pyproject.toml +3 -19
- deadcode-2.3.1/deadcode/actions/get_unused_names_error_message.py +0 -35
- deadcode-2.3.1/deadcode/visitor/__init__.py +0 -0
- {deadcode-2.3.1 → deadcode-2.4.0}/.gitignore +0 -0
- {deadcode-2.3.1 → deadcode-2.4.0}/LICENSE +0 -0
- {deadcode-2.3.1/deadcode → deadcode-2.4.0/deadcode/actions}/__init__.py +0 -0
- {deadcode-2.3.1 → deadcode-2.4.0}/deadcode/actions/find_python_filenames.py +0 -0
- {deadcode-2.3.1 → deadcode-2.4.0}/deadcode/actions/find_unused_names.py +0 -0
- {deadcode-2.3.1 → deadcode-2.4.0}/deadcode/actions/merge_overlaping_file_parts.py +0 -0
- {deadcode-2.3.1 → deadcode-2.4.0}/deadcode/actions/parse_abstract_syntax_tree.py +0 -0
- {deadcode-2.3.1 → deadcode-2.4.0}/deadcode/actions/remove_file_parts_from_content.py +0 -0
- {deadcode-2.3.1 → deadcode-2.4.0}/deadcode/cli.py +0 -0
- {deadcode-2.3.1 → deadcode-2.4.0}/deadcode/constants.py +0 -0
- {deadcode-2.3.1/deadcode/actions → deadcode-2.4.0/deadcode/utils}/__init__.py +0 -0
- {deadcode-2.3.1 → deadcode-2.4.0}/deadcode/utils/add_colors_to_diff.py +0 -0
- {deadcode-2.3.1 → deadcode-2.4.0}/deadcode/utils/base_test_case.py +0 -0
- {deadcode-2.3.1 → deadcode-2.4.0}/deadcode/utils/flatten_lists.py +0 -0
- {deadcode-2.3.1 → deadcode-2.4.0}/deadcode/utils/nested_scopes.py +0 -0
- {deadcode-2.3.1 → deadcode-2.4.0}/deadcode/utils/print_ast.py +0 -0
- {deadcode-2.3.1/deadcode/utils → deadcode-2.4.0/deadcode/visitor}/__init__.py +0 -0
- {deadcode-2.3.1 → deadcode-2.4.0}/deadcode/visitor/code_item.py +0 -0
- {deadcode-2.3.1 → deadcode-2.4.0}/deadcode/visitor/dead_code_visitor.py +0 -0
- {deadcode-2.3.1 → deadcode-2.4.0}/deadcode/visitor/ignore.py +0 -0
- {deadcode-2.3.1 → deadcode-2.4.0}/deadcode/visitor/lines.py +0 -0
- {deadcode-2.3.1 → deadcode-2.4.0}/deadcode/visitor/noqa.py +0 -0
- {deadcode-2.3.1 → deadcode-2.4.0}/deadcode/visitor/utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: deadcode
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.4.0
|
|
4
4
|
Summary: Find and remove dead code.
|
|
5
5
|
Project-URL: homepage, https://github.com/albertas/deadcode
|
|
6
6
|
Project-URL: documentation, https://deadcode.readthedocs.io/
|
|
@@ -11,12 +11,10 @@ Classifier: License :: OSI Approved :: GNU Affero General Public License v3
|
|
|
11
11
|
Classifier: Natural Language :: English
|
|
12
12
|
Classifier: Operating System :: OS Independent
|
|
13
13
|
Classifier: Programming Language :: Python
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
16
14
|
Classifier: Programming Language :: Python :: 3.10
|
|
17
15
|
Classifier: Programming Language :: Python :: 3.11
|
|
18
16
|
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
-
Requires-Python: >=3.
|
|
17
|
+
Requires-Python: >=3.10
|
|
20
18
|
Requires-Dist: tomli>=2.0.1
|
|
21
19
|
Provides-Extra: test
|
|
22
20
|
Requires-Dist: hatch; extra == 'test'
|
|
@@ -32,9 +30,10 @@ Description-Content-Type: text/markdown
|
|
|
32
30
|
<h2 align="center">Find and Fix Unused Python Code</h2>
|
|
33
31
|
|
|
34
32
|
<p align="center">
|
|
35
|
-
<a href="https://github.com/
|
|
33
|
+
<a href="https://github.com/pre-commit/pre-commit"><img src="https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit" alt="pre-commit" style="max-width:100%;"></a>
|
|
36
34
|
<a href="https://pypi.org/project/deadcode/"><img alt="PyPI" src="https://img.shields.io/pypi/v/deadcode"></a>
|
|
37
35
|
<a href="https://pepy.tech/project/deadcode"><img alt="Downloads" src="https://static.pepy.tech/badge/deadcode"></a>
|
|
36
|
+
<a href="https://github.com/albertas/deadcode/blob/main/LICENSE"><img alt="License: AGPLv3" src="https://raw.githubusercontent.com/albertas/deadcode/main/docs/_static/AGPLv3-license.svg"></a>
|
|
38
37
|
</p>
|
|
39
38
|
|
|
40
39
|
|
|
@@ -56,7 +55,7 @@ deadcode . --fix --dry
|
|
|
56
55
|
|
|
57
56
|
To see suggested fixes only for `foo.py` file:
|
|
58
57
|
```shell
|
|
59
|
-
deadcode . --fix --dry foo.py
|
|
58
|
+
deadcode . --fix --dry --only foo.py
|
|
60
59
|
```
|
|
61
60
|
|
|
62
61
|
To fix:
|
|
@@ -82,7 +81,8 @@ ignore-names-in-files = ["migrations"]
|
|
|
82
81
|
| Option | Type | Meaning |
|
|
83
82
|
|-------------------------------------------|------|----------------------------------------------------------------------|
|
|
84
83
|
|`--fix` | - | Automatically remove detected unused code expressions from the code base. |
|
|
85
|
-
|`--dry` | -
|
|
84
|
+
|`--dry` | - | Show changes which would be made in files. |
|
|
85
|
+
|`--only` | list | Filenames (or path expressions), that will be reflected in the output (and modified if needed). |
|
|
86
86
|
|`--exclude` | list | Filenames (or path expressions), which will be completely skipped without being analysed. |
|
|
87
87
|
|`--ignore-names` | list | Removes provided list of names from the output. Regexp expressions to match multiple names can also be provided, e.g. `*Mixin` will match all classes ending with `Mixin`. |
|
|
88
88
|
|`--ignore-names-in-files` | list | Ignores unused names in files, which filenames match provided path expressions. |
|
|
@@ -100,9 +100,9 @@ ignore-names-in-files = ["migrations"]
|
|
|
100
100
|
|
|
101
101
|
|
|
102
102
|
##### Glossory
|
|
103
|
-
name - variable, function or class name.
|
|
104
|
-
body - code block which follows after `:` in function or class definition.
|
|
105
|
-
definition - whole class or function definition expression including its name and body.
|
|
103
|
+
- `name` - variable, function or class name.
|
|
104
|
+
- `body` - code block which follows after `:` in function or class definition.
|
|
105
|
+
- `definition` - whole class or function definition expression including its name and body.
|
|
106
106
|
|
|
107
107
|
|
|
108
108
|
## Rules
|
|
@@ -185,13 +185,11 @@ code base is implemented in.
|
|
|
185
185
|
- [ ] Distinguish between definitions with same name, but different files.
|
|
186
186
|
- [ ] Repeated application of `deadcode` till the output stops changing.
|
|
187
187
|
- [ ] Unreachable code detection and fixing: this should only be scoped for if statements and only limited to primitive variables.
|
|
188
|
-
- [x] `--fix --dry [filenames]` - only show whats about to change in the listed filenames.
|
|
189
188
|
- [ ] Benchmarking performance with larger projects (time, CPU and memory consumption) in order to optimize.
|
|
190
189
|
- [ ] `--fix` could accept a list of filenames as well (only those files would be changed, but the summary could would be full).
|
|
191
190
|
(This might be confusing, because filenames, which have to be considered are provided without any flag, --fix is expected to not accept arguments)
|
|
192
191
|
- [ ] pre-commit-hook.
|
|
193
192
|
- [ ] language server.
|
|
194
|
-
- [x] Use only two digits for error codes instead of 3. Two is plenty and it simplifies usage a bit
|
|
195
193
|
- [ ] DC10: remove code after terminal statements like `raise`, `return`, `break`, `continue` and comes in the same scope.
|
|
196
194
|
- [ ] Add `ignore` and `per-file-ignores` command line and pyproject.toml options, which allows to skip some rules.
|
|
197
195
|
- [ ] Make sure that all rules are being skipped by `noqa` comment and all rules react to `noqa: rule_id` comments.
|
|
@@ -200,8 +198,15 @@ code base is implemented in.
|
|
|
200
198
|
documentation should cleary demonstrate the behaviour/example that "Schema" means "*.Schema".
|
|
201
199
|
- [ ] Redefinition of an existing name makes previous name unreachable, unless it is assigned somehow.
|
|
202
200
|
- [ ] Check if file is still valid/parsable after automatic fixing, if not: halt the change and report error.
|
|
201
|
+
- [ ] Investigate ways of extracting and backporting Python3.10+ `ast` implementation to lower Python versions.
|
|
203
202
|
|
|
204
203
|
## Release notes
|
|
204
|
+
- v2.4.0:
|
|
205
|
+
- Add `--only` option that accepts filenames only which will be reflected in the output and modified.
|
|
206
|
+
This option can be used with `--fix` and `--fix --dry` options as well as for simple unused code detection without fixing.
|
|
207
|
+
- v2.3.2:
|
|
208
|
+
- Add `pre-commit` hook support.
|
|
209
|
+
- Drop support for Python 3.8 and 3.9 versions, since their `ast` implementation is lacking features.
|
|
205
210
|
- v2.3.1:
|
|
206
211
|
- Started analysing files in bytes instead of trying to convert them into UTF-8 encoded strings.
|
|
207
212
|
- Improved automatic removal of unused imports.
|
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
<h2 align="center">Find and Fix Unused Python Code</h2>
|
|
4
4
|
|
|
5
5
|
<p align="center">
|
|
6
|
-
<a href="https://github.com/
|
|
6
|
+
<a href="https://github.com/pre-commit/pre-commit"><img src="https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit" alt="pre-commit" style="max-width:100%;"></a>
|
|
7
7
|
<a href="https://pypi.org/project/deadcode/"><img alt="PyPI" src="https://img.shields.io/pypi/v/deadcode"></a>
|
|
8
8
|
<a href="https://pepy.tech/project/deadcode"><img alt="Downloads" src="https://static.pepy.tech/badge/deadcode"></a>
|
|
9
|
+
<a href="https://github.com/albertas/deadcode/blob/main/LICENSE"><img alt="License: AGPLv3" src="https://raw.githubusercontent.com/albertas/deadcode/main/docs/_static/AGPLv3-license.svg"></a>
|
|
9
10
|
</p>
|
|
10
11
|
|
|
11
12
|
|
|
@@ -27,7 +28,7 @@ deadcode . --fix --dry
|
|
|
27
28
|
|
|
28
29
|
To see suggested fixes only for `foo.py` file:
|
|
29
30
|
```shell
|
|
30
|
-
deadcode . --fix --dry foo.py
|
|
31
|
+
deadcode . --fix --dry --only foo.py
|
|
31
32
|
```
|
|
32
33
|
|
|
33
34
|
To fix:
|
|
@@ -53,7 +54,8 @@ ignore-names-in-files = ["migrations"]
|
|
|
53
54
|
| Option | Type | Meaning |
|
|
54
55
|
|-------------------------------------------|------|----------------------------------------------------------------------|
|
|
55
56
|
|`--fix` | - | Automatically remove detected unused code expressions from the code base. |
|
|
56
|
-
|`--dry` | -
|
|
57
|
+
|`--dry` | - | Show changes which would be made in files. |
|
|
58
|
+
|`--only` | list | Filenames (or path expressions), that will be reflected in the output (and modified if needed). |
|
|
57
59
|
|`--exclude` | list | Filenames (or path expressions), which will be completely skipped without being analysed. |
|
|
58
60
|
|`--ignore-names` | list | Removes provided list of names from the output. Regexp expressions to match multiple names can also be provided, e.g. `*Mixin` will match all classes ending with `Mixin`. |
|
|
59
61
|
|`--ignore-names-in-files` | list | Ignores unused names in files, which filenames match provided path expressions. |
|
|
@@ -71,9 +73,9 @@ ignore-names-in-files = ["migrations"]
|
|
|
71
73
|
|
|
72
74
|
|
|
73
75
|
##### Glossory
|
|
74
|
-
name - variable, function or class name.
|
|
75
|
-
body - code block which follows after `:` in function or class definition.
|
|
76
|
-
definition - whole class or function definition expression including its name and body.
|
|
76
|
+
- `name` - variable, function or class name.
|
|
77
|
+
- `body` - code block which follows after `:` in function or class definition.
|
|
78
|
+
- `definition` - whole class or function definition expression including its name and body.
|
|
77
79
|
|
|
78
80
|
|
|
79
81
|
## Rules
|
|
@@ -156,13 +158,11 @@ code base is implemented in.
|
|
|
156
158
|
- [ ] Distinguish between definitions with same name, but different files.
|
|
157
159
|
- [ ] Repeated application of `deadcode` till the output stops changing.
|
|
158
160
|
- [ ] Unreachable code detection and fixing: this should only be scoped for if statements and only limited to primitive variables.
|
|
159
|
-
- [x] `--fix --dry [filenames]` - only show whats about to change in the listed filenames.
|
|
160
161
|
- [ ] Benchmarking performance with larger projects (time, CPU and memory consumption) in order to optimize.
|
|
161
162
|
- [ ] `--fix` could accept a list of filenames as well (only those files would be changed, but the summary could would be full).
|
|
162
163
|
(This might be confusing, because filenames, which have to be considered are provided without any flag, --fix is expected to not accept arguments)
|
|
163
164
|
- [ ] pre-commit-hook.
|
|
164
165
|
- [ ] language server.
|
|
165
|
-
- [x] Use only two digits for error codes instead of 3. Two is plenty and it simplifies usage a bit
|
|
166
166
|
- [ ] DC10: remove code after terminal statements like `raise`, `return`, `break`, `continue` and comes in the same scope.
|
|
167
167
|
- [ ] Add `ignore` and `per-file-ignores` command line and pyproject.toml options, which allows to skip some rules.
|
|
168
168
|
- [ ] Make sure that all rules are being skipped by `noqa` comment and all rules react to `noqa: rule_id` comments.
|
|
@@ -171,8 +171,15 @@ code base is implemented in.
|
|
|
171
171
|
documentation should cleary demonstrate the behaviour/example that "Schema" means "*.Schema".
|
|
172
172
|
- [ ] Redefinition of an existing name makes previous name unreachable, unless it is assigned somehow.
|
|
173
173
|
- [ ] Check if file is still valid/parsable after automatic fixing, if not: halt the change and report error.
|
|
174
|
+
- [ ] Investigate ways of extracting and backporting Python3.10+ `ast` implementation to lower Python versions.
|
|
174
175
|
|
|
175
176
|
## Release notes
|
|
177
|
+
- v2.4.0:
|
|
178
|
+
- Add `--only` option that accepts filenames only which will be reflected in the output and modified.
|
|
179
|
+
This option can be used with `--fix` and `--fix --dry` options as well as for simple unused code detection without fixing.
|
|
180
|
+
- v2.3.2:
|
|
181
|
+
- Add `pre-commit` hook support.
|
|
182
|
+
- Drop support for Python 3.8 and 3.9 versions, since their `ast` implementation is lacking features.
|
|
176
183
|
- v2.3.1:
|
|
177
184
|
- Started analysing files in bytes instead of trying to convert them into UTF-8 encoded strings.
|
|
178
185
|
- Improved automatic removal of unused imports.
|
|
@@ -38,22 +38,28 @@ def fix_or_show_unused_code(unused_items: Iterable[CodeItem], args: Args) -> str
|
|
|
38
38
|
updated_file_content_lines = remove_file_parts_from_content(file_content_lines, unused_file_parts)
|
|
39
39
|
updated_file_content = b''.join(updated_file_content_lines)
|
|
40
40
|
if updated_file_content.strip():
|
|
41
|
-
if
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
41
|
+
if not args.only or _match(filename, args.only):
|
|
42
|
+
if args.dry:
|
|
43
|
+
with open(filename, 'rb') as f:
|
|
44
|
+
filename_bytes = filename.encode()
|
|
45
|
+
diff = diff_bytes(
|
|
46
|
+
unified_diff,
|
|
47
|
+
f.readlines(),
|
|
48
|
+
updated_file_content_lines,
|
|
49
|
+
fromfile=filename_bytes,
|
|
50
|
+
tofile=filename_bytes,
|
|
51
|
+
)
|
|
52
|
+
# TODO: consider printing result instantly to save memory
|
|
53
|
+
result_chunk = b''.join(diff)
|
|
54
|
+
if args.no_color:
|
|
55
|
+
result.append(result_chunk)
|
|
56
|
+
else:
|
|
57
|
+
result.append(add_colors_to_diff(result_chunk))
|
|
52
58
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
59
|
+
elif args.fix:
|
|
60
|
+
with open(filename, 'wb') as f:
|
|
61
|
+
# TODO: is there a method writelines?
|
|
62
|
+
f.write(updated_file_content)
|
|
57
63
|
else:
|
|
58
64
|
os.remove(filename)
|
|
59
65
|
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
from typing import Iterable, Optional
|
|
2
|
+
|
|
3
|
+
from deadcode.data_types import Args
|
|
4
|
+
from deadcode.visitor.code_item import CodeItem
|
|
5
|
+
from deadcode.visitor.ignore import _match
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def get_unused_names_error_message(unused_names: Iterable[CodeItem], args: Args) -> Optional[str]:
|
|
9
|
+
unused_names = list(unused_names)
|
|
10
|
+
|
|
11
|
+
if not unused_names:
|
|
12
|
+
return None
|
|
13
|
+
|
|
14
|
+
if args.quiet:
|
|
15
|
+
return ''
|
|
16
|
+
|
|
17
|
+
if args.count:
|
|
18
|
+
return f'{len(unused_names)}'
|
|
19
|
+
|
|
20
|
+
messages = []
|
|
21
|
+
for item in unused_names:
|
|
22
|
+
if not args.only or _match(item.filename, args.only):
|
|
23
|
+
message = f'{item.filename_with_position} \033[91m{item.error_code}\033[0m '
|
|
24
|
+
message += item.message or (
|
|
25
|
+
f"{item.type_.replace('_', ' ').capitalize()} " f"`\033[1m{item.name}\033[0m` " f"is never used"
|
|
26
|
+
)
|
|
27
|
+
if args.no_color:
|
|
28
|
+
message = message.replace('\033[91m', '').replace('\033[1m', '').replace('\033[0m', '')
|
|
29
|
+
messages.append(message)
|
|
30
|
+
|
|
31
|
+
if args.fix:
|
|
32
|
+
message = f"\nRemoved \033[1m{len(messages)}\033[0m unused code item{'s' if len(messages) > 1 else ''}!"
|
|
33
|
+
if args.no_color:
|
|
34
|
+
message = message.replace('\x1b[1m', '').replace('\x1b[0m', '')
|
|
35
|
+
messages.append(message)
|
|
36
|
+
|
|
37
|
+
return '\n'.join(messages)
|
|
@@ -36,9 +36,15 @@ def parse_arguments(args: Optional[List[str]]) -> Args:
|
|
|
36
36
|
parser.add_argument(
|
|
37
37
|
'--dry',
|
|
38
38
|
help='Show changes which would be made in files with --fix option.',
|
|
39
|
+
action='store_true',
|
|
40
|
+
default=False,
|
|
41
|
+
)
|
|
42
|
+
parser.add_argument(
|
|
43
|
+
'--only',
|
|
44
|
+
help='Filenames (or path expressions), that will be reflected in the output and modified.',
|
|
39
45
|
nargs='*',
|
|
40
46
|
action='append',
|
|
41
|
-
default=[
|
|
47
|
+
default=[],
|
|
42
48
|
type=str,
|
|
43
49
|
)
|
|
44
50
|
parser.add_argument(
|
|
@@ -200,10 +206,6 @@ def parse_arguments(args: Optional[List[str]]) -> Args:
|
|
|
200
206
|
if key in parsed_args:
|
|
201
207
|
parsed_args[key].extend(item)
|
|
202
208
|
|
|
203
|
-
# Show changes for only provided files instead of all
|
|
204
|
-
if len(parsed_args['dry']) > 1 or '--dry' not in args:
|
|
205
|
-
parsed_args['dry'].remove('__all_files__')
|
|
206
|
-
|
|
207
209
|
# Do not fix if dry option is provided:
|
|
208
210
|
if parsed_args['dry']:
|
|
209
211
|
parsed_args['fix'] = False
|
|
@@ -14,7 +14,8 @@ Pathname = str # Can contain wildewards
|
|
|
14
14
|
class Args:
|
|
15
15
|
fix: bool = False
|
|
16
16
|
verbose: bool = False
|
|
17
|
-
dry:
|
|
17
|
+
dry: bool = False
|
|
18
|
+
only: Iterable[Pathname] = ()
|
|
18
19
|
paths: Iterable[Pathname] = ()
|
|
19
20
|
exclude: Iterable[Pathname] = ()
|
|
20
21
|
ignore_definitions: Iterable[Pathname] = ()
|
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "deadcode"
|
|
3
|
-
version = "2.
|
|
3
|
+
version = "2.4.0"
|
|
4
4
|
authors = [
|
|
5
5
|
{name = "Albertas Gimbutas", email = "albertasgim@gmail.com"},
|
|
6
6
|
]
|
|
7
7
|
description = "Find and remove dead code."
|
|
8
8
|
readme = "README.md"
|
|
9
|
-
requires-python = ">= 3.
|
|
9
|
+
requires-python = ">= 3.10"
|
|
10
10
|
classifiers = [
|
|
11
11
|
"Development Status :: 3 - Alpha",
|
|
12
12
|
"License :: OSI Approved :: GNU Affero General Public License v3",
|
|
13
13
|
"Natural Language :: English",
|
|
14
14
|
"Operating System :: OS Independent",
|
|
15
15
|
"Programming Language :: Python",
|
|
16
|
-
"Programming Language :: Python :: 3.8",
|
|
17
|
-
"Programming Language :: Python :: 3.9",
|
|
18
16
|
"Programming Language :: Python :: 3.10",
|
|
19
17
|
"Programming Language :: Python :: 3.11",
|
|
20
18
|
"Programming Language :: Python :: 3.12",
|
|
@@ -156,10 +154,9 @@ ignore = [
|
|
|
156
154
|
]
|
|
157
155
|
"tests/fix/test_unused_imports.py" = ["F401", "W291"]
|
|
158
156
|
|
|
159
|
-
|
|
160
157
|
[tool.mypy]
|
|
161
158
|
exclude = ["build", "dist", ".venv"]
|
|
162
|
-
python_version = "3.
|
|
159
|
+
python_version = "3.10"
|
|
163
160
|
strict = true
|
|
164
161
|
pretty = true
|
|
165
162
|
color_output = true
|
|
@@ -167,12 +164,6 @@ show_error_codes = true
|
|
|
167
164
|
warn_return_any = true
|
|
168
165
|
warn_unused_configs = true
|
|
169
166
|
|
|
170
|
-
|
|
171
|
-
[tool.isort]
|
|
172
|
-
profile = "black"
|
|
173
|
-
multi_line_output = 3
|
|
174
|
-
known_third_party = ["deadcode"]
|
|
175
|
-
|
|
176
167
|
[tool.deadcode]
|
|
177
168
|
ignore_names = [
|
|
178
169
|
"ERROR_CODES",
|
|
@@ -195,14 +186,7 @@ ignore_names = [
|
|
|
195
186
|
ignore_names_in_files = [
|
|
196
187
|
"deadcode/utils/base_test_case.py"
|
|
197
188
|
]
|
|
198
|
-
|
|
199
189
|
exclude = ["tests"]
|
|
200
190
|
|
|
201
|
-
[tool.black]
|
|
202
|
-
max_line_length = 120
|
|
203
|
-
line_length = 120
|
|
204
|
-
target_version = ["py38"]
|
|
205
|
-
|
|
206
|
-
|
|
207
191
|
[tool.pytest.ini_options]
|
|
208
192
|
addopts = "--cov=. --no-cov-on-fail --cov-fail-under=88.0"
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
from typing import Iterable, Optional
|
|
2
|
-
|
|
3
|
-
from deadcode.data_types import Args
|
|
4
|
-
from deadcode.visitor.code_item import CodeItem
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def get_unused_names_error_message(unused_names: Iterable[CodeItem], args: Args) -> Optional[str]:
|
|
8
|
-
unused_names = list(unused_names)
|
|
9
|
-
|
|
10
|
-
if not unused_names:
|
|
11
|
-
return None
|
|
12
|
-
|
|
13
|
-
if args.quiet:
|
|
14
|
-
return ''
|
|
15
|
-
|
|
16
|
-
if args.count:
|
|
17
|
-
return f'{len(unused_names)}'
|
|
18
|
-
|
|
19
|
-
messages = []
|
|
20
|
-
for item in unused_names:
|
|
21
|
-
message = f'{item.filename_with_position} \033[91m{item.error_code}\033[0m '
|
|
22
|
-
message += item.message or (
|
|
23
|
-
f"{item.type_.replace('_', ' ').capitalize()} " f"`\033[1m{item.name}\033[0m` " f"is never used"
|
|
24
|
-
)
|
|
25
|
-
if args.no_color:
|
|
26
|
-
message = message.replace('\033[91m', '').replace('\033[1m', '').replace('\033[0m', '')
|
|
27
|
-
messages.append(message)
|
|
28
|
-
|
|
29
|
-
if args.fix:
|
|
30
|
-
message = f"\nRemoved \033[1m{len(unused_names)}\033[0m unused code item{'s' if len(unused_names) > 1 else ''}!"
|
|
31
|
-
if args.no_color:
|
|
32
|
-
message = message.replace('\x1b[1m', '').replace('\x1b[0m', '')
|
|
33
|
-
messages.append(message)
|
|
34
|
-
|
|
35
|
-
return '\n'.join(messages)
|
|
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
|