mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-02 04:48:06 +00:00
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:
parent
e08f873077
commit
83fe103d6e
2 changed files with 4 additions and 2 deletions
|
|
@ -40,3 +40,4 @@ __all__ = __all__ + ["Hello"]
|
||||||
|
|
||||||
__all__ = __all__ + multiprocessing.__all__
|
__all__ = __all__ + multiprocessing.__all__
|
||||||
|
|
||||||
|
__all__ = list[str](["Hello", "world"])
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::helpers::map_subscript;
|
||||||
use crate::{self as ast, Constant, Expr, Stmt};
|
use crate::{self as ast, Constant, Expr, Stmt};
|
||||||
use bitflags::bitflags;
|
use bitflags::bitflags;
|
||||||
|
|
||||||
|
|
@ -67,9 +68,9 @@ where
|
||||||
keywords,
|
keywords,
|
||||||
..
|
..
|
||||||
}) => {
|
}) => {
|
||||||
// Allow `tuple()` and `list()` calls.
|
// Allow `tuple()`, `list()`, and their generic forms, like `list[int]()`.
|
||||||
if keywords.is_empty() && args.len() <= 1 {
|
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();
|
let id = id.as_str();
|
||||||
if matches!(id, "tuple" | "list") && is_builtin(id) {
|
if matches!(id, "tuple" | "list") && is_builtin(id) {
|
||||||
let [arg] = args.as_slice() else {
|
let [arg] = args.as_slice() else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue