mirror of
https://github.com/astral-sh/ruff
synced 2026-01-24 06:50:59 -05:00
Pyupgrade: Printf string formatting (#1803)
This commit is contained in:
@@ -1,5 +1,15 @@
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
/// Returns `true` if a string is a valid Python identifier (e.g., variable
|
||||
/// name).
|
||||
pub fn is_identifier(s: &str) -> bool {
|
||||
// Is the first character a letter or underscore?
|
||||
if !s
|
||||
.chars()
|
||||
.next()
|
||||
.map_or(false, |c| c.is_alphabetic() || c == '_')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
pub static IDENTIFIER_REGEX: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(r"^[A-Za-z_][A-Za-z0-9_]*$").unwrap());
|
||||
// Are the rest of the characters letters, digits, or underscores?
|
||||
s.chars().skip(1).all(|c| c.is_alphanumeric() || c == '_')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user