Skip to content

Commit 9c9266e

Browse files
committed
Resolve lint warnings
1 parent dec545d commit 9c9266e

19 files changed

+81
-82
lines changed

src/python_minifier/__main__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from python_minifier import minify
88
from python_minifier.transforms.remove_annotations_options import RemoveAnnotationsOptions
99

10+
1011
if sys.version_info >= (3, 8):
1112
from importlib import metadata
1213

@@ -270,9 +271,9 @@ def error(os_error):
270271

271272
for path_arg in args.path:
272273
if os.path.isdir(path_arg):
273-
for root, dirs, files in os.walk(path_arg, onerror=error, followlinks=True):
274+
for root, _dirs, files in os.walk(path_arg, onerror=error, followlinks=True):
274275
for file in files:
275-
if file.endswith('.py') or file.endswith('.pyw'):
276+
if file.endswith(('.py', '.pyw')):
276277
yield os.path.join(root, file)
277278
else:
278279
yield path_arg

src/python_minifier/ast_compat.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from ast import *
1010

11+
1112
# Ideally we don't import anything else
1213

1314
if 'TypeAlias' in globals():

src/python_minifier/ast_printer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from python_minifier.util import is_ast_node
1616

17+
1718
INDENT = ' '
1819

1920
# The field name that can be omitted for each node

src/python_minifier/expression_printer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,8 @@ def visit_arguments(self, node):
629629
def visit_arg(self, node):
630630
if isinstance(node, ast.Name):
631631
# Python 2 uses Name nodes
632-
return self.visit_Name(node)
632+
self.visit_Name(node)
633+
return
633634

634635
self.printer.identifier(node.arg)
635636

src/python_minifier/f_string.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def is_correct_ast(self, code):
3636
c = ast.parse(code, 'FString candidate', mode='eval')
3737
compare_ast(self.node, c.body)
3838
return True
39-
except Exception as e:
39+
except Exception:
4040
return False
4141

4242
def complete_debug_specifier(self, partial_specifier_candidates, value_node):
@@ -79,12 +79,12 @@ def candidates(self):
7979
# Maybe!
8080
try:
8181
debug_specifier_candidates = [x + '{' + v.s for x in candidates]
82-
except Exception as e:
82+
except Exception:
8383
continue
8484

8585
try:
8686
candidates = [x + self.str_for(v.s, quote) for x in candidates]
87-
except Exception as e:
87+
except Exception:
8888
continue
8989
elif isinstance(v, ast.FormattedValue):
9090
try:
@@ -93,15 +93,14 @@ def candidates(self):
9393
x + y for x in candidates for y in FormattedValue(v, nested_allowed, self.pep701).get_candidates()
9494
] + completed
9595
debug_specifier_candidates = []
96-
except Exception as e:
96+
except Exception:
9797
continue
9898
else:
9999
raise RuntimeError('Unexpected JoinedStr value')
100100

101101
actual_candidates += ['f' + quote + x + quote for x in candidates]
102102

103-
actual_candidates = filter(self.is_correct_ast, actual_candidates)
104-
return actual_candidates
103+
return filter(self.is_correct_ast, actual_candidates)
105104

106105
def str_for(self, s, quote):
107106
return s.replace('{', '{{').replace('}', '}}')

src/python_minifier/ministring.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def __str__(self):
3232

3333
try:
3434
eval(self.quote + s + self.quote)
35-
except (UnicodeDecodeError, UnicodeEncodeError) as e:
35+
except (UnicodeDecodeError, UnicodeEncodeError):
3636
if self.safe_mode:
3737
raise
3838

@@ -63,7 +63,7 @@ def to_short(self):
6363
}
6464

6565
for c in self._s:
66-
if c in escaped.keys():
66+
if c in escaped:
6767
s += escaped[c]
6868
else:
6969
if self.safe_mode:
@@ -95,7 +95,7 @@ def to_long(self):
9595
}
9696

9797
for c in self._s:
98-
if c in escaped.keys():
98+
if c in escaped:
9999
s += escaped[c]
100100
else:
101101
if self.safe_mode:

src/python_minifier/module_printer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def visit_ImportFrom(self, node):
244244
assert isinstance(node, ast.ImportFrom)
245245

246246
self.printer.keyword('from')
247-
for i in range(node.level):
247+
for _i in range(node.level):
248248
self.printer.delimiter('.')
249249
if node.module is not None:
250250
self.printer.identifier(node.module)

src/python_minifier/rename/binding.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def should_rename(self, new_name):
273273
274274
"""
275275

276-
raise NotImplementedError()
276+
raise NotImplementedError
277277

278278
def rename(self, new_name):
279279
"""
@@ -283,7 +283,7 @@ def rename(self, new_name):
283283
284284
"""
285285

286-
raise NotImplementedError()
286+
raise NotImplementedError
287287

288288

289289
class NameBinding(Binding):

src/python_minifier/rename/mapper.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,11 @@ def add_parent(node, parent=None, namespace=None):
161161
if is_ast_node(node, 'Nonlocal'):
162162
namespace.nonlocal_names.update(node.names)
163163

164-
if isinstance(node, ast.Name):
165-
if isinstance(namespace, ast.ClassDef):
166-
if isinstance(node.ctx, ast.Load):
167-
namespace.nonlocal_names.add(node.id)
168-
elif isinstance(node.ctx, ast.Store) and isinstance(node.parent, ast.AugAssign):
169-
namespace.nonlocal_names.add(node.id)
164+
if isinstance(node, ast.Name) and isinstance(namespace, ast.ClassDef):
165+
if isinstance(node.ctx, ast.Load):
166+
namespace.nonlocal_names.add(node.id)
167+
elif isinstance(node.ctx, ast.Store) and isinstance(node.parent, ast.AugAssign):
168+
namespace.nonlocal_names.add(node.id)
170169

171170
for child in ast.iter_child_nodes(node):
172171
add_parent(child, parent=node, namespace=namespace)

src/python_minifier/rename/rename_literals.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,18 +155,18 @@ def namespace_path(self, node):
155155
156156
"""
157157

158-
l = []
158+
path = []
159159

160160
while True:
161161
namespace = self.nearest_function_namespace(node)
162-
l.insert(0, namespace)
162+
path.insert(0, namespace)
163163

164164
if isinstance(namespace, ast.Module):
165165
break
166166

167167
node = namespace
168168

169-
return l
169+
return path
170170

171171
def common_path(self, n1_path, n2_path):
172172

@@ -217,8 +217,7 @@ def visit_JoinedStr(self, node):
217217
if is_ast_node(v, ast.Str):
218218
# Can't hoist this!
219219
continue
220-
else:
221-
self.visit(v)
220+
self.visit(v)
222221

223222
def visit_NameConstant(self, node):
224223
self.get_binding(node.value, node).add_reference(node)
@@ -242,7 +241,7 @@ def visit_Assign(self, node):
242241
for target in node.targets:
243242
if is_ast_node(target, ast.Name) and target.id == '__slots__':
244243
# This is a __slots__ assignment, don't hoist the literals
245-
return
244+
return None
246245

247246
return self.generic_visit(node)
248247

0 commit comments

Comments
 (0)