From c0ad875339864226dbe5419a6382b14f52485eac Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Mon, 6 Mar 2023 18:28:20 -0500 Subject: [PATCH] Remove unnecessary quote-stripping method (#3372) --- crates/ruff/src/rules/pyflakes/fixes.rs | 4 ++-- crates/ruff_python_stdlib/src/str.rs | 23 +---------------------- 2 files changed, 3 insertions(+), 24 deletions(-) diff --git a/crates/ruff/src/rules/pyflakes/fixes.rs b/crates/ruff/src/rules/pyflakes/fixes.rs index 5dda436d6a..4058b8c751 100644 --- a/crates/ruff/src/rules/pyflakes/fixes.rs +++ b/crates/ruff/src/rules/pyflakes/fixes.rs @@ -1,9 +1,9 @@ use anyhow::{bail, Result}; use libcst_native::{Call, Codegen, CodegenState, Dict, DictElement, Expression}; -use ruff_python_stdlib::str::strip_quotes_and_prefixes; use rustpython_parser::ast::{Excepthandler, Expr}; use rustpython_parser::{lexer, Mode, Tok}; +use crate::ast::strings::raw_contents; use crate::ast::types::Range; use crate::cst::matchers::{match_expr, match_module}; use crate::fix::Fix; @@ -37,7 +37,7 @@ pub fn remove_unused_format_arguments_from_dict( DictElement::Simple { key: Expression::SimpleString(name), .. - } if unused_arguments.contains(&strip_quotes_and_prefixes(name.value)) => None, + } if unused_arguments.contains(&raw_contents(name.value)) => None, e => Some(e.clone()), }) .collect(), diff --git a/crates/ruff_python_stdlib/src/str.rs b/crates/ruff_python_stdlib/src/str.rs index 82b80073c1..f62d04a200 100644 --- a/crates/ruff_python_stdlib/src/str.rs +++ b/crates/ruff_python_stdlib/src/str.rs @@ -38,22 +38,9 @@ pub fn is_upper(s: &str) -> bool { cased } -/// Remove prefixes (u, r, b) and quotes around a string. This expects the given -/// string to be a valid Python string representation, it doesn't do any -/// validation. -pub fn strip_quotes_and_prefixes(s: &str) -> &str { - match STRING_QUOTE_PREFIX_REGEX.captures(s) { - Some(caps) => match caps.name("raw") { - Some(m) => m.as_str(), - None => s, - }, - None => s, - } -} - #[cfg(test)] mod tests { - use crate::str::{is_lower, is_upper, strip_quotes_and_prefixes}; + use crate::str::{is_lower, is_upper}; #[test] fn test_is_lower() { @@ -76,12 +63,4 @@ mod tests { assert!(!is_upper("")); assert!(!is_upper("_")); } - - #[test] - fn test_strip_quotes_and_prefixes() { - assert_eq!(strip_quotes_and_prefixes(r#"'a'"#), "a"); - assert_eq!(strip_quotes_and_prefixes(r#"bur'a'"#), "a"); - assert_eq!(strip_quotes_and_prefixes(r#"UrB'a'"#), "a"); - assert_eq!(strip_quotes_and_prefixes(r#""a""#), "a"); - } }