Allow list comprehensions for __all__ assignment (#2326)
This commit is contained in:
7
resources/test/fixtures/pylint/PLE0605.py
vendored
7
resources/test/fixtures/pylint/PLE0605.py
vendored
@@ -1,7 +0,0 @@
|
||||
__all__ = ("CONST") # [invalid-all-format]
|
||||
|
||||
__all__ = ["Hello"] + {"world"} # [invalid-all-format]
|
||||
|
||||
__all__ += {"world"} # [invalid-all-format]
|
||||
|
||||
__all__ = {"world"} + ["Hello"] # [invalid-all-format]
|
||||
19
resources/test/fixtures/pylint/invalid_all_format.py
vendored
Normal file
19
resources/test/fixtures/pylint/invalid_all_format.py
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
__all__ = "CONST" # [invalid-all-format]
|
||||
|
||||
__all__ = ["Hello"] + {"world"} # [invalid-all-format]
|
||||
|
||||
__all__ += {"world"} # [invalid-all-format]
|
||||
|
||||
__all__ = {"world"} + ["Hello"] # [invalid-all-format]
|
||||
|
||||
__all__ = (x for x in ["Hello", "world"]) # [invalid-all-format]
|
||||
|
||||
__all__ = {x for x in ["Hello", "world"]} # [invalid-all-format]
|
||||
|
||||
__all__ = ["Hello"]
|
||||
|
||||
__all__ = ("Hello",)
|
||||
|
||||
__all__ = ["Hello"] + ("world",)
|
||||
|
||||
__all__ = [x for x in ["Hello", "world"]]
|
||||
@@ -88,6 +88,11 @@ pub fn extract_all_names(
|
||||
}
|
||||
}
|
||||
}
|
||||
ExprKind::ListComp { .. } => {
|
||||
// Allow list comprehensions, even though we can't statically analyze them.
|
||||
// TODO(charlie): Allow `list()` and `tuple()` calls too, and extract the members
|
||||
// from them (even if, e.g., it's `list({...})`).
|
||||
}
|
||||
_ => {
|
||||
flags |= AllNamesFlags::INVALID_FORMAT;
|
||||
}
|
||||
|
||||
@@ -34,8 +34,8 @@ mod tests {
|
||||
#[test_case(Rule::MagicValueComparison, Path::new("magic_value_comparison.py"); "PLR2004")]
|
||||
#[test_case(Rule::UselessElseOnLoop, Path::new("useless_else_on_loop.py"); "PLW0120")]
|
||||
#[test_case(Rule::GlobalVariableNotAssigned, Path::new("global_variable_not_assigned.py"); "PLW0602")]
|
||||
#[test_case(Rule::InvalidAllFormat, Path::new("PLE0605.py"); "PLE0605")]
|
||||
#[test_case(Rule::InvalidAllObject, Path::new("PLE0604.py"); "PLE0604")]
|
||||
#[test_case(Rule::InvalidAllFormat, Path::new("invalid_all_format.py"); "PLE0605")]
|
||||
#[test_case(Rule::InvalidAllObject, Path::new("invalid_all_object.py"); "PLE0604")]
|
||||
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
|
||||
let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
|
||||
@@ -42,4 +42,24 @@ expression: diagnostics
|
||||
column: 7
|
||||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
InvalidAllFormat: ~
|
||||
location:
|
||||
row: 9
|
||||
column: 0
|
||||
end_location:
|
||||
row: 9
|
||||
column: 7
|
||||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
InvalidAllFormat: ~
|
||||
location:
|
||||
row: 11
|
||||
column: 0
|
||||
end_location:
|
||||
row: 11
|
||||
column: 7
|
||||
fix: ~
|
||||
parent: ~
|
||||
|
||||
Reference in New Issue
Block a user