Skip to content

Commit 334e74c

Browse files
committedNov 23, 2024
bump ruff to 0.8.0, refactor ruff opts and code
1 parent 823d923 commit 334e74c

21 files changed

+40
-86
lines changed
 

‎nested_diff/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class Differ:
9898

9999
default_differ = DEFAULT_HANDLER.diff
100100

101-
def __init__(
101+
def __init__( # noqa: PLR0913
102102
self,
103103
A=True, # noqa: N803
104104
N=True, # noqa: N803

‎nested_diff/cli.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -552,17 +552,15 @@ def __init__(self, **kwargs):
552552

553553
import yaml
554554

555-
from yaml.nodes import (
556-
ScalarNode as YamlScalarNode,
557-
SequenceNode as YamlSequenceNode,
558-
MappingNode as YamlMappingNode,
559-
)
560-
561555
try:
562556
from yaml import CSafeLoader as YamlLoader
563557
except ImportError:
564558
from yaml import SafeLoader as YamlLoader
565559

560+
from yaml.nodes import MappingNode as YamlMappingNode
561+
from yaml.nodes import ScalarNode as YamlScalarNode
562+
from yaml.nodes import SequenceNode as YamlSequenceNode
563+
566564
self.opts = self.get_opts(kwargs)
567565
self.yaml = yaml
568566
self.yaml_loader = YamlLoader

‎nested_diff/diff_tool.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,17 @@ def diff(self, a, b, **kwargs):
6666

6767
return differ.diff(a, b)
6868

69-
def generate_diffs(self):
69+
def generate_diffs(self): # noqa: C901
7070
"""Generate diffs."""
7171
a = None
7272
headers_enabled = False
7373

7474
if self.args.show:
7575
if len(self.args.files) > 1:
7676
headers_enabled = True
77-
elif len(self.args.files) < 2:
77+
elif len(self.args.files) < 2: # noqa: PLR2004
7878
self.argparser.error('Two or more arguments expected for diff')
79-
elif len(self.args.files) > 2:
79+
elif len(self.args.files) > 2: # noqa: PLR2004
8080
headers_enabled = True
8181

8282
for file_ in self.args.files:
@@ -254,7 +254,7 @@ class FormatterDumper(nested_diff.cli.Dumper):
254254

255255
supported_fmts = ('term', 'text', 'html')
256256

257-
def __init__(
257+
def __init__( # noqa: PLR0913
258258
self,
259259
fmt,
260260
header=None,

‎nested_diff/formatters.py

+1-12
Original file line numberDiff line numberDiff line change
@@ -356,18 +356,7 @@ def get_script(self):
356356
}
357357
})
358358
"""
359-
lines = []
360-
for line in script.split('\n'):
361-
try:
362-
comment_starts = line.index('//')
363-
except ValueError:
364-
pass
365-
else:
366-
line = line[:comment_starts]
367-
368-
lines.append(line.strip())
369-
370-
return ''.join(lines)
359+
return ''.join(x.split('//', 1)[0].strip() for x in script.split('\n'))
371360

372361
def format_key(self, key):
373362
"""Return key/index representation."""

‎nested_diff/handlers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def __init__(self):
320320
super().__init__()
321321
self.lcs = SequenceMatcher(isjunk=None, autojunk=False)
322322

323-
def diff(self, differ, a, b):
323+
def diff(self, differ, a, b): # noqa: C901 PLR0912
324324
"""Calculate diff for two list objects.
325325
326326
Args:
@@ -598,7 +598,7 @@ def patch(self, patcher, target, diff): # noqa: ARG002
598598
for subdiff in diff['D']:
599599
try:
600600
target.add(subdiff['A'])
601-
except KeyError:
601+
except KeyError: # noqa: PERF203
602602
try:
603603
target.remove(subdiff['R'])
604604
except KeyError:

‎pyproject.toml

+11-36
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ test = [
5656
'pytest',
5757
'pytest-cov',
5858
'pytest-ruff',
59-
'ruff==0.6.3',
59+
'ruff==0.8.0',
6060
]
6161

6262
[project.scripts]
@@ -92,48 +92,23 @@ docstring-code-format = true
9292
quote-style = 'single'
9393

9494
[tool.ruff.lint]
95-
select = [
96-
'A',
97-
'ARG',
98-
'B',
99-
'BLE',
100-
'C4',
101-
'COM',
102-
'D',
103-
'DTZ',
104-
'E',
105-
'ERA',
106-
'EXE',
107-
# 'FBT', # TODO
108-
'FLY',
109-
'G',
110-
'ICN',
111-
'ISC',
112-
'LOG',
113-
'N',
114-
'PGH',
115-
'PIE',
116-
'PT',
117-
# 'PL', # TODO
118-
'PLE',
119-
'Q',
120-
'RET',
121-
'RSE',
122-
'RUF',
123-
'SIM',
124-
'SLF',
125-
'TD',
126-
'UP',
127-
'W',
128-
]
95+
select = ['ALL'] # IMPORTANT: keep ruff version pinned!
12996
ignore = [
130-
'D407', # Missing dashed underline after section
97+
'ANN', # TODO: enable
98+
'EM101', # Exception must not use a string literal, assign to variable...
99+
'EM102', # Exception must not use an f-string literal
100+
'FBT002', # TODO: enable
101+
'PTH', # ... should be replaced by `Path...
131102
'SIM105', # contextlib.suppress is slower than try-except-pass
103+
'TRY003', # Avoid specifying long messages outside the exception class
132104
]
133105

134106
[tool.ruff.lint.extend-per-file-ignores]
135107
'tests/*' = [
136108
'D', # docstrings
109+
'PLR2004', # Magic value used in comparison...
110+
'S101', # Use of `assert`
111+
'T201', # `print` found
137112
]
138113

139114
[tool.ruff.lint.flake8-quotes]

‎tests/cli/__init__.py

Whitespace-only changes.

‎tests/cli/test_cli.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import pytest
21
import sys
32

3+
import pytest
4+
45
from nested_diff import cli
56

67

‎tests/cli/test_diff_tool.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import builtins
22
import json
3-
import pytest
43
import sys
5-
64
from unittest import mock
75

6+
import pytest
7+
88
import nested_diff.diff_tool
99

1010

‎tests/cli/test_patch_tool.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import io
22
import json
3-
import pytest
4-
5-
from unittest import mock
63
from shutil import copyfile
4+
from unittest import mock
5+
6+
import pytest
77

88
import nested_diff.patch_tool
99

‎tests/common.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
23
import pytest
34

45

‎tests/conftest.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import os
2-
import pytest
3-
42
from io import StringIO
53

4+
import pytest
65

76
pytest.register_assert_rewrite('tests.common')
87

‎tests/data/__init__.py

Whitespace-only changes.

‎tests/data/gen_html_compare.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
import html
44

5-
from nested_diff.formatters import HtmlFormatter, TextFormatter
6-
75
import tests.data.formatters
6+
from nested_diff.formatters import HtmlFormatter, TextFormatter
87

98

109
def main():

‎tests/data/specific.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import sys
2-
32
from pickle import dumps
43

54
from nested_diff.handlers import FloatHandler, TextHandler

‎tests/test_diff.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import pytest
21
import sys
32

4-
from nested_diff import Differ, diff, handlers
3+
import pytest
54

5+
from nested_diff import Differ, diff, handlers
66
from tests.data import specific, standard
77

88
TESTS = {}

‎tests/test_fmt_html.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import pytest
22

3-
from nested_diff.formatters import HtmlFormatter
4-
53
import tests.data.formatters
64
import tests.data.formatters.HtmlFormatter
7-
5+
from nested_diff.formatters import HtmlFormatter
86
from tests.common import do_test_function, iterate_test_suite
97

108

‎tests/test_fmt_term.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import pytest
22

3-
from nested_diff.formatters import TermFormatter
4-
53
import tests.data.formatters
64
import tests.data.formatters.TermFormatter
7-
5+
from nested_diff.formatters import TermFormatter
86
from tests.common import do_test_function, iterate_test_suite
97

108

‎tests/test_fmt_text.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import pytest
22

3-
from nested_diff.formatters import TextFormatter
4-
53
import tests.data.formatters
64
import tests.data.formatters.TextFormatter
7-
5+
from nested_diff.formatters import TextFormatter
86
from tests.common import do_test_function, iterate_test_suite
97

108

‎tests/test_iterator.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22

3-
from nested_diff import Iterator, Differ
3+
from nested_diff import Differ, Iterator
44

55

66
def test_scalar_diff():
@@ -118,7 +118,7 @@ def test_set_diff():
118118

119119

120120
def test_unknown_containers():
121-
class UnknownContainer(tuple):
121+
class UnknownContainer(tuple): # noqa: SLOT001
122122
pass
123123

124124
d = {'D': UnknownContainer([{'O': 0, 'N': 1}])}

‎tests/test_patch.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import pytest
22

33
from nested_diff import Differ, Patcher, patch
4-
54
from tests.data import specific, standard
65

76
TESTS = {}

0 commit comments

Comments
 (0)
Failed to load comments.