-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add new message called duplicate-value #5928
Conversation
This commit adds some new functionality which checks for duplicate values inside sets. For that reason, we create a new message called duplicate-value.
This commit adds new functional tests for the new message duplicate-value.
Pull Request Test Coverage Report for Build 2079079540
💛 - Coveralls |
Tested locally; works! Thanks @ksaketou! |
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.
This looks pretty good. I think some additions would pick up many more common cases.
Also surfacing the failure on the Pylint presubmit: https://github.com/PyCQA/pylint/runs/5571708705?check_suite_focus=true
************* Module pylint.checkers.format
pylint/checkers/format.py:721:23: W0130: Duplicate value '\x0b' in set (duplicate-value)
pylint/checkers/format.py:721:23: W0130: Duplicate value '\x0c' in set (duplicate-value)
Which is this:
unsplit_ends = {
"\v",
"\x0b",
"\f",
"\x0c",
"\x1c",
"\x1d",
"\x1e",
"\x85",
"\u2028",
"\u2029",
}
https://stackoverflow.com/questions/26184100/how-does-v-differ-from-x0b-or-x0c
It seems \v == \x0b
and \x0c == \f
. I think we remove duplicates in our code. It can benefit clarity to explicitly write both synonym escape sequences, but that clarification is better in a comment.
So regarding that case should we modify |
Let's keep the unicode one and add |
This commit changes the unsplit_ends set by keeping only the unicode sequences and noting their synonyms in comments in order to avoid duplicate-value error triggering.
Hi @ksaketou, We have been working on the documentation of the messages that pylint emits. As this PR adds a new message could I ask you to rebase on |
doc/whatsnew/2.13.rst
Outdated
@@ -66,6 +66,10 @@ New checkers | |||
|
|||
Closes #5670 | |||
|
|||
* Added new message called ``duplicate-value`` which identifies duplicate values inside sets. |
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.
This should be moved to 2.14
.
pylint/checkers/base.py
Outdated
else: | ||
continue | ||
if value in values: | ||
self.add_message("duplicate-value", node=node, args=value) |
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.
self.add_message("duplicate-value", node=node, args=value) | |
self.add_message("duplicate-value", node=node, args=value, confidence=HIGH) |
You'll probably need to import that.
Hello @DanielNoord @Pierre-Sassoulas , sorry for the late reply. Unfortunately, I don't currently have enough time to expand the checker's functionality (#5928 (comment)) . However, I can work on the documentation and the other minor suggested changes above during the following days if that's okay. |
Quick question, should I add the documentation on a separate PR? @DanielNoord |
No adding here is fine. It shouldn't increase the review burden significantly. |
Did the refactoring affect the test execution at all? because I get errors regarding the When I add the |
No it should be the same behavior, only less code per file.
Yes, I checked the diff it was in the BasicChecker class.
I had the same issue, I just fixed it in #6054, it should work if you rebase on latest main |
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.
Almost there! Most of this looks good to go in my opinion!
@@ -0,0 +1,2 @@ | |||
This error message is emitted when a set contains the same value two or more times. |
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.
Information like this should probably included in the message description in its declaration.
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.
Only need to move this to pylint/checkers/base/basic_checker.py
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, good job @ksaketou !
Co-authored-by: Daniël van Noord <13665637+DanielNoord@users.noreply.github.com>
@@ -0,0 +1,2 @@ | |||
This error message is emitted when a set contains the same value two or more times. |
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.
Only need to move this to pylint/checkers/base/basic_checker.py
Type of Changes
Description
This PR creates a new error message called
duplicate-value
which identifies duplicate values inside sets.Its functionality is similar to the
duplicate-key
message which finds duplicate values in dictionaries.Closes #5880