Don't flag B009/B010 if identifiers would be mangled (#2204)

This commit is contained in:
Samuel Cormier-Iijima
2023-01-26 12:56:18 -05:00
committed by GitHub
parent 0ad6b8224d
commit 7370a27c09
6 changed files with 101 additions and 50 deletions

View File

@@ -13,3 +13,12 @@ pub fn is_identifier(s: &str) -> bool {
// Are the rest of the characters letters, digits, or underscores?
s.chars().skip(1).all(|c| c.is_alphanumeric() || c == '_')
}
/// Returns `true` if a string is a private identifier, such that, when the
/// identifier is defined in a class definition, it will be mangled prior to
/// code generation.
///
/// See: <https://docs.python.org/3.5/reference/expressions.html?highlight=mangling#index-5>.
pub fn is_mangled_private(id: &str) -> bool {
id.starts_with("__") && !id.ends_with("__")
}