Skip to content

Commit 4029a25

Browse files
AlexWaygoodMichaReiser
authored andcommitted
[Ruff v0.5] Stabilise 15 pylint rules (#12051)
1 parent 0917ce1 commit 4029a25

14 files changed

+95
-84
lines changed

crates/ruff_linter/src/codes.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,14 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
191191
(Pylint, "C0414") => (RuleGroup::Stable, rules::pylint::rules::UselessImportAlias),
192192
(Pylint, "C0415") => (RuleGroup::Preview, rules::pylint::rules::ImportOutsideTopLevel),
193193
(Pylint, "C1901") => (RuleGroup::Preview, rules::pylint::rules::CompareToEmptyString),
194-
(Pylint, "C2401") => (RuleGroup::Preview, rules::pylint::rules::NonAsciiName),
195-
(Pylint, "C2403") => (RuleGroup::Preview, rules::pylint::rules::NonAsciiImportName),
194+
(Pylint, "C2401") => (RuleGroup::Stable, rules::pylint::rules::NonAsciiName),
195+
(Pylint, "C2403") => (RuleGroup::Stable, rules::pylint::rules::NonAsciiImportName),
196196
(Pylint, "C2701") => (RuleGroup::Preview, rules::pylint::rules::ImportPrivateName),
197197
(Pylint, "C2801") => (RuleGroup::Preview, rules::pylint::rules::UnnecessaryDunderCall),
198198
(Pylint, "C3002") => (RuleGroup::Stable, rules::pylint::rules::UnnecessaryDirectLambdaCall),
199199
(Pylint, "E0100") => (RuleGroup::Stable, rules::pylint::rules::YieldInInit),
200200
(Pylint, "E0101") => (RuleGroup::Stable, rules::pylint::rules::ReturnInInit),
201-
(Pylint, "E0115") => (RuleGroup::Preview, rules::pylint::rules::NonlocalAndGlobal),
201+
(Pylint, "E0115") => (RuleGroup::Stable, rules::pylint::rules::NonlocalAndGlobal),
202202
(Pylint, "E0116") => (RuleGroup::Stable, rules::pylint::rules::ContinueInFinally),
203203
(Pylint, "E0117") => (RuleGroup::Stable, rules::pylint::rules::NonlocalWithoutBinding),
204204
(Pylint, "E0118") => (RuleGroup::Stable, rules::pylint::rules::LoadBeforeGlobalDeclaration),
@@ -213,9 +213,9 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
213213
(Pylint, "E0309") => (RuleGroup::Preview, rules::pylint::rules::InvalidHashReturnType),
214214
(Pylint, "E0604") => (RuleGroup::Stable, rules::pylint::rules::InvalidAllObject),
215215
(Pylint, "E0605") => (RuleGroup::Stable, rules::pylint::rules::InvalidAllFormat),
216-
(Pylint, "E0643") => (RuleGroup::Preview, rules::pylint::rules::PotentialIndexError),
217-
(Pylint, "E0704") => (RuleGroup::Preview, rules::pylint::rules::MisplacedBareRaise),
218-
(Pylint, "E1132") => (RuleGroup::Preview, rules::pylint::rules::RepeatedKeywordArgument),
216+
(Pylint, "E0643") => (RuleGroup::Stable, rules::pylint::rules::PotentialIndexError),
217+
(Pylint, "E0704") => (RuleGroup::Stable, rules::pylint::rules::MisplacedBareRaise),
218+
(Pylint, "E1132") => (RuleGroup::Stable, rules::pylint::rules::RepeatedKeywordArgument),
219219
(Pylint, "E1141") => (RuleGroup::Preview, rules::pylint::rules::DictIterMissingItems),
220220
(Pylint, "E1142") => (RuleGroup::Stable, rules::pylint::rules::AwaitOutsideAsync),
221221
(Pylint, "E1205") => (RuleGroup::Stable, rules::pylint::rules::LoggingTooManyArgs),
@@ -250,16 +250,16 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
250250
(Pylint, "R0917") => (RuleGroup::Preview, rules::pylint::rules::TooManyPositional),
251251
(Pylint, "R1701") => (RuleGroup::Removed, rules::pylint::rules::RepeatedIsinstanceCalls),
252252
(Pylint, "R1702") => (RuleGroup::Preview, rules::pylint::rules::TooManyNestedBlocks),
253-
(Pylint, "R1704") => (RuleGroup::Preview, rules::pylint::rules::RedefinedArgumentFromLocal),
253+
(Pylint, "R1704") => (RuleGroup::Stable, rules::pylint::rules::RedefinedArgumentFromLocal),
254254
(Pylint, "R1706") => (RuleGroup::Removed, rules::pylint::rules::AndOrTernary),
255255
(Pylint, "R1711") => (RuleGroup::Stable, rules::pylint::rules::UselessReturn),
256256
(Pylint, "R1714") => (RuleGroup::Stable, rules::pylint::rules::RepeatedEqualityComparison),
257257
(Pylint, "R1722") => (RuleGroup::Stable, rules::pylint::rules::SysExitAlias),
258258
(Pylint, "R1730") => (RuleGroup::Preview, rules::pylint::rules::IfStmtMinMax),
259259
(Pylint, "R1733") => (RuleGroup::Preview, rules::pylint::rules::UnnecessaryDictIndexLookup),
260-
(Pylint, "R1736") => (RuleGroup::Preview, rules::pylint::rules::UnnecessaryListIndexLookup),
260+
(Pylint, "R1736") => (RuleGroup::Stable, rules::pylint::rules::UnnecessaryListIndexLookup),
261261
(Pylint, "R2004") => (RuleGroup::Stable, rules::pylint::rules::MagicValueComparison),
262-
(Pylint, "R2044") => (RuleGroup::Preview, rules::pylint::rules::EmptyComment),
262+
(Pylint, "R2044") => (RuleGroup::Stable, rules::pylint::rules::EmptyComment),
263263
(Pylint, "R5501") => (RuleGroup::Stable, rules::pylint::rules::CollapsibleElseIf),
264264
(Pylint, "R6104") => (RuleGroup::Preview, rules::pylint::rules::NonAugmentedAssignment),
265265
(Pylint, "R6201") => (RuleGroup::Preview, rules::pylint::rules::LiteralMembership),
@@ -268,25 +268,25 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
268268
(Pylint, "W0177") => (RuleGroup::Preview, rules::pylint::rules::NanComparison),
269269
(Pylint, "W0120") => (RuleGroup::Stable, rules::pylint::rules::UselessElseOnLoop),
270270
(Pylint, "W0127") => (RuleGroup::Stable, rules::pylint::rules::SelfAssigningVariable),
271-
(Pylint, "W0128") => (RuleGroup::Preview, rules::pylint::rules::RedeclaredAssignedName),
271+
(Pylint, "W0128") => (RuleGroup::Stable, rules::pylint::rules::RedeclaredAssignedName),
272272
(Pylint, "W0129") => (RuleGroup::Stable, rules::pylint::rules::AssertOnStringLiteral),
273273
(Pylint, "W0131") => (RuleGroup::Stable, rules::pylint::rules::NamedExprWithoutContext),
274-
(Pylint, "W0133") => (RuleGroup::Preview, rules::pylint::rules::UselessExceptionStatement),
274+
(Pylint, "W0133") => (RuleGroup::Stable, rules::pylint::rules::UselessExceptionStatement),
275275
(Pylint, "W0211") => (RuleGroup::Preview, rules::pylint::rules::BadStaticmethodArgument),
276-
(Pylint, "W0245") => (RuleGroup::Preview, rules::pylint::rules::SuperWithoutBrackets),
276+
(Pylint, "W0245") => (RuleGroup::Stable, rules::pylint::rules::SuperWithoutBrackets),
277277
(Pylint, "W0406") => (RuleGroup::Stable, rules::pylint::rules::ImportSelf),
278278
(Pylint, "W0602") => (RuleGroup::Stable, rules::pylint::rules::GlobalVariableNotAssigned),
279279
(Pylint, "W0603") => (RuleGroup::Stable, rules::pylint::rules::GlobalStatement),
280-
(Pylint, "W0604") => (RuleGroup::Preview, rules::pylint::rules::GlobalAtModuleLevel),
280+
(Pylint, "W0604") => (RuleGroup::Stable, rules::pylint::rules::GlobalAtModuleLevel),
281281
(Pylint, "W0642") => (RuleGroup::Preview, rules::pylint::rules::SelfOrClsAssignment),
282282
(Pylint, "W0711") => (RuleGroup::Stable, rules::pylint::rules::BinaryOpException),
283-
(Pylint, "W1501") => (RuleGroup::Preview, rules::pylint::rules::BadOpenMode),
283+
(Pylint, "W1501") => (RuleGroup::Stable, rules::pylint::rules::BadOpenMode),
284284
(Pylint, "W1508") => (RuleGroup::Stable, rules::pylint::rules::InvalidEnvvarDefault),
285285
(Pylint, "W1509") => (RuleGroup::Stable, rules::pylint::rules::SubprocessPopenPreexecFn),
286286
(Pylint, "W1510") => (RuleGroup::Stable, rules::pylint::rules::SubprocessRunWithoutCheck),
287287
(Pylint, "W1514") => (RuleGroup::Preview, rules::pylint::rules::UnspecifiedEncoding),
288288
(Pylint, "W1641") => (RuleGroup::Preview, rules::pylint::rules::EqWithoutHash),
289-
(Pylint, "W2101") => (RuleGroup::Preview, rules::pylint::rules::UselessWithLock),
289+
(Pylint, "W2101") => (RuleGroup::Stable, rules::pylint::rules::UselessWithLock),
290290
(Pylint, "W2901") => (RuleGroup::Stable, rules::pylint::rules::RedefinedLoopName),
291291
(Pylint, "W3201") => (RuleGroup::Preview, rules::pylint::rules::BadDunderMethodName),
292292
(Pylint, "W3301") => (RuleGroup::Stable, rules::pylint::rules::NestedMinMax),

crates/ruff_linter/src/rules/pylint/rules/bad_open_mode.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub(crate) fn bad_open_mode(checker: &mut Checker, call: &ast::ExprCall) {
5959
return;
6060
};
6161

62-
let Some(ast::ExprStringLiteral { value, .. }) = mode.as_string_literal_expr() else {
62+
let ast::Expr::StringLiteral(ast::ExprStringLiteral { value, .. }) = mode else {
6363
return;
6464
};
6565

crates/ruff_linter/src/rules/pylint/rules/literal_membership.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub struct LiteralMembership;
3737
impl AlwaysFixableViolation for LiteralMembership {
3838
#[derive_message_formats]
3939
fn message(&self) -> String {
40-
format!("Use a `set` literal when testing for membership")
40+
format!("Use a set literal when testing for membership")
4141
}
4242

4343
fn fix_title(&self) -> String {

crates/ruff_linter/src/rules/pylint/rules/non_ascii_module_import.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,20 @@ impl Violation for NonAsciiImportName {
4141
let Self { name, kind } = self;
4242
match kind {
4343
Kind::Aliased => {
44-
format!(
45-
"Module alias `{name}` contains a non-ASCII character, use an ASCII-only alias"
46-
)
44+
format!("Module alias `{name}` contains a non-ASCII character")
4745
}
4846
Kind::Unaliased => {
49-
format!(
50-
"Module name `{name}` contains a non-ASCII character, use an ASCII-only alias"
51-
)
47+
format!("Module name `{name}` contains a non-ASCII character")
5248
}
5349
}
5450
}
51+
52+
fn fix_title(&self) -> Option<String> {
53+
Some("Use an ASCII-only alias".to_string())
54+
}
5555
}
5656

57-
#[derive(Debug, PartialEq, Eq)]
57+
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
5858
enum Kind {
5959
/// The import uses a non-ASCII alias (e.g., `import foo as bár`).
6060
Aliased,

crates/ruff_linter/src/rules/pylint/rules/non_ascii_name.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ impl Violation for NonAsciiName {
3434
#[derive_message_formats]
3535
fn message(&self) -> String {
3636
let Self { name, kind } = self;
37-
format!("{kind} name `{name}` contains a non-ASCII character, consider renaming it")
37+
format!("{kind} name `{name}` contains a non-ASCII character")
38+
}
39+
40+
fn fix_title(&self) -> Option<String> {
41+
Some("Rename the variable using ASCII characters".to_string())
3842
}
3943
}
4044

@@ -82,7 +86,7 @@ pub(crate) fn non_ascii_name(binding: &Binding, locator: &Locator) -> Option<Dia
8286
))
8387
}
8488

85-
#[derive(Debug, PartialEq, Eq)]
89+
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
8690
enum Kind {
8791
Annotation,
8892
Argument,

crates/ruff_linter/src/rules/pylint/rules/potential_index_error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub struct PotentialIndexError;
2424
impl Violation for PotentialIndexError {
2525
#[derive_message_formats]
2626
fn message(&self) -> String {
27-
format!("Potential IndexError")
27+
format!("Expression is likely to raise `IndexError`")
2828
}
2929
}
3030

crates/ruff_linter/src/rules/pylint/rules/super_without_brackets.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ use ruff_text_size::Ranged;
88
use crate::checkers::ast::Checker;
99

1010
/// ## What it does
11-
/// Checks for `super` calls without parentheses.
11+
/// Detects attempts to use `super` without parentheses.
1212
///
1313
/// ## Why is this bad?
14-
/// When `super` is used without parentheses, it is not an actual call, and
15-
/// thus has no effect.
14+
/// The [`super()` callable](https://docs.python.org/3/library/functions.html#super)
15+
/// can be used inside method definitions to create a proxy object that
16+
/// delegates attribute access to a superclass of the current class. Attempting
17+
/// to access attributes on `super` itself, however, instead of the object
18+
/// returned by a call to `super()`, will raise `AttributeError`.
1619
///
1720
/// ## Example
1821
/// ```python
@@ -25,7 +28,7 @@ use crate::checkers::ast::Checker;
2528
/// class Dog(Animal):
2629
/// @staticmethod
2730
/// def speak():
28-
/// original_speak = super.speak()
31+
/// original_speak = super.speak() # ERROR: `super.speak()`
2932
/// return f"{original_speak} But as a dog, it barks!"
3033
/// ```
3134
///
@@ -40,7 +43,7 @@ use crate::checkers::ast::Checker;
4043
/// class Dog(Animal):
4144
/// @staticmethod
4245
/// def speak():
43-
/// original_speak = super().speak()
46+
/// original_speak = super().speak() # Correct: `super().speak()`
4447
/// return f"{original_speak} But as a dog, it barks!"
4548
/// ```
4649
#[violation]

crates/ruff_linter/src/rules/pylint/rules/unnecessary_list_index_lookup.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ pub struct UnnecessaryListIndexLookup;
3737
impl AlwaysFixableViolation for UnnecessaryListIndexLookup {
3838
#[derive_message_formats]
3939
fn message(&self) -> String {
40-
format!("Unnecessary lookup of list item by index")
40+
format!("List index lookup in `enumerate()` loop")
4141
}
4242

4343
fn fix_title(&self) -> String {
44-
format!("Use existing variable")
44+
format!("Use the loop variable directly")
4545
}
4646
}
4747

crates/ruff_linter/src/rules/pylint/rules/useless_with_lock.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ use ruff_text_size::Ranged;
66
use crate::checkers::ast::Checker;
77

88
/// ## What it does
9-
/// Checks for direct uses of lock objects in `with` statements.
9+
/// Checks for lock objects that are created and immediately discarded in
10+
/// `with` statements.
1011
///
1112
/// ## Why is this bad?
1213
/// Creating a lock (via `threading.Lock` or similar) in a `with` statement
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
---
22
source: crates/ruff_linter/src/rules/pylint/mod.rs
33
---
4-
non_ascii_name.py:1:1: PLC2401 Variable name `ápple_count` contains a non-ASCII character, consider renaming it
4+
non_ascii_name.py:1:1: PLC2401 Variable name `ápple_count` contains a non-ASCII character
55
|
66
1 | ápple_count: int = 1 # C2401
77
| ^^^^^^^^^^^ PLC2401
88
2 | ápple_count += 2 # C2401
99
3 | ápple_count = 3 # C2401
1010
|
11+
= help: Rename the variable using ASCII characters
1112

12-
non_ascii_name.py:2:1: PLC2401 Variable name `ápple_count` contains a non-ASCII character, consider renaming it
13+
non_ascii_name.py:2:1: PLC2401 Variable name `ápple_count` contains a non-ASCII character
1314
|
1415
1 | ápple_count: int = 1 # C2401
1516
2 | ápple_count += 2 # C2401
1617
| ^^^^^^^^^^^ PLC2401
1718
3 | ápple_count = 3 # C2401
1819
|
20+
= help: Rename the variable using ASCII characters
1921

20-
non_ascii_name.py:3:1: PLC2401 Variable name `ápple_count` contains a non-ASCII character, consider renaming it
22+
non_ascii_name.py:3:1: PLC2401 Variable name `ápple_count` contains a non-ASCII character
2123
|
2224
1 | ápple_count: int = 1 # C2401
2325
2 | ápple_count += 2 # C2401
@@ -26,47 +28,53 @@ non_ascii_name.py:3:1: PLC2401 Variable name `ápple_count` contains a non-ASCII
2628
4 |
2729
5 |pple_count for ápple_count in y)
2830
|
31+
= help: Rename the variable using ASCII characters
2932

30-
non_ascii_name.py:5:18: PLC2401 Variable name `ápple_count` contains a non-ASCII character, consider renaming it
33+
non_ascii_name.py:5:18: PLC2401 Variable name `ápple_count` contains a non-ASCII character
3134
|
3235
3 | ápple_count = 3 # C2401
3336
4 |
3437
5 |pple_count for ápple_count in y)
3538
| ^^^^^^^^^^^ PLC2401
3639
|
40+
= help: Rename the variable using ASCII characters
3741

38-
non_ascii_name.py:8:10: PLC2401 Argument name `ápple_count` contains a non-ASCII character, consider renaming it
42+
non_ascii_name.py:8:10: PLC2401 Argument name `ápple_count` contains a non-ASCII character
3943
|
4044
8 | def funcpple_count):
4145
| ^^^^^^^^^^^ PLC2401
4246
9 | global ápple_count
4347
10 | nonlocal ápple_count
4448
|
49+
= help: Rename the variable using ASCII characters
4550

46-
non_ascii_name.py:9:12: PLC2401 Global name `ápple_count` contains a non-ASCII character, consider renaming it
51+
non_ascii_name.py:9:12: PLC2401 Global name `ápple_count` contains a non-ASCII character
4752
|
4853
8 | def funcpple_count):
4954
9 | global ápple_count
5055
| ^^^^^^^^^^^ PLC2401
5156
10 | nonlocal ápple_count
5257
|
58+
= help: Rename the variable using ASCII characters
5359

54-
non_ascii_name.py:13:5: PLC2401 Function name `ápple_count` contains a non-ASCII character, consider renaming it
60+
non_ascii_name.py:13:5: PLC2401 Function name `ápple_count` contains a non-ASCII character
5561
|
5662
13 | def ápple_count():
5763
| ^^^^^^^^^^^ PLC2401
5864
14 | pass
5965
|
66+
= help: Rename the variable using ASCII characters
6067

