Skip to content

Commit 8b72f0a

Browse files
committed
Use single quotes for formatting
1 parent 0188714 commit 8b72f0a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+909
-746
lines changed

deadcode/actions/find_python_filenames.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ def find_python_filenames(args: Args) -> List[str]:
1616

1717
if _match(path, args.exclude):
1818
if args.verbose:
19-
logger.info(f"Ignoring: {path}")
19+
logger.info(f'Ignoring: {path}')
2020
continue
2121

22-
if path.is_file() and path.suffix == ".py":
22+
if path.is_file() and path.suffix == '.py':
2323
filenames.append(str(path))
2424
elif path.is_dir():
25-
paths += list([str(p) for p in path.glob("*")])
25+
paths += list([str(p) for p in path.glob('*')])
2626
elif not path.exists():
2727
# TODO: unify error logging and reporting
2828
# Maybe a cli flag could be added to stop on error
29-
logger.error(f"Error: {path} could not be found.")
29+
logger.error(f'Error: {path} could not be found.')
3030

3131
if args.verbose:
32-
sep = "\n - "
33-
logger.info(f"Files to be checked for dead code: {sep.join(filenames)}")
32+
sep = '\n - '
33+
logger.info(f'Files to be checked for dead code: {sep.join(filenames)}')
3434
return filenames
3535

3636

deadcode/actions/fix_or_show_unused_code.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,28 @@ def fix_or_show_unused_code(unused_items: Iterable[CodeItem], args: Args) -> str
3636
file_content_lines = f.readlines()
3737

3838
updated_file_content_lines = remove_file_parts_from_content(file_content_lines, unused_file_parts)
39-
updated_file_content = "".join(updated_file_content_lines)
39+
updated_file_content = ''.join(updated_file_content_lines)
4040
if updated_file_content.strip():
41-
if args.dry and ("__all_files__" in args.dry or _match(filename, args.dry)):
42-
with open(filename, "r") as f:
41+
if args.dry and ('__all_files__' in args.dry or _match(filename, args.dry)):
42+
with open(filename, 'r') as f:
4343
diff = unified_diff(f.readlines(), updated_file_content_lines, fromfile=filename, tofile=filename)
4444
# TODO: consider printing result instantly to save memory
45-
diff_str = "".join(diff)
45+
diff_str = ''.join(diff)
4646
if args.no_color:
4747
result.append(diff_str)
4848
else:
4949
result.append(add_colors_to_diff(diff_str))
5050

5151
elif args.fix:
52-
with open(filename, "w") as f:
52+
with open(filename, 'w') as f:
5353
# TODO: is there a method writelines?
5454
f.write(updated_file_content)
5555
else:
5656
os.remove(filename)
5757

5858
if result:
59-
return "\n".join(result)
60-
return ""
59+
return '\n'.join(result)
60+
return ''
6161

6262
# TODO: update this one: solution is to use read and write operations.
6363
#

deadcode/actions/get_unused_names_error_message.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,25 @@ def get_unused_names_error_message(unused_names: Iterable[CodeItem], args: Args)
1111
return None
1212

1313
if args.quiet:
14-
return ""
14+
return ''
1515

1616
if args.count:
17-
return f"{len(unused_names)}"
17+
return f'{len(unused_names)}'
1818

1919
messages = []
2020
for item in unused_names:
21-
message = f"{item.filename_with_position} \033[91m{item.error_code}\033[0m "
21+
message = f'{item.filename_with_position} \033[91m{item.error_code}\033[0m '
2222
message += item.message or (
2323
f"{item.type_.replace('_', ' ').capitalize()} " f"`\033[1m{item.name}\033[0m` " f"is never used"
2424
)
2525
if args.no_color:
26-
message = message.replace("\033[91m", "").replace("\033[1m", "").replace("\033[0m", "")
26+
message = message.replace('\033[91m', '').replace('\033[1m', '').replace('\033[0m', '')
2727
messages.append(message)
2828

2929
if args.fix:
3030
message = f"\nRemoved \033[1m{len(unused_names)}\033[0m unused code item{'s' if len(unused_names) > 1 else ''}!"
3131
if args.no_color:
32-
message = message.replace("\x1b[1m", "").replace("\x1b[0m", "")
32+
message = message.replace('\x1b[1m', '').replace('\x1b[0m', '')
3333
messages.append(message)
3434

35-
return "\n".join(messages)
35+
return '\n'.join(messages)

