-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix: avoid false positive when module-level names match class-level names #10723
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: avoid false positive when module-level names match class-level names #10723
Conversation
1a5cff6 to
178bdc8
Compare
Pierre-Sassoulas
left a comment
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.
Great first PR, thank you. Could you add a functional test in tests/functional to check it automatically, please ?
178bdc8 to
8f658a3
Compare
|
Thanks for the review @Pierre-Sassoulas, just added it! |
This comment has been minimized.
This comment has been minimized.
Pierre-Sassoulas
left a comment
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.
Made a suggestion to match the example from the issue, let me know what you think. Changed Input to input, maybe it was the reason for the second invalid-name (shouldn't have been pascal case ?)
| @@ -0,0 +1,8 @@ | |||
| """Test module-level constants with class attribute same name""" | |||
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.
| """Test module-level constants with class attribute same name""" | |
| """Test module-level constants with class attribute same name | |
| Regression test for #10719. | |
| """ |
| class MyClass: | ||
| MY_CONST = 10 |
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.
| class MyClass: | |
| MY_CONST = 10 | |
| class MyClass: | |
| MY_CONST = 10 | |
| class Theme: | |
| INPUT = ">>> " | |
| INPUT = Theme() | |
| input = Theme() | |
| OUTPUT = Theme() | |
| output = Theme() |
8f658a3 to
6459607
Compare
This comment has been minimized.
This comment has been minimized.
|
There's lot of changes from the primer which is worrying. Also the tests are not passing you can launch them with pytest locally, see https://pylint.readthedocs.io/en/stable/development_guide/contributor_guide/tests/launching_test.html#pytest |
23c90df to
284a794
Compare
jacobtylerwalls
left a comment
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.
Thanks! I checked a few of the primer changes, and they look good. Does anything look concerning to you?
pylint/checkers/utils.py
Outdated
| if isinstance(a, (nodes.ClassDef, nodes.FunctionDef)): | ||
| if a.parent and a.parent.scope() == node_scope: | ||
| return True | ||
| elif a.scope() == node_scope: |
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.
I think is is usually used for specific node comparisons.
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.
still applies
284a794 to
dc44856
Compare
jacobtylerwalls
left a comment
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.
Looking good!
dc44856 to
47b22a7
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #10723 +/- ##
=======================================
Coverage ? 95.98%
=======================================
Files ? 176
Lines ? 19559
Branches ? 0
=======================================
Hits ? 18774
Misses ? 785
Partials ? 0
🚀 New features to boost your workflow:
|
This comment has been minimized.
This comment has been minimized.
Pierre-Sassoulas
left a comment
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.
LGTM, but would you mind covering the missing lines with automated tests, please ?
47b22a7 to
17828a6
Compare
This comment has been minimized.
This comment has been minimized.
…ames - Add scope comparision to avoid module-level constants to be incorrectly classified as variables when a class-level attribute with the same name exists Closes pylint-dev#10719
17828a6 to
d77f097
Compare
|
Thank you, great PR ! |
…vel names match class-level names (#10753) fix: avoid false positive when module-level names match class-level names (#10723) Add scope comparision to avoid module-level constants to be incorrectly classified as variables when a class-level attribute with the same name exists Closes #10719 (cherry picked from commit e55e830) Co-authored-by: Joao Faria <joaovitorfaria.dev@gmail.com>
Description
Fixes a false positive where module-level constants were incorrectly classified as variables when a class-level attribute with the same name exists. I added a scope check so now when we check for reassignments, we make sure we only look at nodes within the same scope
Closes #10719