From 83fe103d6e62f8ef70d3fae8db133cbe90f4abd2 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Tue, 1 Aug 2023 12:01:48 -0400 Subject: [PATCH] Allow generic tuple and list calls in __all__ (#6247) ## Summary Allows, e.g., `__all__ = list[str]()`. Closes https://github.com/astral-sh/ruff/issues/6226. --- .../resources/test/fixtures/pylint/invalid_all_format.py | 1 + crates/ruff_python_ast/src/all.rs | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/ruff/resources/test/fixtures/pylint/invalid_all_format.py b/crates/ruff/resources/test/fixtures/pylint/invalid_all_format.py index 9054087de431a..fc7a3f8e154fa 100644 --- a/crates/ruff/resources/test/fixtures/pylint/invalid_all_format.py +++ b/crates/ruff/resources/test/fixtures/pylint/invalid_all_format.py @@ -40,3 +40,4 @@ __all__ = __all__ + multiprocessing.__all__ +__all__ = list[str](["Hello", "world"]) diff --git a/crates/ruff_python_ast/src/all.rs b/crates/ruff_python_ast/src/all.rs index 27955a845ef96..f3dcfb67dfbba 100644 --- a/crates/ruff_python_ast/src/all.rs +++ b/crates/ruff_python_ast/src/all.rs @@ -1,3 +1,4 @@ +use crate::helpers::map_subscript; use crate::{self as ast, Constant, Expr, Stmt}; use bitflags::bitflags; @@ -67,9 +68,9 @@ where keywords, .. }) => { - // Allow `tuple()` and `list()` calls. + // Allow `tuple()`, `list()`, and their generic forms, like `list[int]()`. if keywords.is_empty() && args.len() <= 1 { - if let Expr::Name(ast::ExprName { id, .. }) = func.as_ref() { + if let Expr::Name(ast::ExprName { id, .. }) = map_subscript(func) { let id = id.as_str(); if matches!(id, "tuple" | "list") && is_builtin(id) { let [arg] = args.as_slice() else {