Skip to content

Commit 400b22d

Browse files
Merge pull request #12622 from Pierre-Sassoulas/more-pylint-fixes
[pylint/ruff] Activate PLR / PLC messages in ruff
2 parents 6d66d16 + 6f0faec commit 400b22d

File tree

3 files changed

+32
-15
lines changed

3 files changed

+32
-15
lines changed

Diff for: pyproject.toml

+30-12
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ lint.select = [
102102
"I", # isort
103103
"PGH004", # pygrep-hooks - Use specific rule codes when using noqa
104104
"PIE", # flake8-pie
105+
"PLC", # pylint convention
105106
"PLE", # pylint error
107+
"PLR", # pylint refactor
106108
"PLR1714", # Consider merging multiple comparisons
107109
"PLW", # pylint warning
108110
"PYI", # flake8-pyi
@@ -139,6 +141,17 @@ lint.ignore = [
139141
# what we're doing when we use type(..) is ...
140142
"E721", # Do not compare types, use `isinstance()`
141143
# pylint ignore
144+
"PLC0105", # `TypeVar` name "E" does not reflect its covariance;
145+
"PLC0414", # Import alias does not rename original package
146+
"PLR0124", # Name compared with itself
147+
"PLR0133", # Two constants compared in a comparison (lots of those in tests)
148+
"PLR0402", # Use `from x.y import z` in lieu of alias
149+
"PLR0911", # Too many return statements
150+
"PLR0912", # Too many branches
151+
"PLR0913", # Too many arguments in function definition
152+
"PLR0915", # Too many statements
153+
"PLR2004", # Magic value used in comparison
154+
"PLR2044", # Line with empty comment
142155
"PLR5501", # Use `elif` instead of `else` then `if`
143156
"PLW0120", # remove the else and dedent its contents
144157
"PLW0603", # Using the global statement
@@ -191,24 +204,27 @@ disable = [
191204
"broad-exception-caught",
192205
"broad-exception-raised",
193206
"cell-var-from-loop", # B023 from ruff / flake8-bugbear
194-
"comparison-of-constants",
207+
"comparison-of-constants", # disabled in ruff (PLR0133)
195208
"comparison-with-callable",
196-
"comparison-with-itself",
209+
"comparison-with-itself", # PLR0124 from ruff
197210
"condition-evals-to-constant",
198211
"consider-using-dict-items",
199212
"consider-using-from-import",
200213
"consider-using-f-string",
201214
"consider-using-in",
202215
"consider-using-ternary",
203216
"consider-using-with",
217+
"consider-using-from-import", # not activated by default, PLR0402 disabled in ruff
204218
"cyclic-import",
205219
"disallowed-name", # foo / bar are used often in tests
206220
"duplicate-code",
221+
"else-if-used", # not activated by default, PLR5501 disabled in ruff
222+
"empty-comment", # not activated by default, PLR2044 disabled in ruff
207223
"eval-used",
208224
"exec-used",
209225
"expression-not-assigned",
210226
"fixme",
211-
"global-statement",
227+
"global-statement", # PLW0603 disabled in ruff
212228
"import-error",
213229
"import-outside-toplevel",
214230
"inconsistent-return-statements",
@@ -218,6 +234,7 @@ disable = [
218234
"invalid-str-returned",
219235
"keyword-arg-before-vararg",
220236
"line-too-long",
237+
"magic-value-comparison", # not activated by default, PLR2004 disabled in ruff
221238
"method-hidden",
222239
"missing-docstring",
223240
"missing-timeout",
@@ -232,14 +249,15 @@ disable = [
232249
"no-self-argument",
233250
"not-an-iterable",
234251
"not-callable",
235-
"pointless-exception-statement",
236-
"pointless-statement",
237-
"pointless-string-statement",
252+
"pointless-exception-statement", # https://github.com/pytest-dev/pytest/pull/12379
253+
"pointless-statement", # https://github.com/pytest-dev/pytest/pull/12379
254+
"pointless-string-statement", # https://github.com/pytest-dev/pytest/pull/12379
238255
"possibly-used-before-assignment",
239256
"protected-access",
240257
"raise-missing-from",
241258
"redefined-argument-from-local",
242259
"redefined-builtin",
260+
"redefined-loop-name", # PLW2901 disabled in ruff
243261
"redefined-outer-name",
244262
"reimported",
245263
"simplifiable-condition",
@@ -249,18 +267,18 @@ disable = [
249267
"super-init-not-called",
250268
"too-few-public-methods",
251269
"too-many-ancestors",
252-
"too-many-arguments",
253-
"too-many-branches",
270+
"too-many-arguments", # disabled in ruff
271+
"too-many-branches", # disabled in ruff
254272
"too-many-function-args",
255273
"too-many-instance-attributes",
256274
"too-many-lines",
257275
"too-many-locals",
258276
"too-many-nested-blocks",
259277
"too-many-public-methods",
260-
"too-many-return-statements",
261-
"too-many-statements",
278+
"too-many-return-statements", # disabled in ruff
279+
"too-many-statements", # disabled in ruff
262280
"try-except-raise",
263-
"typevar-name-incorrect-variance",
281+
"typevar-name-incorrect-variance", # PLC0105 disabled in ruff
264282
"unbalanced-tuple-unpacking",
265283
"undefined-loop-variable",
266284
"undefined-variable",
@@ -280,7 +298,7 @@ disable = [
280298
"use-dict-literal",
281299
"use-implicit-booleaness-not-comparison",
282300
"use-implicit-booleaness-not-len",
283-
"useless-else-on-loop",
301+
"useless-else-on-loop", # PLC0414 disabled in ruff
284302
"useless-import-alias",
285303
"useless-return",
286304
"using-constant-test",

Diff for: src/_pytest/_io/saferepr.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ def _format_repr_exception(exc: BaseException, obj: object) -> str:
1818
exc_info = _try_repr_or_str(exc)
1919
except (KeyboardInterrupt, SystemExit):
2020
raise
21-
except BaseException as exc:
22-
exc_info = f"unpresentable exception ({_try_repr_or_str(exc)})"
21+
except BaseException as inner_exc:
22+
exc_info = f"unpresentable exception ({_try_repr_or_str(inner_exc)})"
2323
return (
2424
f"<[{exc_info} raised in repr()] {type(obj).__name__} object at 0x{id(obj):x}>"
2525
)

Diff for: src/_pytest/helpconfig.py

-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ def showhelp(config: Config) -> None:
238238

239239
for warningreport in reporter.stats.get("warnings", []):
240240
tw.line("warning : " + warningreport.message, red=True)
241-
return
242241

243242

244243
conftest_options = [("pytest_plugins", "list of plugin names to load")]

0 commit comments

Comments
 (0)