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

Make used-before-assignment consider classes in method annotation and defaults #5184

Merged
merged 11 commits into from
Oct 23, 2021

Conversation

DanielNoord
Copy link
Collaborator

  • Add yourself to CONTRIBUTORS if you are a new contributor.
  • Add a ChangeLog entry describing what your PR does.
  • If it's a new feature, or an important bug fix, add a What's New entry in
    doc/whatsnew/<current release.rst>.
  • Write a good description on what the PR does.

Type of Changes

Type
🐛 Bug fix

Description

This closes #3771

This was originally filed as undefined-variable but I think it should actually be used-before-assignment. I'm happy to change it to undefined-variable instead.

@DanielNoord DanielNoord added the False Negative 🦋 No message is emitted but something is wrong with the code label Oct 18, 2021
@DanielNoord DanielNoord added this to the 2.12.0 milestone Oct 18, 2021
@coveralls
Copy link

coveralls commented Oct 18, 2021

Pull Request Test Coverage Report for Build 1373941910

  • 20 of 20 (100.0%) changed or added relevant lines in 1 file are covered.
  • 51 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.008%) to 93.259%

Files with Coverage Reduction New Missed Lines %
pylint/checkers/classes.py 51 94.57%
Totals Coverage Status
Change from base Build 1357983533: 0.008%
Covered Lines: 13655
Relevant Lines: 14642

💛 - Coveralls

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.

Looks good ! I have an open question about the existing code we extended :)

self.add_message(
"used-before-assignment", node=node, args=node.name
)
break
Copy link
Member

Choose a reason for hiding this comment

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

This for loop spanning 200 lines asks for a refactor. Maybe you have an idea on how we could simplify this ? I'm not saying we should refactor it now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's awful. I don't even understand half of what it is doing and variable names such as maybee0601 really don't help.
One of the problems is that it is doing something with consuming variables in different scopes which I don't really understand. We can probably investigate this at some point.

I'm just going through the open issues for undefined-variable as it seemed like a good addition to 2.12 to improve that checker. For now I tend to add new single-purpose methods and elifs, that should help refactoring later.

Copy link
Member

Choose a reason for hiding this comment

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

It's awful. I

Glad to see I'm not the only one 😄 Yes the consuming + continue + break makes the refactor quite hard. Also it's really hard to understand what's happening, good job fixing issues despite that 🎉

Copy link
Member

Choose a reason for hiding this comment

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

The complete visit_name function has just gotten too complicated. Not sure we'll ever be able to fix it though. It's really easy to break things if something goes wrong during the refactor. Lot's of testing needed before then.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is also because the way consumption works is quite difficult to understand. It took me a while to understand how the actual looping over scopes works. If we were to improve that (or it explanation) I think we would already be in a much better place.

@DanielNoord
Copy link
Collaborator Author

DanielNoord commented Oct 18, 2021

@Pierre-Sassoulas I just updated the method's name and docstring because I noticed they basically only referred to the checker for annotation and not for defaults. Should be good to go still!

Edit: Github Actions failed on downloading python 3.10. Going to rerun!

Edit2: Something wrong I guess.. Nothing on https://www.githubstatus.com yet.

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.

I don't know what's wrong with GitHub, let's relaunch the ci later.

@DanielNoord
Copy link
Collaborator Author

@Pierre-Sassoulas you approved this PR before Marc's review. I don't want to immediately tag him or ask for his re-review as not to spam him, but do you want him to take another look or can we merge this now?

@cdce8p
Copy link
Member

cdce8p commented Oct 21, 2021

@DanielNoord I do plan on reviewing this shortly. Haven't had much time these past few days though. Sorry for the delay.

@cdce8p cdce8p self-requested a review October 21, 2021 22:05
@DanielNoord
Copy link
Collaborator Author

@cdce8p No worries (and certainly no need to say sorry for any "delay")! I know you had requested some other reviews from yourself on some other PRs so I didn't want to unnecessarily bother you. I don't expect all maintainers/collaborators to be as active @Pierre-Sassoulas, we're all stil volunteers after all 😄

@cdce8p
Copy link
Member

cdce8p commented Oct 21, 2021

It's certainly interesting to keep up with you guys sometimes 😄

Copy link
Member

@cdce8p cdce8p left a comment

Choose a reason for hiding this comment

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

I think both functions should be combined, especially since there needs to be some more logic for it. Left a comment with suggestions on how to handle it.

pylint/checkers/variables.py Outdated Show resolved Hide resolved
pylint/checkers/variables.py Outdated Show resolved Hide resolved
pylint/checkers/variables.py Outdated Show resolved Hide resolved
Copy link
Member

@cdce8p cdce8p left a comment

Choose a reason for hiding this comment

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

Some last comments

pylint/checkers/variables.py Outdated Show resolved Hide resolved
pylint/checkers/variables.py Outdated Show resolved Hide resolved
pylint/checkers/variables.py Show resolved Hide resolved
DanielNoord and others added 2 commits October 22, 2021 17:58
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
pylint/checkers/variables.py Outdated Show resolved Hide resolved
pylint/checkers/variables.py Outdated Show resolved Hide resolved
pylint/checkers/variables.py Outdated Show resolved Hide resolved
pylint/checkers/variables.py Outdated Show resolved Hide resolved
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Copy link
Member

@cdce8p cdce8p left a comment

Choose a reason for hiding this comment

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

Looks good! Thanks, @DanielNoord 🐬

@DanielNoord DanielNoord merged commit 91f525f into pylint-dev:main Oct 23, 2021
@DanielNoord DanielNoord deleted the undefined-variable branch October 23, 2021 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Negative 🦋 No message is emitted but something is wrong with the code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pylint fails to detect NameError from type hint
4 participants