Skip to content

Commit 88fae23

Browse files
[pylint] Fixes all use-maxplit-args, consider-using-enumerate (#12172)
* [pylint 'use-maxsplit-arg'] Do not split more than necessary when using the first element * [pylint 'consider-using-enumerate'] Use zip when iterating on two iterators * [pylint] 'cell-var-from-loop' and 'disallowed-name' permanent disable * [pylint] Disable 'possibly-used-before-assignment' following 3.2.0 release
1 parent 24abe4e commit 88fae23

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

pyproject.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,21 +181,20 @@ disable = [
181181
"bad-mcs-method-argument",
182182
"broad-exception-caught",
183183
"broad-exception-raised",
184-
"cell-var-from-loop",
184+
"cell-var-from-loop", # B023 from ruff / flake8-bugbear
185185
"comparison-of-constants",
186186
"comparison-with-callable",
187187
"comparison-with-itself",
188188
"condition-evals-to-constant",
189189
"consider-using-dict-items",
190-
"consider-using-enumerate",
191190
"consider-using-from-import",
192191
"consider-using-f-string",
193192
"consider-using-in",
194193
"consider-using-sys-exit",
195194
"consider-using-ternary",
196195
"consider-using-with",
197196
"cyclic-import",
198-
"disallowed-name",
197+
"disallowed-name", # foo / bar are used often in tests
199198
"duplicate-code",
200199
"eval-used",
201200
"exec-used",
@@ -229,6 +228,7 @@ disable = [
229228
"pointless-exception-statement",
230229
"pointless-statement",
231230
"pointless-string-statement",
231+
"possibly-used-before-assignment",
232232
"protected-access",
233233
"raise-missing-from",
234234
"redefined-argument-from-local",
@@ -276,7 +276,6 @@ disable = [
276276
"useless-else-on-loop",
277277
"useless-import-alias",
278278
"useless-return",
279-
"use-maxsplit-arg",
280279
"using-constant-test",
281280
"wrong-import-order",
282281
]

src/_pytest/fixtures.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,7 +1821,10 @@ def write_fixture(fixture_def: FixtureDef[object]) -> None:
18211821
fixture_doc = inspect.getdoc(fixture_def.func)
18221822
if fixture_doc:
18231823
write_docstring(
1824-
tw, fixture_doc.split("\n\n")[0] if verbose <= 0 else fixture_doc
1824+
tw,
1825+
fixture_doc.split("\n\n", maxsplit=1)[0]
1826+
if verbose <= 0
1827+
else fixture_doc,
18251828
)
18261829
else:
18271830
tw.line(" no docstring available", red=True)
@@ -1903,7 +1906,9 @@ def _showfixtures_main(config: Config, session: "Session") -> None:
19031906
tw.write("\n")
19041907
doc = inspect.getdoc(fixturedef.func)
19051908
if doc:
1906-
write_docstring(tw, doc.split("\n\n")[0] if verbose <= 0 else doc)
1909+
write_docstring(
1910+
tw, doc.split("\n\n", maxsplit=1)[0] if verbose <= 0 else doc
1911+
)
19071912
else:
19081913
tw.line(" no docstring available", red=True)
19091914
tw.line()

testing/test_reports.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,13 @@ def test_repr_entry():
100100

101101
rep_entries = rep.longrepr.reprtraceback.reprentries
102102
a_entries = a.longrepr.reprtraceback.reprentries
103-
for i in range(len(a_entries)):
104-
rep_entry = rep_entries[i]
103+
assert len(rep_entries) == len(a_entries) # python < 3.10 zip(strict=True)
104+
for a_entry, rep_entry in zip(a_entries, rep_entries):
105105
assert isinstance(rep_entry, ReprEntry)
106106
assert rep_entry.reprfileloc is not None
107107
assert rep_entry.reprfuncargs is not None
108108
assert rep_entry.reprlocals is not None
109109

110-
a_entry = a_entries[i]
111110
assert isinstance(a_entry, ReprEntry)
112111
assert a_entry.reprfileloc is not None
113112
assert a_entry.reprfuncargs is not None
@@ -146,9 +145,10 @@ def test_repr_entry_native():
146145

147146
rep_entries = rep.longrepr.reprtraceback.reprentries
148147
a_entries = a.longrepr.reprtraceback.reprentries
149-
for i in range(len(a_entries)):
150-
assert isinstance(rep_entries[i], ReprEntryNative)
151-
assert rep_entries[i].lines == a_entries[i].lines
148+
assert len(rep_entries) == len(a_entries) # python < 3.10 zip(strict=True)
149+
for rep_entry, a_entry in zip(rep_entries, a_entries):
150+
assert isinstance(rep_entry, ReprEntryNative)
151+
assert rep_entry.lines == a_entry.lines
152152

153153
def test_itemreport_outcomes(self, pytester: Pytester) -> None:
154154
# This test came originally from test_remote.py in xdist (ca03269).

testing/test_warnings.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,8 @@ def pytest_warning_recorded(self, warning_message, when, nodeid, location):
280280
("call warning", "runtest", "test_warning_recorded_hook.py::test_func"),
281281
("teardown warning", "runtest", "test_warning_recorded_hook.py::test_func"),
282282
]
283-
for index in range(len(expected)):
284-
collected_result = collected[index]
285-
expected_result = expected[index]
286-
283+
assert len(collected) == len(expected) # python < 3.10 zip(strict=True)
284+
for collected_result, expected_result in zip(collected, expected):
287285
assert collected_result[0] == expected_result[0], str(collected)
288286
assert collected_result[1] == expected_result[1], str(collected)
289287
assert collected_result[2] == expected_result[2], str(collected)

0 commit comments

Comments
 (0)