Skip to content

Commit 74f3c0f

Browse files
committed
Add rufft o linting job
1 parent 31d0c6b commit 74f3c0f

4 files changed

Lines changed: 46 additions & 46 deletions

File tree

.github/workflows/test.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ jobs:
115115
globs: |
116116
**/README.md
117117
118-
- name: Lint Dockerfile
119-
uses: hadolint/hadolint-action@54c9adbab1582c2ef04b2016b760714a4bfde3cf # v3.1.0
118+
- uses: astral-sh/ruff-action@9828f49eb4cadf267b40eaa330295c412c68c1f9 # v3
120119
with:
121-
dockerfile: ./docker/Dockerfile-*
120+
args: --config=.config/ruff.toml check

src/python_minifier/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ def minify(
8686
:param str source: The python module source code
8787
:param str filename: The original source filename if known
8888
89-
:param remove_annotations: Configures the removal of type annotations. True removes all annotations, False removes none. RemoveAnnotationsOptions can be used to configure the removal of specific annotations.
89+
:param remove_annotations: Configures the removal of type annotations. True removes all annotations, False removes none.
90+
RemoveAnnotationsOptions can be used to configure the removal of specific annotations.
9091
:type remove_annotations: bool or RemoveAnnotationsOptions
9192
:param bool remove_pass: If Pass statements should be removed where possible
9293
:param bool remove_literal_statements: If statements consisting of a single literal should be removed, including docstrings

src/python_minifier/ast_compare.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,26 +77,26 @@ def counter():
7777
% (type(l_ast), field, len(l_list), type(r_ast), field, len(r_list)),
7878
)
7979

80-
for i, l, r in zip(counter(), l_list, r_list):
81-
if isinstance(l, ast.AST) or isinstance(r, ast.AST):
82-
compare_ast(l, r)
83-
elif l != r:
80+
for i, left, right in zip(counter(), l_list, r_list):
81+
if isinstance(left, ast.AST) or isinstance(right, ast.AST):
82+
compare_ast(left, right)
83+
elif left != right:
8484
raise CompareError(
8585
l_ast,
8686
r_ast,
8787
'Fields do not match! %s.%s[%i]=%r, %s.%s[%i]=%r'
88-
% (type(l_ast), field, i, l, type(r_ast), field, i, r),
88+
% (type(l_ast), field, i, left, type(r_ast), field, i, right),
8989
)
9090

9191
else:
92-
l = getattr(l_ast, field, None)
93-
r = getattr(r_ast, field, None)
92+
left_field = getattr(l_ast, field, None)
93+
right_field = getattr(r_ast, field, None)
9494

95-
if isinstance(l, ast.AST) or isinstance(r, ast.AST):
96-
compare_ast(l, r)
97-
elif l != r:
95+
if isinstance(left_field, ast.AST) or isinstance(right_field, ast.AST):
96+
compare_ast(left_field, right_field)
97+
elif left_field != right_field:
9898
raise CompareError(
9999
l_ast,
100100
r_ast,
101-
'Fields do not match! %s.%s=%r, %s.%s=%r' % (type(l_ast), field, l, type(r_ast), field, r),
101+
'Fields do not match! %s.%s=%r, %s.%s=%r' % (type(l_ast), field, left_field, type(r_ast), field, right_field),
102102
)

src/python_minifier/f_string.py

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -272,31 +272,31 @@ def _get_quote(self, c):
272272
raise ValueError("Couldn't find a quote")
273273

274274
def _literals(self):
275-
l = ''
275+
literal = ''
276276
for c in self._s:
277277
if not self._can_quote(c):
278-
if l:
279-
l += self.current_quote
280-
yield l
281-
l = ''
278+
if literal:
279+
literal += self.current_quote
280+
yield literal
281+
literal = ''
282282

283283
self.current_quote = self._get_quote(c)
284284

285-
if l == '':
286-
l += self.current_quote
285+
if literal == '':
286+
literal += self.current_quote
287287

288288
if c == '\n':
289-
l += '\\n'
289+
literal += '\\n'
290290
elif c == '\r':
291-
l += '\\r'
291+
literal += '\\r'
292292
elif c == '\\':
293-
l += '\\\\'
293+
literal += '\\\\'
294294
else:
295-
l += c
295+
literal += c
296296

297-
if l:
298-
l += self.current_quote
299-
yield l
297+
if literal:
298+
literal += self.current_quote
299+
yield literal
300300

301301
def __str__(self):
302302
if self._s == '':
@@ -315,10 +315,10 @@ def __str__(self):
315315
for start_quote in self.allowed_quotes:
316316
self.current_quote = start_quote
317317
s = ''
318-
for l in self._literals():
319-
if s and s[-1] == l[0]:
318+
for literal in self._literals():
319+
if s and s[-1] == literal[0]:
320320
s += ' '
321-
s += l
321+
s += literal
322322

323323
if eval(s) == self._s:
324324
candidates.append(s)
@@ -399,23 +399,23 @@ def _get_quote(self, c):
399399
raise ValueError("Couldn't find a quote")
400400

401401
def _literals(self):
402-
l = ''
402+
literal = ''
403403
for b in self._b:
404404
if not self._can_quote(b):
405-
if l:
406-
l += self.current_quote
407-
yield l
408-
l = ''
405+
if literal:
406+
literal += self.current_quote
407+
yield literal
408+
literal = ''
409409

410410
self.current_quote = self._get_quote(b)
411411

412-
if l == '':
413-
l = 'b' + self.current_quote
414-
l += chr(b)
412+
if literal == '':
413+
literal = 'b' + self.current_quote
414+
literal += chr(b)
415415

416-
if l:
417-
l += self.current_quote
418-
yield l
416+
if literal:
417+
literal += self.current_quote
418+
yield literal
419419

420420
def __str__(self):
421421
if self._b == b'':
@@ -434,10 +434,10 @@ def __str__(self):
434434
for start_quote in self.allowed_quotes:
435435
self.current_quote = start_quote
436436
s = ''
437-
for l in self._literals():
438-
if s and s[-1] == l[0]:
437+
for literal in self._literals():
438+
if s and s[-1] == literal[0]:
439439
s += ' '
440-
s += l
440+
s += literal
441441

442442
assert eval(s) == self._b
443443
candidates.append(s)

0 commit comments

Comments
 (0)