Skip to content

Commit 1de9dac

Browse files
committed
Stabilize unused-unpacked-variable (RUF059) (#20233)
The tests looked good. For the docs, I added a `## See also` section pointing to the closely-related F841 (unused-variable) and the corresponding section to F841 pointing back to RUF059. It seems like you'd probably want both of these active or at least to know about the other when reading the docs.
1 parent 1cf6c24 commit 1de9dac

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

crates/ruff_linter/src/codes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
10461046
(Ruff, "056") => (RuleGroup::Preview, rules::ruff::rules::FalsyDictGetFallback),
10471047
(Ruff, "057") => (RuleGroup::Stable, rules::ruff::rules::UnnecessaryRound),
10481048
(Ruff, "058") => (RuleGroup::Stable, rules::ruff::rules::StarmapZip),
1049-
(Ruff, "059") => (RuleGroup::Preview, rules::ruff::rules::UnusedUnpackedVariable),
1049+
(Ruff, "059") => (RuleGroup::Stable, rules::ruff::rules::UnusedUnpackedVariable),
10501050
(Ruff, "060") => (RuleGroup::Preview, rules::ruff::rules::InEmptyCollection),
10511051
(Ruff, "061") => (RuleGroup::Preview, rules::ruff::rules::LegacyFormPytestRaises),
10521052
(Ruff, "063") => (RuleGroup::Preview, rules::ruff::rules::AccessAnnotationsFromClassDict),

crates/ruff_linter/src/message/snapshots/ruff_linter__message__sarif__tests__results.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ expression: value
119119
},
120120
{
121121
"fullDescription": {
122-
"text": "## What it does\nChecks for the presence of unused variables in function scopes.\n\n## Why is this bad?\nA variable that is defined but not used is likely a mistake, and should\nbe removed to avoid confusion.\n\nIf a variable is intentionally defined-but-not-used, it should be\nprefixed with an underscore, or some other value that adheres to the\n[`lint.dummy-variable-rgx`] pattern.\n\n## Example\n```python\ndef foo():\n x = 1\n y = 2\n return x\n```\n\nUse instead:\n```python\ndef foo():\n x = 1\n return x\n```\n\n## Fix safety\n\nThis rule's fix is marked as unsafe because removing an unused variable assignment may\ndelete comments that are attached to the assignment.\n\n## Options\n- `lint.dummy-variable-rgx`\n"
122+
"text": "## What it does\nChecks for the presence of unused variables in function scopes.\n\n## Why is this bad?\nA variable that is defined but not used is likely a mistake, and should\nbe removed to avoid confusion.\n\nIf a variable is intentionally defined-but-not-used, it should be\nprefixed with an underscore, or some other value that adheres to the\n[`lint.dummy-variable-rgx`] pattern.\n\n## Example\n```python\ndef foo():\n x = 1\n y = 2\n return x\n```\n\nUse instead:\n```python\ndef foo():\n x = 1\n return x\n```\n\n## Fix safety\n\nThis rule's fix is marked as unsafe because removing an unused variable assignment may\ndelete comments that are attached to the assignment.\n\n## See also\n\nThis rule does not apply to bindings in unpacked assignments (e.g. `x, y = 1, 2`). See\n[`unused-unpacked-variable`][RUF059] for this case.\n\n## Options\n- `lint.dummy-variable-rgx`\n\n[RUF059]: https://docs.astral.sh/ruff/rules/unused-unpacked-variable/\n"
123123
},
124124
"help": {
125125
"text": "Local variable `{name}` is assigned to but never used"

crates/ruff_linter/src/rules/pyflakes/rules/unused_variable.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,15 @@ use crate::{Edit, Fix, FixAvailability, Violation};
4343
/// This rule's fix is marked as unsafe because removing an unused variable assignment may
4444
/// delete comments that are attached to the assignment.
4545
///
46+
/// ## See also
47+
///
48+
/// This rule does not apply to bindings in unpacked assignments (e.g. `x, y = 1, 2`). See
49+
/// [`unused-unpacked-variable`][RUF059] for this case.
50+
///
4651
/// ## Options
4752
/// - `lint.dummy-variable-rgx`
53+
///
54+
/// [RUF059]: https://docs.astral.sh/ruff/rules/unused-unpacked-variable/
4855
#[derive(ViolationMetadata)]
4956
pub(crate) struct UnusedVariable {
5057
pub name: String,

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,15 @@ use crate::{Edit, Fix, FixAvailability, Violation};
3636
/// return x
3737
/// ```
3838
///
39+
/// ## See also
40+
///
41+
/// This rule applies only to unpacked assignments. For regular assignments, see
42+
/// [`unused-variable`][F841].
43+
///
3944
/// ## Options
4045
/// - `lint.dummy-variable-rgx`
46+
///
47+
/// [F841]: https://docs.astral.sh/ruff/rules/unused-variable/
4148
#[derive(ViolationMetadata)]
4249
pub(crate) struct UnusedUnpackedVariable {
4350
pub name: String,

0 commit comments

Comments
 (0)