Fix typing::match_annotated_subscript matching ExprKind::Call (#1554)

This commit is contained in:
Martin Fischer
2023-01-02 18:13:45 +01:00
committed by GitHub
parent f52691a90a
commit cdae2f0e67
4 changed files with 20 additions and 1 deletions

View File

@@ -0,0 +1,6 @@
from __future__ import annotations
# test case for https://github.com/charliermarsh/ruff/issues/1552
def _():
x = 0
list()[x:]

View File

@@ -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<()> {

View File

@@ -0,0 +1,6 @@
---
source: src/pyflakes/mod.rs
expression: checks
---
[]

View File

@@ -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 {