Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow re-assignments to __all__ #4967

Merged
merged 1 commit into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions crates/ruff/resources/test/fixtures/pylint/invalid_all_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@

__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",)
Expand All @@ -29,3 +35,8 @@
__all__ = list(["Hello"]) + list(["world"])

__all__ = tuple(["Hello"]) + ("world",)

__all__ = __all__ + ["Hello"]

__all__ = __all__ + multiprocessing.__all__

Original file line number Diff line number Diff line change
Expand Up @@ -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"]
|


14 changes: 13 additions & 1 deletion crates/ruff_python_ast/src/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down