Skip to content

Commit b54018e

Browse files
committed
[pylint] Better inference for str.strip (PLE310)
1 parent b93f829 commit b54018e

File tree

4 files changed

+27
-217
lines changed

4 files changed

+27
-217
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,6 @@ mod tests {
445445
Rule::RepeatedEqualityComparison,
446446
Path::new("repeated_equality_comparison.py")
447447
)]
448-
#[test_case(Rule::BadStrStripCall, Path::new("bad_str_strip_call.py"))]
449448
#[test_case(
450449
Rule::BadStaticmethodArgument,
451450
Path::new("bad_staticmethod_argument.py")

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,6 @@ pub(crate) fn bad_str_strip_call(checker: &Checker, call: &ast::ExprCall) {
187187

188188
let value = &**value;
189189

190-
if checker.settings.preview.is_disabled()
191-
&& !matches!(value, Expr::StringLiteral(_) | Expr::BytesLiteral(_))
192-
{
193-
return;
194-
}
195-
196190
let Some(value_kind) = ValueKind::from(value, checker.semantic()) else {
197191
return;
198192
};

crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__PLE1310_bad_str_strip_call.py.snap

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,30 @@ bad_str_strip_call.py:81:10: PLE1310 String `strip` call contains duplicate char
181181
82 |
182182
83 | # Errors: Type inference
183183
|
184+
185+
bad_str_strip_call.py:85:9: PLE1310 String `strip` call contains duplicate characters
186+
|
187+
83 | # Errors: Type inference
188+
84 | b = b''
189+
85 | b.strip(b'//')
190+
| ^^^^^ PLE1310
191+
86 |
192+
87 | # Errors: Type inference (preview)
193+
|
194+
195+
bad_str_strip_call.py:89:12: PLE1310 String `rstrip` call contains duplicate characters (did you mean `removesuffix`?)
196+
|
197+
87 | # Errors: Type inference (preview)
198+
88 | foo: str = ""; bar: bytes = b""
199+
89 | foo.rstrip("//")
200+
| ^^^^ PLE1310
201+
90 | bar.lstrip(b"//")
202+
|
203+
204+
bad_str_strip_call.py:90:12: PLE1310 String `lstrip` call contains duplicate characters (did you mean `removeprefix`?)
205+
|
206+
88 | foo: str = ""; bar: bytes = b""
207+
89 | foo.rstrip("//")
208+
90 | bar.lstrip(b"//")
209+
| ^^^^^ PLE1310
210+
|

crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__preview__PLE1310_bad_str_strip_call.py.snap

Lines changed: 0 additions & 210 deletions
This file was deleted.

0 commit comments

Comments
 (0)