-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add configuration option exclude-too-few-public-methods
#5191
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 configuration option exclude-too-few-public-methods
#5191
Conversation
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.
@Pierre-Sassoulas et al - here's what I've come up with so far. Looking forward to your review!
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 like where this is going! Would be good to see an issue with (relatively) many upvotes get fixed!
I'm happy to assist with any of the changes I suggested!
Pull Request Test Coverage Report for Build 1383302578
💛 - Coveralls |
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.
We will really need to use get_global_option
here to make this option and its implementation future-proof.
A good example of how to do this can be found here:
https://github.com/PyCQA/pylint/blob/80205dc813e17fc416e56bace982c971a10553fb/pylint/checkers/imports.py#L477
get_global_option
is used to create a private attribute for which we do know the type. We do this in the open
method because then it is called as soon as the checker class is "opened".
We get type inference because we have "overloaded" get_global_option
here:
https://github.com/PyCQA/pylint/blob/80205dc813e17fc416e56bace982c971a10553fb/pylint/utils/utils.py#L232-L236
You will notice currently there is no GLOBAL_OPTION_PATTERN_LIST
at the top of the file.
Furthermore, in T_GlobalOptionReturnTypes
List[Pattern[str]]
is not included. https://github.com/PyCQA/pylint/blob/80205dc813e17fc416e56bace982c971a10553fb/pylint/utils/utils.py#L67-L69
So to make this work and prepare it for a type-proof future we will need to do three things:
- Add
get_global_option()
to theopen
method of the class to create a private attribute and use that attribute in the checker - Add a
GLOBAL_OPTION_PATTERN_LIST
variable to theutils/utils.py
file - Add the return type of
GLOBAL_OPTION_PATTERN_LIST
options (which isList[Pattern[str]]
toT_GlobalOptionReturnTypes
- Add
GLOBAL_OPTION_PATTERN_LIST
toGLOBAL_OPTION_NAMES
- Create a new overload based on
GLOBAL_OPTION_PATTERN_LIST
and its return type
I know this might be a little more than you initially signed up for, so please let me know if I can help with anything or if you would like me to show how this should be done! As I said, I'm happy to help and think this is a valuable addition to pylint
!
@miketheman Just to let you know, I actually had to create a It's located in this PR: DanielNoord#20 However, I need #5195 to be merged before I can create a PR for this change. |
@DanielNoord Thanks for the guidance! I saw the dependent PR get merged, so am in no rush. I think the code works just fine, and no mypy errors are currently emitted, so I'm not clear how to test this if/when I make that change? |
I'm going to go over some of the review comments I got on some of my own existing PRs and then submit the PR which I talked about. I will split the commits so you can follow along and see what you would need to add once mine has been merged. You could also duplicate those commits here and then we would just resolve merge conflicts once both have been approved! |
I've cleaned up the PR and the commit history. You can look at it here: To make your new option work you will need to add Next comes the slightly more difficult task of adding unittests for the new option. You can look at what I did here: You can wait for my PR to be merged or copy the work from 8a8e7a5 and you should be able to add the test yourself. That way you don't need to wait for me and we can just solve possible merge conflicts when the time comes. Hopefully this explains it well enough, but please let me know if you have any further questions. I know this is all quite a bit of extra work for a simple new option, without any clear previous examples of how to do this. We need to improve our testing of setting configs with tests so this serves as a good learning case for us as well! |
@miketheman My PR has been merged, so if you merge |
I'll revisit soon! |
19b92aa
to
f47e156
Compare
@DanielNoord I was confused about the test failure - I don't see that locally, and looks like I had misnamed a test output file. I've renamed the file in the most recent commit. |
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 good! Perfect use of the get_global_option
util :)
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.
Sorry for nitpicking so much on the option description. I believe this is the most true to what it actually does.
The failing tests seem to be a case of adding some disables to the functional test file!
I'm not sure I understand this - as the test seems to only fail on Windows and pypy3 - is it possible those envs don't have the yaml/toml packages included? |
I guess so. Can we change the tests to not require an import? Just by inheriting from another class within the same file and then adding that classes name to the regex? |
Sure, I can do that. But I was really trying to embody the capability of the original intent - excluding an imported module's inherited class - is there one from the Python stdlib you think would work better? |
I can't think of one immediately. Perhaps @Pierre-Sassoulas has some good suggestions here! |
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 job 👍
Before changing anything about the code, make sure we have a unit test that covers the basic behavior. Signed-off-by: Mike Fiedler <[email protected]>
Instead of adding specific packages to an in-code exclusion list, add a configuration value that allows the end user to set values for packages/modules and classes to exclude from evaluation. TODO: needs documentation and examples Signed-off-by: Mike Fiedler <[email protected]>
Signed-off-by: Mike Fiedler <[email protected]>
Signed-off-by: Mike Fiedler <[email protected]>
Also update the help string. Signed-off-by: Mike Fiedler <[email protected]>
Signed-off-by: Mike Fiedler <[email protected]>
Signed-off-by: Mike Fiedler <[email protected]>
Signed-off-by: Mike Fiedler <[email protected]>
Signed-off-by: Mike Fiedler <[email protected]>
Signed-off-by: Mike Fiedler <[email protected]>
Signed-off-by: Mike Fiedler <[email protected]>
Signed-off-by: Mike Fiedler <[email protected]>
Co-authored-by: Daniël van Noord <[email protected]>
for more information, see https://pre-commit.ci
Signed-off-by: Mike Fiedler <[email protected]>
Using a stdlib of json ought to be future-proof enough to traverse platforms. Signed-off-by: Mike Fiedler <[email protected]>
Co-authored-by: Daniël van Noord <[email protected]>
7f5af68
to
bbfbffa
Compare
for more information, see https://pre-commit.ci
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.
Good choice!
Thanks for your work @miketheman! This is a really nice contribution and good and concise PR :)
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, very nice evolution !
doc/whatsnew/<current release.rst>
.Type of Changes
Description
Add feature to exclude classes from too-few-public-methods
Instead of adding specific packages to an in-code exclusion list,
add a configuration value that allows the end user to set values
for packages/modules and classes to exclude from evaluation.
Closes #3370