Skip to content

Commit

Permalink
Allow generic tuple and list calls in __all__ (#6247)
Browse files Browse the repository at this point in the history
## Summary

Allows, e.g., `__all__ = list[str]()`.

Closes #6226.
  • Loading branch information
charliermarsh authored Aug 1, 2023
1 parent e08f873 commit 83fe103
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@

__all__ = __all__ + multiprocessing.__all__

__all__ = list[str](["Hello", "world"])
5 changes: 3 additions & 2 deletions crates/ruff_python_ast/src/all.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::helpers::map_subscript;
use crate::{self as ast, Constant, Expr, Stmt};
use bitflags::bitflags;

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 83fe103

Please sign in to comment.