[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
This commit is contained in:
Pierre Sassoulas 2024-05-27 21:18:03 +02:00 committed by GitHub
parent 24abe4eb03
commit 88fae23bdd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 18 additions and 16 deletions

View File

@ -181,13 +181,12 @@ disable = [
"bad-mcs-method-argument", "bad-mcs-method-argument",
"broad-exception-caught", "broad-exception-caught",
"broad-exception-raised", "broad-exception-raised",
"cell-var-from-loop", "cell-var-from-loop", # B023 from ruff / flake8-bugbear
"comparison-of-constants", "comparison-of-constants",
"comparison-with-callable", "comparison-with-callable",
"comparison-with-itself", "comparison-with-itself",
"condition-evals-to-constant", "condition-evals-to-constant",
"consider-using-dict-items", "consider-using-dict-items",
"consider-using-enumerate",
"consider-using-from-import", "consider-using-from-import",
"consider-using-f-string", "consider-using-f-string",
"consider-using-in", "consider-using-in",
@ -195,7 +194,7 @@ disable = [
"consider-using-ternary", "consider-using-ternary",
"consider-using-with", "consider-using-with",
"cyclic-import", "cyclic-import",
"disallowed-name", "disallowed-name", # foo / bar are used often in tests
"duplicate-code", "duplicate-code",
"eval-used", "eval-used",
"exec-used", "exec-used",
@ -229,6 +228,7 @@ disable = [
"pointless-exception-statement", "pointless-exception-statement",
"pointless-statement", "pointless-statement",
"pointless-string-statement", "pointless-string-statement",
"possibly-used-before-assignment",
"protected-access", "protected-access",
"raise-missing-from", "raise-missing-from",
"redefined-argument-from-local", "redefined-argument-from-local",
@ -276,7 +276,6 @@ disable = [
"useless-else-on-loop", "useless-else-on-loop",
"useless-import-alias", "useless-import-alias",
"useless-return", "useless-return",
"use-maxsplit-arg",
"using-constant-test", "using-constant-test",
"wrong-import-order", "wrong-import-order",
] ]

View File

@ -1821,7 +1821,10 @@ def _show_fixtures_per_test(config: Config, session: "Session") -> None:
fixture_doc = inspect.getdoc(fixture_def.func) fixture_doc = inspect.getdoc(fixture_def.func)
if fixture_doc: if fixture_doc:
write_docstring( write_docstring(
tw, fixture_doc.split("\n\n")[0] if verbose <= 0 else fixture_doc tw,
fixture_doc.split("\n\n", maxsplit=1)[0]
if verbose <= 0
else fixture_doc,
) )
else: else:
tw.line(" no docstring available", red=True) tw.line(" no docstring available", red=True)
@ -1903,7 +1906,9 @@ def _showfixtures_main(config: Config, session: "Session") -> None:
tw.write("\n") tw.write("\n")
doc = inspect.getdoc(fixturedef.func) doc = inspect.getdoc(fixturedef.func)
if doc: if doc:
write_docstring(tw, doc.split("\n\n")[0] if verbose <= 0 else doc) write_docstring(
tw, doc.split("\n\n", maxsplit=1)[0] if verbose <= 0 else doc
)
else: else:
tw.line(" no docstring available", red=True) tw.line(" no docstring available", red=True)
tw.line() tw.line()

View File

@ -100,14 +100,13 @@ class TestReportSerialization:
rep_entries = rep.longrepr.reprtraceback.reprentries rep_entries = rep.longrepr.reprtraceback.reprentries
a_entries = a.longrepr.reprtraceback.reprentries a_entries = a.longrepr.reprtraceback.reprentries
for i in range(len(a_entries)): assert len(rep_entries) == len(a_entries) # python < 3.10 zip(strict=True)
rep_entry = rep_entries[i] for a_entry, rep_entry in zip(a_entries, rep_entries):
assert isinstance(rep_entry, ReprEntry) assert isinstance(rep_entry, ReprEntry)
assert rep_entry.reprfileloc is not None assert rep_entry.reprfileloc is not None
assert rep_entry.reprfuncargs is not None assert rep_entry.reprfuncargs is not None
assert rep_entry.reprlocals is not None assert rep_entry.reprlocals is not None
a_entry = a_entries[i]
assert isinstance(a_entry, ReprEntry) assert isinstance(a_entry, ReprEntry)
assert a_entry.reprfileloc is not None assert a_entry.reprfileloc is not None
assert a_entry.reprfuncargs is not None assert a_entry.reprfuncargs is not None
@ -146,9 +145,10 @@ class TestReportSerialization:
rep_entries = rep.longrepr.reprtraceback.reprentries rep_entries = rep.longrepr.reprtraceback.reprentries
a_entries = a.longrepr.reprtraceback.reprentries a_entries = a.longrepr.reprtraceback.reprentries
for i in range(len(a_entries)): assert len(rep_entries) == len(a_entries) # python < 3.10 zip(strict=True)
assert isinstance(rep_entries[i], ReprEntryNative) for rep_entry, a_entry in zip(rep_entries, a_entries):
assert rep_entries[i].lines == a_entries[i].lines assert isinstance(rep_entry, ReprEntryNative)
assert rep_entry.lines == a_entry.lines
def test_itemreport_outcomes(self, pytester: Pytester) -> None: def test_itemreport_outcomes(self, pytester: Pytester) -> None:
# This test came originally from test_remote.py in xdist (ca03269). # This test came originally from test_remote.py in xdist (ca03269).

View File

@ -280,10 +280,8 @@ def test_warning_recorded_hook(pytester: Pytester) -> None:
("call warning", "runtest", "test_warning_recorded_hook.py::test_func"), ("call warning", "runtest", "test_warning_recorded_hook.py::test_func"),
("teardown warning", "runtest", "test_warning_recorded_hook.py::test_func"), ("teardown warning", "runtest", "test_warning_recorded_hook.py::test_func"),
] ]
for index in range(len(expected)): assert len(collected) == len(expected) # python < 3.10 zip(strict=True)
collected_result = collected[index] for collected_result, expected_result in zip(collected, expected):
expected_result = expected[index]
assert collected_result[0] == expected_result[0], str(collected) assert collected_result[0] == expected_result[0], str(collected)
assert collected_result[1] == expected_result[1], str(collected) assert collected_result[1] == expected_result[1], str(collected)
assert collected_result[2] == expected_result[2], str(collected) assert collected_result[2] == expected_result[2], str(collected)