deadcode/actions/parse_abstract_syntax_tree.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ def parse_abstract_syntax_tree(file_content: FileContent, args: Args, filename:
99
return ast.parse(file_content, filename=filename, type_comments=True)
1010
except: # noqa: E722
1111
if not args.count and not args.quiet:
12-
print(f"Error: Failed to parse {filename} file, ignoring it.")
12+
print(f'Error: Failed to parse {filename} file, ignoring it.')
1313
return ast.Module()

deadcode/actions/parse_arguments.py

Lines changed: 87 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -26,173 +26,173 @@ def parse_arguments(args: Optional[List[str]]) -> Args:
2626

2727
# Docs: https://docs.python.org/3/library/argparse.html
2828
parser = argparse.ArgumentParser()
29-
parser.add_argument("paths", help="Paths where to search for python files", nargs="+")
29+
parser.add_argument('paths', help='Paths where to search for python files', nargs='+')
3030
parser.add_argument(
31-
"--fix",
32-
help="Automatically remove detected unused code expressions from the code base.",
33-
action="store_true",
31+
'--fix',
32+
help='Automatically remove detected unused code expressions from the code base.',
33+
action='store_true',
3434
default=False,
3535
)
3636
parser.add_argument(
37-
"--dry",
38-
help="Show changes which would be made in files with --fix option.",
39-
nargs="*",
40-
action="append",
41-
default=[["__all_files__"]],
37+
'--dry',
38+
help='Show changes which would be made in files with --fix option.',
39+
nargs='*',
40+
action='append',
41+
default=[['__all_files__']],
4242
type=str,
4343
)
4444
parser.add_argument(
45-
"--exclude",
46-
help="Filenames (or path expressions), which will be completely skipped without being analysed.",
47-
nargs="*",
48-
action="append",
45+
'--exclude',
46+
help='Filenames (or path expressions), which will be completely skipped without being analysed.',
47+
nargs='*',
48+
action='append',
4949
default=[],
5050
type=str,
5151
)
5252
parser.add_argument(
53-
"--ignore-names",
53+
'--ignore-names',
5454
help=(
55-
"Removes provided list of names from the output. "
56-
"Regexp expressions to match multiple names can also be provided."
55+
'Removes provided list of names from the output. '
56+
'Regexp expressions to match multiple names can also be provided.'
5757
),
58-
nargs="*",
59-
action="append",
58+
nargs='*',
59+
action='append',
6060
default=[],
6161
type=str,
6262
)
6363
parser.add_argument(
64-
"--ignore-bodies-of",
65-
help="Ignores body of an expression if its name matches any of the provided names.",
66-
nargs="*",
67-
action="append",
64+
'--ignore-bodies-of',
65+
help='Ignores body of an expression if its name matches any of the provided names.',
66+
nargs='*',
67+
action='append',
6868
default=[],
6969
type=str,
7070
)
7171
parser.add_argument(
72-
"--ignore-bodies-if-decorated-with",
73-
help="Ignores body of an expression if its decorated with one of the provided decorator names.",
74-
nargs="*",
75-
action="append",
72+
'--ignore-bodies-if-decorated-with',
73+
help='Ignores body of an expression if its decorated with one of the provided decorator names.',
74+
nargs='*',
75+
action='append',
7676
default=[],
7777
type=str,
7878
)
7979
parser.add_argument(
80-
"--ignore-bodies-if-inherits-from",
81-
help="Ignores body of a class if it inherits from any of the provided class names.",
82-
nargs="*",
83-
action="append",
80+
'--ignore-bodies-if-inherits-from',
81+
help='Ignores body of a class if it inherits from any of the provided class names.',
82+
nargs='*',
83+
action='append',
8484
default=[],
8585
type=str,
8686
)
8787
parser.add_argument(
88-
"--ignore-definitions",
88+
'--ignore-definitions',
8989
help=(
90-
"Ignores definition (including name and body) if a "
91-
"name of an expression matches any of the provided ones."
90+
'Ignores definition (including name and body) if a '
91+
'name of an expression matches any of the provided ones.'
9292
),
93-
nargs="*",
94-
action="append",
93+
nargs='*',
94+
action='append',
9595
default=[],
9696
type=str,
9797
)
9898
parser.add_argument(
99-
"--ignore-definitions-if-inherits-from",
99+
'--ignore-definitions-if-inherits-from',
100100
help=(
101-
"Ignores definition (including name and body) of a class if "
102-
"it inherits from any of the provided class names."
101+
'Ignores definition (including name and body) of a class if '
102+
'it inherits from any of the provided class names.'
103103
),
104-
nargs="*",
105-
action="append",
104+
nargs='*',
105+
action='append',
106106
default=[],
107107
type=str,
108108
)
109109
parser.add_argument(
110-
"--ignore-definitions-if-decorated-with",
110+
'--ignore-definitions-if-decorated-with',
111111
help=(
112-
"Ignores definition (including name and body) of an expression, "
113-
"which is decorated with any of the provided decorator names."
112+
'Ignores definition (including name and body) of an expression, '
113+
'which is decorated with any of the provided decorator names.'
114114
),
115-
nargs="*",
116-
action="append",
115+
nargs='*',
116+
action='append',
117117
default=[],
118118
type=str,
119119
)
120120

121121
parser.add_argument(
122-
"--ignore-if-decorated-with",
123-
help="Ignores both the name and its definition if its decorated with one of the provided decorator names.",
124-
nargs="*",
125-
action="append",
122+
'--ignore-if-decorated-with',
123+
help='Ignores both the name and its definition if its decorated with one of the provided decorator names.',
124+
nargs='*',
125+
action='append',
126126
default=[],
127127
type=str,
128128
)
129129
parser.add_argument(
130-
"--ignore-if-inherits-from",
131-
help="Ignores both the name and its definition if the class inerits from the provided class name.",
132-
nargs="*",
133-
action="append",
130+
'--ignore-if-inherits-from',
131+
help='Ignores both the name and its definition if the class inerits from the provided class name.',
132+
nargs='*',
133+
action='append',
134134
default=[],
135135
type=str,
136136
)
137137

138138
parser.add_argument(
139-
"--ignore-names-if-inherits-from",
140-
help="Ignores names of classes, which inherit from provided class names.",
141-
nargs="*",
142-
action="append",
139+
'--ignore-names-if-inherits-from',
140+
help='Ignores names of classes, which inherit from provided class names.',
141+
nargs='*',
142+
action='append',
143143
default=[],
144144
type=str,
145145
)
146146
parser.add_argument(
147-
"--ignore-names-if-decorated-with",
148-
help="Ignores names of an expression, which is decorated with one of the provided decorator names.",
149-
nargs="*",
150-
action="append",
147+
'--ignore-names-if-decorated-with',
148+
help='Ignores names of an expression, which is decorated with one of the provided decorator names.',
149+
nargs='*',
150+
action='append',
151151
default=[],
152152
type=str,
153153
)
154154

155155
parser.add_argument(
156-
"--ignore-names-in-files",
157-
help="Ignores unused names in files, which filenames match provided path expressions.",
158-
nargs="*",
159-
action="append",
156+
'--ignore-names-in-files',
157+
help='Ignores unused names in files, which filenames match provided path expressions.',
158+
nargs='*',
159+
action='append',
160160
default=[],
161161
type=str,
162162
)
163163

164164
parser.add_argument(
165-
"--no-color",
166-
help="Turn off colors in the output",
167-
action="store_true",
165+
'--no-color',
166+
help='Turn off colors in the output',
167+
action='store_true',
168168
default=False,
169169
)
170170

171171
parser.add_argument(
172-
"--quiet",
173-
help="Does not output anything. Makefile still fails with exit code 1 if unused names are found.",
174-
action="store_true",
172+
'--quiet',
173+
help='Does not output anything. Makefile still fails with exit code 1 if unused names are found.',
174+
action='store_true',
175175
default=False,
176176
)
177177

178178
parser.add_argument(
179-
"--count",
180-
help="Provides the count of the detected unused names instead of printing them all out.",
181-
action="store_true",
179+
'--count',
180+
help='Provides the count of the detected unused names instead of printing them all out.',
181+
action='store_true',
182182
default=False,
183183
)
184184
parser.add_argument(
185-
"-v",
186-
"--verbose",
187-
help="Shows logs useful for debuging",
188-
action="store_true",
185+
'-v',
186+
'--verbose',
187+
help='Shows logs useful for debuging',
188+
action='store_true',
189189
default=False,
190190
)
191191

192192
parsed_args = parser.parse_args(args).__dict__
193193

194194
for arg_name, arg_value in parsed_args.items():
195-
if isinstance(arg_value, list) and arg_name != "paths":
195+
if isinstance(arg_value, list) and arg_name != 'paths':
196196
parsed_args[arg_name] = flatten_lists_of_comma_separated_values(parsed_args.get(arg_name))
197197

198198
# Extend the Args with the values provided in the pyproject.toml
@@ -201,12 +201,12 @@ def parse_arguments(args: Optional[List[str]]) -> Args:
201201
parsed_args[key].extend(item)
202202

203203
# 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__")
204+
if len(parsed_args['dry']) > 1 or '--dry' not in args:
205+
parsed_args['dry'].remove('__all_files__')
206206

207207
# Do not fix if dry option is provided:
208-
if parsed_args["dry"]:
209-
parsed_args["fix"] = False
208+
if parsed_args['dry']:
209+
parsed_args['fix'] = False
210210

211211
return Args(**parsed_args)
212212

@@ -217,13 +217,13 @@ def parse_pyproject_toml() -> Dict[str, Any]:
217217
If parsing fails, will raise a tomllib.TOMLDecodeError.
218218
Copied from: https://github.com/psf/black/blob/01b8d3d4095ebdb91d0d39012a517931625c63cb/src/black/files.py#LL113C15-L113C15
219219
"""
220-
pyproject_toml_filename = "pyproject.toml"
220+
pyproject_toml_filename = 'pyproject.toml'
221221
if not os.path.isfile(pyproject_toml_filename):
222222
return {}
223223

224-
with open(pyproject_toml_filename, "rb") as f:
224+
with open(pyproject_toml_filename, 'rb') as f:
225225
pyproject_toml = tomllib.load(f)
226226

227-
config: Dict[str, Any] = pyproject_toml.get("tool", {}).get("deadcode", {})
228-
config = {k.replace("--", "").replace("-", "_"): v for k, v in config.items()}
227+
config: Dict[str, Any] = pyproject_toml.get('tool', {}).get('deadcode', {})
228+
config = {k.replace('--', '').replace('-', '_'): v for k, v in config.items()}
229229
return config

0 commit comments

Comments
 (0)