61-
non_ascii_name.py:18:10: PLC2401 Variable name `ápple_count` contains a non-ASCII character, consider renaming it
68+
non_ascii_name.py:18:10: PLC2401 Variable name `ápple_count` contains a non-ASCII character
6269
|
6370
17 | match ápple_count:
6471
18 | case ápple_count:
6572
| ^^^^^^^^^^^ PLC2401
6673
19 | pass
6774
|
75+
= help: Rename the variable using ASCII characters
6876

69-
non_ascii_name.py:21:1: PLC2401 Annotation name `ápple_count` contains a non-ASCII character, consider renaming it
77+
non_ascii_name.py:21:1: PLC2401 Annotation name `ápple_count` contains a non-ASCII character
7078
|
7179
19 | pass
7280
20 |
@@ -75,5 +83,4 @@ non_ascii_name.py:21:1: PLC2401 Annotation name `ápple_count` contains a non-AS
7583
22 |
7684
23 | try:
7785
|
78-
79-
86+
= help: Rename the variable using ASCII characters
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,40 @@
11
---
22
source: crates/ruff_linter/src/rules/pylint/mod.rs
33
---
4-
non_ascii_module_import.py:1:29: PLC2403 Module alias `łos` contains a non-ASCII character, use an ASCII-only alias
4+
non_ascii_module_import.py:1:29: PLC2403 Module alias `łos` contains a non-ASCII character
55
|
66
1 | from os.path import join as łos # Error
77
| ^^^ PLC2403
88
2 | from os.path import join as los # OK
99
|
10+
= help: Use an ASCII-only alias
1011

