Fix typing::match_annotated_subscript matching ExprKind::Call (#1554)
This commit is contained in:
6
resources/test/fixtures/pyflakes/F841_2.py
vendored
Normal file
6
resources/test/fixtures/pyflakes/F841_2.py
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
# test case for https://github.com/charliermarsh/ruff/issues/1552
|
||||
def _():
|
||||
x = 0
|
||||
list()[x:]
|
||||
@@ -102,6 +102,7 @@ mod tests {
|
||||
#[test_case(CheckCode::F823, Path::new("F823.py"); "F823")]
|
||||
#[test_case(CheckCode::F841, Path::new("F841_0.py"); "F841_0")]
|
||||
#[test_case(CheckCode::F841, Path::new("F841_1.py"); "F841_1")]
|
||||
#[test_case(CheckCode::F841, Path::new("F841_2.py"); "F841_2")]
|
||||
#[test_case(CheckCode::F842, Path::new("F842.py"); "F842")]
|
||||
#[test_case(CheckCode::F901, Path::new("F901.py"); "F901")]
|
||||
fn checks(check_code: CheckCode, path: &Path) -> Result<()> {
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
---
|
||||
source: src/pyflakes/mod.rs
|
||||
expression: checks
|
||||
---
|
||||
[]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use once_cell::sync::Lazy;
|
||||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
use rustpython_ast::Expr;
|
||||
use rustpython_ast::{Expr, ExprKind};
|
||||
|
||||
use crate::ast::helpers::{collect_call_paths, dealias_call_path, match_call_path};
|
||||
|
||||
@@ -219,6 +219,12 @@ pub fn match_annotated_subscript<F>(
|
||||
where
|
||||
F: Fn(&str) -> bool,
|
||||
{
|
||||
if !matches!(
|
||||
expr.node,
|
||||
ExprKind::Name { .. } | ExprKind::Attribute { .. }
|
||||
) {
|
||||
return None;
|
||||
}
|
||||
let call_path = dealias_call_path(collect_call_paths(expr), import_aliases);
|
||||
if !call_path.is_empty() {
|
||||
for (module, member) in SUBSCRIPTS {
|
||||
|
||||
Reference in New Issue
Block a user