Improve performance of import matching code (#744)

This commit is contained in:
Charlie Marsh 2022-11-14 17:14:22 -05:00 committed by GitHub
parent fea029ae35
commit f67727b13c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 238 additions and 150 deletions

View file

@ -7,7 +7,7 @@ use crate::check_ast::Checker;
use crate::checks::{Check, CheckCode, CheckKind};
fn is_sys(checker: &Checker, expr: &Expr, target: &str) -> bool {
match_module_member(expr, &format!("sys.{target}"), &checker.from_imports)
match_module_member(expr, "sys", target, &checker.from_imports)
}
/// YTT101, YTT102, YTT301, YTT303
@ -181,7 +181,7 @@ pub fn compare(checker: &mut Checker, left: &Expr, ops: &[Cmpop], comparators: &
/// YTT202
pub fn name_or_attribute(checker: &mut Checker, expr: &Expr) {
if match_module_member(expr, "six.PY3", &checker.from_imports) {
if match_module_member(expr, "six", "PY3", &checker.from_imports) {
checker.add_check(Check::new(
CheckKind::SixPY3Referenced,
Range::from_located(expr),