mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-13 13:57:22 +00:00
Remove some additional manual iterator matches (#5482)
## Summary I've done a few of these PRs, I thought I'd caught them all, but missed this pattern.
This commit is contained in:
parent
dadad0e9ed
commit
00fbbe4223
6 changed files with 75 additions and 69 deletions
|
@ -1,4 +1,4 @@
|
|||
use crate::keyword::KWLIST;
|
||||
use crate::keyword::is_keyword;
|
||||
|
||||
/// Returns `true` if a string is a valid Python identifier (e.g., variable
|
||||
/// name).
|
||||
|
@ -18,7 +18,7 @@ pub fn is_identifier(name: &str) -> bool {
|
|||
}
|
||||
|
||||
// Is the identifier a keyword?
|
||||
if KWLIST.contains(&name) {
|
||||
if is_keyword(name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ pub fn is_module_name(name: &str) -> bool {
|
|||
}
|
||||
|
||||
// Is the identifier a keyword?
|
||||
if KWLIST.contains(&name) {
|
||||
if is_keyword(name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,7 @@ pub fn is_migration_name(name: &str) -> bool {
|
|||
}
|
||||
|
||||
// Is the identifier a keyword?
|
||||
if KWLIST.contains(&name) {
|
||||
if is_keyword(name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,41 @@
|
|||
// See: https://github.com/python/cpython/blob/9d692841691590c25e6cf5b2250a594d3bf54825/Lib/keyword.py#L18
|
||||
pub(crate) const KWLIST: [&str; 35] = [
|
||||
"False", "None", "True", "and", "as", "assert", "async", "await", "break", "class", "continue",
|
||||
"def", "del", "elif", "else", "except", "finally", "for", "from", "global", "if", "import",
|
||||
"in", "is", "lambda", "nonlocal", "not", "or", "pass", "raise", "return", "try", "while",
|
||||
"with", "yield",
|
||||
];
|
||||
pub(crate) fn is_keyword(name: &str) -> bool {
|
||||
matches!(
|
||||
name,
|
||||
"False"
|
||||
| "None"
|
||||
| "True"
|
||||
| "and"
|
||||
| "as"
|
||||
| "assert"
|
||||
| "async"
|
||||
| "await"
|
||||
| "break"
|
||||
| "class"
|
||||
| "continue"
|
||||
| "def"
|
||||
| "del"
|
||||
| "elif"
|
||||
| "else"
|
||||
| "except"
|
||||
| "finally"
|
||||
| "for"
|
||||
| "from"
|
||||
| "global"
|
||||
| "if"
|
||||
| "import"
|
||||
| "in"
|
||||
| "is"
|
||||
| "lambda"
|
||||
| "nonlocal"
|
||||
| "not"
|
||||
| "or"
|
||||
| "pass"
|
||||
| "raise"
|
||||
| "return"
|
||||
| "try"
|
||||
| "while"
|
||||
| "with"
|
||||
| "yield",
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue