Skip to content

Commit 826a12c

Browse files
charliermarshzanieb
authored andcommitted
Recategorize static-key-dict-comprehension from RUF011 to B035 (#9428)
## Summary This rule was added to flake8-bugbear. In general, we tend to prefer redirecting to prominent plugins when our own rules are reimplemented (since more projects have `B` activated than `RUF`). ## Test Plan `cargo test`
1 parent 065fa23 commit 826a12c

File tree

11 files changed

+29
-28
lines changed

11 files changed

+29
-28
lines changed

crates/ruff_linter/src/checkers/ast/analyze/expression.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1446,7 +1446,7 @@ pub(crate) fn expression(expr: &Expr, checker: &mut Checker) {
14461446
}
14471447
}
14481448
if checker.enabled(Rule::StaticKeyDictComprehension) {
1449-
ruff::rules::static_key_dict_comprehension(checker, dict_comp);
1449+
flake8_bugbear::rules::static_key_dict_comprehension(checker, dict_comp);
14501450
}
14511451
}
14521452
Expr::GeneratorExp(

crates/ruff_linter/src/codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
351351
(Flake8Bugbear, "032") => (RuleGroup::Stable, rules::flake8_bugbear::rules::UnintentionalTypeAnnotation),
352352
(Flake8Bugbear, "033") => (RuleGroup::Stable, rules::flake8_bugbear::rules::DuplicateValue),
353353
(Flake8Bugbear, "034") => (RuleGroup::Stable, rules::flake8_bugbear::rules::ReSubPositionalArgs),
354+
(Flake8Bugbear, "035") => (RuleGroup::Stable, rules::flake8_bugbear::rules::StaticKeyDictComprehension),
354355
(Flake8Bugbear, "904") => (RuleGroup::Stable, rules::flake8_bugbear::rules::RaiseWithoutFromInsideExcept),
355356
(Flake8Bugbear, "905") => (RuleGroup::Stable, rules::flake8_bugbear::rules::ZipWithoutExplicitStrict),
356357

@@ -916,7 +917,6 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
916917
(Ruff, "008") => (RuleGroup::Stable, rules::ruff::rules::MutableDataclassDefault),
917918
(Ruff, "009") => (RuleGroup::Stable, rules::ruff::rules::FunctionCallInDataclassDefaultArgument),
918919
(Ruff, "010") => (RuleGroup::Stable, rules::ruff::rules::ExplicitFStringTypeConversion),
919-
(Ruff, "011") => (RuleGroup::Stable, rules::ruff::rules::StaticKeyDictComprehension),
920920
(Ruff, "012") => (RuleGroup::Stable, rules::ruff::rules::MutableClassDefault),
921921
(Ruff, "013") => (RuleGroup::Stable, rules::ruff::rules::ImplicitOptional),
922922
(Ruff, "015") => (RuleGroup::Stable, rules::ruff::rules::UnnecessaryIterableAllocationForFirstElement),

crates/ruff_linter/src/rule_redirects.rs

+1
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,6 @@ static REDIRECTS: Lazy<HashMap<&'static str, &'static str>> = Lazy::new(|| {
9898
("T002", "FIX002"),
9999
("T003", "FIX003"),
100100
("T004", "FIX004"),
101+
("RUF011", "B035"),
101102
])
102103
});

crates/ruff_linter/src/rules/flake8_bugbear/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ mod tests {
3434
#[test_case(Rule::GetAttrWithConstant, Path::new("B009_B010.py"))]
3535
#[test_case(Rule::JumpStatementInFinally, Path::new("B012.py"))]
3636
#[test_case(Rule::LoopVariableOverridesIterator, Path::new("B020.py"))]
37-
#[test_case(Rule::MutableArgumentDefault, Path::new("B006_B008.py"))]
3837
#[test_case(Rule::MutableArgumentDefault, Path::new("B006_1.py"))]
3938
#[test_case(Rule::MutableArgumentDefault, Path::new("B006_2.py"))]
4039
#[test_case(Rule::MutableArgumentDefault, Path::new("B006_3.py"))]
4140
#[test_case(Rule::MutableArgumentDefault, Path::new("B006_4.py"))]
4241
#[test_case(Rule::MutableArgumentDefault, Path::new("B006_5.py"))]
4342
#[test_case(Rule::MutableArgumentDefault, Path::new("B006_6.py"))]
4443
#[test_case(Rule::MutableArgumentDefault, Path::new("B006_7.py"))]
44+
#[test_case(Rule::MutableArgumentDefault, Path::new("B006_B008.py"))]
4545
#[test_case(Rule::NoExplicitStacklevel, Path::new("B028.py"))]
4646
#[test_case(Rule::RaiseLiteral, Path::new("B016.py"))]
4747
#[test_case(Rule::RaiseWithoutFromInsideExcept, Path::new("B904.py"))]
@@ -50,16 +50,17 @@ mod tests {
5050
#[test_case(Rule::ReuseOfGroupbyGenerator, Path::new("B031.py"))]
5151
#[test_case(Rule::SetAttrWithConstant, Path::new("B009_B010.py"))]
5252
#[test_case(Rule::StarArgUnpackingAfterKeywordArg, Path::new("B026.py"))]
53+
#[test_case(Rule::StaticKeyDictComprehension, Path::new("B035.py"))]
5354
#[test_case(Rule::StripWithMultiCharacters, Path::new("B005.py"))]
5455
#[test_case(Rule::UnaryPrefixIncrementDecrement, Path::new("B002.py"))]
5556
#[test_case(Rule::UnintentionalTypeAnnotation, Path::new("B032.py"))]
5657
#[test_case(Rule::UnreliableCallableCheck, Path::new("B004.py"))]
5758
#[test_case(Rule::UnusedLoopControlVariable, Path::new("B007.py"))]
58-
#[test_case(Rule::UselessComparison, Path::new("B015.py"))]
5959
#[test_case(Rule::UselessComparison, Path::new("B015.ipynb"))]
60+
#[test_case(Rule::UselessComparison, Path::new("B015.py"))]
6061
#[test_case(Rule::UselessContextlibSuppress, Path::new("B022.py"))]
61-
#[test_case(Rule::UselessExpression, Path::new("B018.py"))]
6262
#[test_case(Rule::UselessExpression, Path::new("B018.ipynb"))]
63+
#[test_case(Rule::UselessExpression, Path::new("B018.py"))]
6364
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
6465
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
6566
let diagnostics = test_path(

crates/ruff_linter/src/rules/flake8_bugbear/rules/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub(crate) use redundant_tuple_in_exception_handler::*;
2222
pub(crate) use reuse_of_groupby_generator::*;
2323
pub(crate) use setattr_with_constant::*;
2424
pub(crate) use star_arg_unpacking_after_keyword_arg::*;
25+
pub(crate) use static_key_dict_comprehension::*;
2526
pub(crate) use strip_with_multi_characters::*;
2627
pub(crate) use unary_prefix_increment_decrement::*;
2728
pub(crate) use unintentional_type_annotation::*;
@@ -56,6 +57,7 @@ mod redundant_tuple_in_exception_handler;
5657
mod reuse_of_groupby_generator;
5758
mod setattr_with_constant;
5859
mod star_arg_unpacking_after_keyword_arg;
60+
mod static_key_dict_comprehension;
5961
mod strip_with_multi_characters;
6062
mod unary_prefix_increment_decrement;
6163
mod unintentional_type_annotation;
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,90 @@
11
---
2-
source: crates/ruff_linter/src/rules/ruff/mod.rs
2+
source: crates/ruff_linter/src/rules/flake8_bugbear/mod.rs
33
---
4-
RUF011.py:17:2: RUF011 Dictionary comprehension uses static key: `"key"`
4+
B035.py:17:2: B035 Dictionary comprehension uses static key: `"key"`
55
|
66
16 | # Errors
77
17 | {"key": value.upper() for value in data}
8-
| ^^^^^ RUF011
8+
| ^^^^^ B035
99
18 | {True: value.upper() for value in data}
1010
19 | {0: value.upper() for value in data}
1111
|
1212

13-
RUF011.py:18:2: RUF011 Dictionary comprehension uses static key: `True`
13+
B035.py:18:2: B035 Dictionary comprehension uses static key: `True`
1414
|
1515
16 | # Errors
1616
17 | {"key": value.upper() for value in data}
1717
18 | {True: value.upper() for value in data}
18-
| ^^^^ RUF011
18+
| ^^^^ B035
1919
19 | {0: value.upper() for value in data}
2020
20 | {(1, "a"): value.upper() for value in data} # Constant tuple
2121
|
2222

23-
RUF011.py:19:2: RUF011 Dictionary comprehension uses static key: `0`
23+
B035.py:19:2: B035 Dictionary comprehension uses static key: `0`
2424
|
2525
17 | {"key": value.upper() for value in data}
2626
18 | {True: value.upper() for value in data}
2727
19 | {0: value.upper() for value in data}
28-
| ^ RUF011
28+
| ^ B035
2929
20 | {(1, "a"): value.upper() for value in data} # Constant tuple
3030
21 | {constant: value.upper() for value in data}
3131
|
3232

33-
RUF011.py:20:2: RUF011 Dictionary comprehension uses static key: `(1, "a")`
33+
B035.py:20:2: B035 Dictionary comprehension uses static key: `(1, "a")`
3434
|
3535
18 | {True: value.upper() for value in data}
3636
19 | {0: value.upper() for value in data}
3737
20 | {(1, "a"): value.upper() for value in data} # Constant tuple
38-
| ^^^^^^^^ RUF011
38+
| ^^^^^^^^ B035
3939
21 | {constant: value.upper() for value in data}
4040
22 | {constant + constant: value.upper() for value in data}
4141
|
4242

43-
RUF011.py:21:2: RUF011 Dictionary comprehension uses static key: `constant`
43+
B035.py:21:2: B035 Dictionary comprehension uses static key: `constant`
4444
|
4545
19 | {0: value.upper() for value in data}
4646
20 | {(1, "a"): value.upper() for value in data} # Constant tuple
4747
21 | {constant: value.upper() for value in data}
48-
| ^^^^^^^^ RUF011
48+
| ^^^^^^^^ B035
4949
22 | {constant + constant: value.upper() for value in data}
5050
23 | {constant.attribute: value.upper() for value in data}
5151
|
5252

53-
RUF011.py:22:2: RUF011 Dictionary comprehension uses static key: `constant + constant`
53+
B035.py:22:2: B035 Dictionary comprehension uses static key: `constant + constant`
5454
|
5555
20 | {(1, "a"): value.upper() for value in data} # Constant tuple
5656
21 | {constant: value.upper() for value in data}
5757
22 | {constant + constant: value.upper() for value in data}
58-
| ^^^^^^^^^^^^^^^^^^^ RUF011
58+
| ^^^^^^^^^^^^^^^^^^^ B035
5959
23 | {constant.attribute: value.upper() for value in data}
6060
24 | {constant[0]: value.upper() for value in data}
6161
|
6262

63-
RUF011.py:23:2: RUF011 Dictionary comprehension uses static key: `constant.attribute`
63+
B035.py:23:2: B035 Dictionary comprehension uses static key: `constant.attribute`
6464
|
6565
21 | {constant: value.upper() for value in data}
6666
22 | {constant + constant: value.upper() for value in data}
6767
23 | {constant.attribute: value.upper() for value in data}
68-
| ^^^^^^^^^^^^^^^^^^ RUF011
68+
| ^^^^^^^^^^^^^^^^^^ B035
6969
24 | {constant[0]: value.upper() for value in data}
7070
25 | {tokens: token for token in tokens}
7171
|
7272

73-
RUF011.py:24:2: RUF011 Dictionary comprehension uses static key: `constant[0]`
73+
B035.py:24:2: B035 Dictionary comprehension uses static key: `constant[0]`
7474
|
7575
22 | {constant + constant: value.upper() for value in data}
7676
23 | {constant.attribute: value.upper() for value in data}
7777
24 | {constant[0]: value.upper() for value in data}
78-
| ^^^^^^^^^^^ RUF011
78+
| ^^^^^^^^^^^ B035
7979
25 | {tokens: token for token in tokens}
8080
|
8181

82-
RUF011.py:25:2: RUF011 Dictionary comprehension uses static key: `tokens`
82+
B035.py:25:2: B035 Dictionary comprehension uses static key: `tokens`
8383
|
8484
23 | {constant.attribute: value.upper() for value in data}
8585
24 | {constant[0]: value.upper() for value in data}
8686
25 | {tokens: token for token in tokens}
87-
| ^^^^^^ RUF011
87+
| ^^^^^^ B035
8888
|
8989

9090

crates/ruff_linter/src/rules/ruff/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ mod tests {
3030
#[test_case(Rule::MutableClassDefault, Path::new("RUF012.py"))]
3131
#[test_case(Rule::MutableDataclassDefault, Path::new("RUF008.py"))]
3232
#[test_case(Rule::PairwiseOverZipped, Path::new("RUF007.py"))]
33-
#[test_case(Rule::StaticKeyDictComprehension, Path::new("RUF011.py"))]
3433
#[test_case(
3534
Rule::UnnecessaryIterableAllocationForFirstElement,
3635
Path::new("RUF015.py")

crates/ruff_linter/src/rules/ruff/rules/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ pub(crate) use parenthesize_logical_operators::*;
1717
pub(crate) use quadratic_list_summation::*;
1818
pub(crate) use sort_dunder_all::*;
1919
pub(crate) use sort_dunder_slots::*;
20-
pub(crate) use static_key_dict_comprehension::*;
2120
pub(crate) use unnecessary_dict_comprehension_for_iterable::*;
2221
pub(crate) use unnecessary_iterable_allocation_for_first_element::*;
2322
pub(crate) use unnecessary_key_check::*;
@@ -44,7 +43,6 @@ mod parenthesize_logical_operators;
4443
mod sequence_sorting;
4544
mod sort_dunder_all;
4645
mod sort_dunder_slots;
47-
mod static_key_dict_comprehension;
4846
mod unnecessary_dict_comprehension_for_iterable;
4947
mod unnecessary_iterable_allocation_for_first_element;
5048
mod unnecessary_key_check;

ruff.schema.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)