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

Fix possibly-used-before-assignment issues in pylint codebase #9644

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

aatle
Copy link
Contributor

@aatle aatle commented May 17, 2024

Type of Changes

Type
βœ“ πŸ”¨ Refactoring

Description

This new check was disabled for pylint itself. Enabled, it gives 7 errors in 5 files in the codebase.

Enables the check for pylint and fixes the 7 errors.

Three of the errors were fixed by adding an else clause that explicitly raised ValueError for bad values instead of letting the code possibly run into an UnboundLocalError.
Two errors were caused by checking a bool flag (that never changes) in two separate conditionals: one where the variable set, the other where it was used.
The last two errors were caused by relying on a separate flag when setting a variable, for the conditional that uses the variable.

Closes #9637

Note: this is my first contribution to open source, so feedback and advice are welcome

Copy link

codecov bot commented May 17, 2024

Codecov Report

Attention: Patch coverage is 86.95652% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 95.84%. Comparing base (978981d) to head (165cfdd).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #9644      +/-   ##
==========================================
- Coverage   95.86%   95.84%   -0.02%     
==========================================
  Files         174      174              
  Lines       18907    18898       -9     
==========================================
- Hits        18125    18113      -12     
- Misses        782      785       +3     
Files Coverage Ξ”
...heckers/refactoring/implicit_booleaness_checker.py 100.00% <100.00%> (ΓΈ)
pylint/checkers/similar.py 96.23% <100.00%> (-0.06%) ⬇️
pylint/checkers/__init__.py 90.00% <0.00%> (-3.11%) ⬇️
pylint/checkers/typecheck.py 96.51% <66.66%> (-0.11%) ⬇️
pylint/testutils/_primer/primer.py 94.33% <0.00%> (-1.82%) ⬇️

This comment has been minimized.

@Pierre-Sassoulas Pierre-Sassoulas added Maintenance Discussion or action around maintaining pylint or the dev workflow Skip news πŸ”‡ This change does not require a changelog entry labels May 18, 2024
@Pierre-Sassoulas
Copy link
Member

Hey @aatle thank you for your contribution ! It would be better if each commit was passing the tests (i.e. first commit activates the check and disable warnings locally, then each following commit remove a local disable and fix the associated warning). That way we can look at each individual commit during review and partially revert or drop them later. You can open a merge request for each too if necessary. (Sometime it's nice to move what's consensual out of the way.)

This comment has been minimized.

Copy link
Contributor

πŸ€– According to the primer, this change has no effect on the checked open source code. πŸ€–πŸŽ‰

This comment was generated for commit 165cfdd

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please open a first merge request with bea0aae and the new local disable first and the commit with no value error raised like 9e8d43f ? I think those change are mergeable as is This will make you trusted enough to run the CI without our approval and ease both of our lives and also make the following review smaller :)

Comment on lines +112 to +113
else:
raise ValueError(stat_type)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd rather have default value like

      [
                ("convention", "NC"),
                ("refactor", "NC"),
                ("warning", "NC"),
                ("error", "NC"),
            ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Maintenance Discussion or action around maintaining pylint or the dev workflow Skip news πŸ”‡ This change does not require a changelog entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix possibly-used-before-assignment issues in our own codebase
2 participants