11-
non_ascii_module_import.py:4:24: PLC2403 Module alias `łos` contains a non-ASCII character, use an ASCII-only alias
12+
non_ascii_module_import.py:4:24: PLC2403 Module alias `łos` contains a non-ASCII character
1213
|
1314
2 | from os.path import join as los # OK
1415
3 |
1516
4 | import os.path.join as łos # Error
1617
| ^^^ PLC2403
1718
5 | import os.path.join as los # OK
1819
|
20+
= help: Use an ASCII-only alias
1921

20-
non_ascii_module_import.py:7:8: PLC2403 Module name `os.path.łos` contains a non-ASCII character, use an ASCII-only alias
22+
non_ascii_module_import.py:7:8: PLC2403 Module name `os.path.łos` contains a non-ASCII character
2123
|
2224
5 | import os.path.join as los # OK
2325
6 |
2426
7 | import os.pathos # Error (recommend an ASCII alias)
2527
| ^^^^^^^^^^^ PLC2403
2628
8 | import os.path.los # OK
2729
|
30+
= help: Use an ASCII-only alias
2831

29-
non_ascii_module_import.py:10:21: PLC2403 Module name `łos` contains a non-ASCII character, use an ASCII-only alias
32+
non_ascii_module_import.py:10:21: PLC2403 Module name `łos` contains a non-ASCII character
3033
|
3134
8 | import os.path.los # OK
3235
9 |
3336
10 | from os.path import łos # Error (recommend an ASCII alias)
3437
| ^^^ PLC2403
3538
11 | from os.path import los # OK
3639
|
37-
38-
40+
= help: Use an ASCII-only alias

0 commit comments

Comments
 (0)