Add pyflakes.extend-generics setting (#4677)

This commit is contained in:
Jonathan Plasse 2023-06-02 00:19:37 +02:00 committed by GitHub
parent 3180f9978a
commit edadd7814f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 156 additions and 8 deletions

View file

@ -1,7 +1,7 @@
use rustpython_parser::ast::{self, Constant, Expr, Operator};
use num_traits::identities::Zero;
use ruff_python_ast::call_path::{from_unqualified_name, CallPath};
use ruff_python_ast::call_path::{from_qualified_name, from_unqualified_name, CallPath};
use ruff_python_stdlib::typing::{
IMMUTABLE_GENERIC_TYPES, IMMUTABLE_TYPES, PEP_585_GENERICS, PEP_593_SUBSCRIPTS, SUBSCRIPTS,
};
@ -29,6 +29,7 @@ pub fn match_annotated_subscript<'a>(
expr: &Expr,
semantic_model: &SemanticModel,
typing_modules: impl Iterator<Item = &'a str>,
extend_generics: &[String],
) -> Option<SubscriptKind> {
if !matches!(expr, Expr::Name(_) | Expr::Attribute(_)) {
return None;
@ -37,7 +38,12 @@ pub fn match_annotated_subscript<'a>(
semantic_model
.resolve_call_path(expr)
.and_then(|call_path| {
if SUBSCRIPTS.contains(&call_path.as_slice()) {
if SUBSCRIPTS.contains(&call_path.as_slice())
|| extend_generics
.iter()
.map(|target| from_qualified_name(target))
.any(|target| call_path == target)
{
return Some(SubscriptKind::AnnotatedSubscript);
}
if PEP_593_SUBSCRIPTS.contains(&call_path.as_slice()) {