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.
This commit is contained in:
Charlie Marsh 2023-08-01 12:01:48 -04:00 committed by GitHub
parent e08f873077
commit 83fe103d6e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View file

@ -40,3 +40,4 @@ __all__ = __all__ + ["Hello"]
__all__ = __all__ + multiprocessing.__all__
__all__ = list[str](["Hello", "world"])

View file

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