mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 10:22:24 +00:00
Allow re-assignments to __all__
(#4967)
This commit is contained in:
parent
902c4e7d77
commit
58d08219e8
3 changed files with 55 additions and 2 deletions
|
@ -14,6 +14,12 @@ __all__ = (x for x in ["Hello", "world"]) # [invalid-all-format]
|
|||
|
||||
__all__ = {x for x in ["Hello", "world"]} # [invalid-all-format]
|
||||
|
||||
__all__ = foo # [invalid-all-format]
|
||||
|
||||
__all__ = foo.bar # [invalid-all-format]
|
||||
|
||||
__all__ = foo["bar"] # [invalid-all-format]
|
||||
|
||||
__all__ = ["Hello"]
|
||||
|
||||
__all__ = ("Hello",)
|
||||
|
@ -29,3 +35,8 @@ __all__ = list({"Hello", "world"})
|
|||
__all__ = list(["Hello"]) + list(["world"])
|
||||
|
||||
__all__ = tuple(["Hello"]) + ("world",)
|
||||
|
||||
__all__ = __all__ + ["Hello"]
|
||||
|
||||
__all__ = __all__ + multiprocessing.__all__
|
||||
|
||||
|
|
|
@ -76,7 +76,37 @@ invalid_all_format.py:15:1: PLE0605 Invalid format for `__all__`, must be `tuple
|
|||
17 | __all__ = {x for x in ["Hello", "world"]} # [invalid-all-format]
|
||||
| ^^^^^^^ PLE0605
|
||||
18 |
|
||||
19 | __all__ = ["Hello"]
|
||||
19 | __all__ = foo # [invalid-all-format]
|
||||
|
|
||||
|
||||
invalid_all_format.py:17:1: PLE0605 Invalid format for `__all__`, must be `tuple` or `list`
|
||||
|
|
||||
17 | __all__ = {x for x in ["Hello", "world"]} # [invalid-all-format]
|
||||
18 |
|
||||
19 | __all__ = foo # [invalid-all-format]
|
||||
| ^^^^^^^ PLE0605
|
||||
20 |
|
||||
21 | __all__ = foo.bar # [invalid-all-format]
|
||||
|
|
||||
|
||||
invalid_all_format.py:19:1: PLE0605 Invalid format for `__all__`, must be `tuple` or `list`
|
||||
|
|
||||
19 | __all__ = foo # [invalid-all-format]
|
||||
20 |
|
||||
21 | __all__ = foo.bar # [invalid-all-format]
|
||||
| ^^^^^^^ PLE0605
|
||||
22 |
|
||||
23 | __all__ = foo["bar"] # [invalid-all-format]
|
||||
|
|
||||
|
||||
invalid_all_format.py:21:1: PLE0605 Invalid format for `__all__`, must be `tuple` or `list`
|
||||
|
|
||||
21 | __all__ = foo.bar # [invalid-all-format]
|
||||
22 |
|
||||
23 | __all__ = foo["bar"] # [invalid-all-format]
|
||||
| ^^^^^^^ PLE0605
|
||||
24 |
|
||||
25 | __all__ = ["Hello"]
|
||||
|
|
||||
|
||||
|
||||
|
|
|
@ -45,11 +45,23 @@ where
|
|||
// Allow comprehensions, even though we can't statically analyze them.
|
||||
return (None, AllNamesFlags::empty());
|
||||
}
|
||||
Expr::Name(ast::ExprName { id, .. }) => {
|
||||
// Ex) `__all__ = __all__ + multiprocessing.__all__`
|
||||
if id == "__all__" {
|
||||
return (None, AllNamesFlags::empty());
|
||||
}
|
||||
}
|
||||
Expr::Attribute(ast::ExprAttribute { attr, .. }) => {
|
||||
// Ex) `__all__ = __all__ + multiprocessing.__all__`
|
||||
if attr == "__all__" {
|
||||
return (None, AllNamesFlags::empty());
|
||||
}
|
||||
}
|
||||
Expr::Call(ast::ExprCall {
|
||||
func,
|
||||
args,
|
||||
keywords,
|
||||
range: _range,
|
||||
..
|
||||
}) => {
|
||||
// Allow `tuple()` and `list()` calls.
|
||||
if keywords.is_empty() && args.len() <= 1 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue