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

An F841 error shows up only when enabling the preview mode #9881

Closed
suhaibmujahid opened this issue Feb 7, 2024 · 3 comments
Closed

An F841 error shows up only when enabling the preview mode #9881

suhaibmujahid opened this issue Feb 7, 2024 · 3 comments

Comments

@suhaibmujahid
Copy link

Currently, F841 is not in preview. However, it will catch the following unused variable (i.e., secund) only when the preview mode is enabled.

Minimal code snippet

class Foo:
    def bar(self):
        return 1, 2

    def main(self):
        first, secund = self.bar()

        print(first)

Invoked commands

The following command shows no errors:

ruff ruff_F841.py --isolated

While enabling the preview shows an F841 error:

ruff ruff_F841.py --isolated --preview
ruff_F841.py:6:16: F841 Local variable `secund` is assigned to but never used
  |
5 |     def main(self):
6 |         first, secund = self.bar()
  |                ^^^^^^ F841
7 | 
8 |         print(first)
  |
  = help: Remove assignment to unused variable `secund`

Found 1 error.
No fixes available (1 hidden fix can be enabled with the `--unsafe-fixes` option).

The current Ruff settings

Just the defaults with no customization

The current Ruff version

ruff 0.2.1
@charliermarsh
Copy link
Member

Hey sorry -- this is intended and it's covered in the rule documentation: https://docs.astral.sh/ruff/rules/unused-variable/. Right now, we don't lint against unused variables in tuples if at least one of them is used, but we're considering changing that behavior (hence why the revised logic is present in preview).

@charliermarsh
Copy link
Member

(For completeness, there's also a separate issue here discussing whether / how to stabilize that change: #8884.)

@suhaibmujahid
Copy link
Author

suhaibmujahid commented Feb 7, 2024

I appreciate the clarification.

BTW, this behaviour does not respect the explicit-preview-rules option. When having explicit-preview-rules = true, I was expecting to not have any preview behaviour unless the rule is explicitly selected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants