-
-
Notifications
You must be signed in to change notification settings - Fork 626
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
Fix F841 - Unused variables #16877
Fix F841 - Unused variables #16877
Conversation
If there are any remaning variables, could you please underscore prefix them and remove the noqa?
If this is an issue that can be isolated pretty easily, it might be worthwhile to report this to Ruff. |
I have removed the last one in commit f2a7f74. Even if it had been introduced on purpose (cc @josephsl), there was no need to define an unused variable in this unit test.
I am just realizing that Ruff ignores private variables(i.e. prefixed with underscore) by default, what Flake8 probably did not do. Why is there such default in Ruff? If we stick with this default configuration, we will miss unused private variables (prefixed with underscore), and thus miss any potential issue. |
I believe they only ignored them for F841. We could fix this by overriding dummy-variable-rgx |
Yes, that's what I was meaning.
Of course. But before overriding the default rule, in the first place, I would be curious to know the reason why they ignore private variables. |
I guess this is by design/convension. For example if you want to loop ten times without needing the iteration variable, you can do |
Hi, Ah, the nonexistent Windows version variable... I did it to improve readability. If assigning a dedicated variable impedes readablity, then I guess we should remove it but with justifications. Thanks. |
I have finally removed the unused variable (see commit f2a7f74).
@josephsl, which extra explanation do you expect? Something more in the test's code (other comment, etc.)? Or another explanation comment on this page? Please be more specific if needed. Thanks. Or The code for this |
Setting:
I get only one more issue: Though, I do not know this file at all, nor how to test it. And I am not able to @seanbudd, without any other hint, I am tempted to leave this file as is, to keep this potential history, due to impossibility of testing. Or maybe should I use Also @seanbudd, do you think that I should modify I'll switch this PR to Ready to get the required answered. |
WalkthroughThe changes primarily involve code simplifications and optimizations by removing unused variables, streamlining function calls, and adjusting control flows within various modules. These modifications enhance code readability and maintainability without introducing new features or altering existing functionality. Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Outside diff range, codebase verification and nitpick comments (1)
source/appModules/outlook.py (1)
Line range hint
210-210
:
Remove unused variablestates
.The variable
states
is declared but not used in the method. Removing it improves code readability and maintainability.- states = self.states
I think it would be best to leave this. It might be worth adding more thorough comments noting that the second definition is the one used, however we may want to migrate functionality from the first definition.
You may need to add .git-blame-ignore-revs in your local git config, or use the CLI flag
I think there are probably cases where we want to follow the magic rules for a dummy variable. |
@CyrilleB79 - do you plan to continue this? |
@seanbudd, finally, it is ready again. |
Link to issue number:
None
Summary of the issue:
NVDA's code contains unused variables, with specific directives for the linter to ignore them (
#noqa F841
)Description of user facing changes
There is no more
#noqa F841
directive in the code.Description of development approach
Searched for
F841
in the code and solved the situations:NVDAObjects/window/_msOfficeChart.py
)winConsoleHandler.py
, renamedconsoleEventHookHandles
toconsoleWinEventHookHandles
since the goal clearly seems to empty the list.Also used a Flake8 report on an older version of NVDA to identify other
F841
issues. This way, I have been able to find undefined private variables (i.e. starting with underscore) that are not caught by Ruff's default rule.Testing strategy:
Manual checks:
Known issues with pull request:
In
WordDocumentTextInfo._normalizeFormatField
, the RUFF linter did not complain that_startOffset
and_endOffset
were not used, even if there is no#noqa F841
directives on these lines. It's because Ruff's default config exclude private variables (i.e. starting with underscore) from unused variable checking.I wonder why there is such default config for Ruff and if excluding private variables from the check may prevent us from finding potential unused variable and related issues.
Code Review Checklist:
Summary by CodeRabbit
Bug Fixes
Refactor
Tests
test_winVersion.py
by removing unused variable assignments for clarity and maintainability.