Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Declare function mutators with inline comment #8332
Declare function mutators with inline comment #8332
Changes from 2 commits
7f4b21f
6af39bb
63f0747
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Should not be an error imo, but I also think it should not be a message either. Or at least some prior design is in order. Isn't the goal to auto-populate the function-mutator option based on comment by the lib authors directly in their code ? I like this the end goal, but this would be something new in pylint, with the expected associated maintenance cost. Maybe a hack like this is using the existing message control framework is good, maybe it would be simpler to suggest to add a value to
function-mutator
manually in the message ? This is not something that is done often, even less so if we do configuration template, this way it's done once per library and become very reasonable.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.
Agreed. I just needed a simple way to hook into the inline comment system. It feels like this comment is meant to "mark" decorator definitions as being signature-mutators. Thus, a more ideal comment might read:
I'm not really sure how to do this though.
If I understand this correctly you're suggesting that, if PyLint discovers invalid arguments, and the function in question has a decorator, that PyLint report the error, but also recommend adding the decorator to the
signature-mutators
list manually.If so, I think this could be problematic. Signature mutating decorators are a fairly advanced concept and users might add decorators to that list, on the recommendation of this message without fully understanding what they're doing just to make the error go away. I foresee bug reports to PyLint from people who have done this and are getting false negatives for invalid function calls.
Further, as a lib author, even with this addition to the error message, I'm still probably going to get bug reports from people complaining about this PyLint false positive because, they either don't understand the suggestion, or because the find it inconvenient. Also, if I ever decide to refactor and change the name of the offending decorator, my users' PyLint configs will need to be updated.
Ultimately, a message would be a mild improvement in some situations and possibly a detriment in others.
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 don't have any useful suggestions on implementation (sorry), but just to add a bit of weight to the cause... I'm coming from a completely unrelated project from @rmorshea and was independently looking for a solution to the exact same problem. I agree with everything he's said here. I understand there's no other patterns like this in pylint at the moment, but it would be much, much more convenient if this
disable
could be somehow specified at point of function definition rather than at point of call. I'm developing a package that defines decorated functions that will unfortunately raiseunexpected-keyword-arg
when called. At the moment there's a burden on every user that uses pylint and calls my function to update their config; it would be much more maintainable if the burden fell on the package author instead.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.
Right. though I can see most library maintainers refusing to add it because it's not their job to fix pylint's bad code comprehension (What if all linter needed something like that ? It becomes unreasonable pretty fast, and add a coupling I would not want myself). It then become the same situation than previously for users but we now also have to maintain the more complicated system on top of it. Also wouldn't it raise a useless-suppression in the original lib code if we don't add a new keyword ? I'm not sure of the performance implication of adding a new pylint keyword in the message control (
mark
ordisable-in-calling-code
) instead ofdisable
/enable
). This is something we need to take into account because this might have a big impact (all comments are parsed).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.
Perhaps rather than creating a new pattern, should pylint consider disabling this error on all decorated functions?
In theory, this change should only be a temporary until a method is determined on how to properly parse and analyze these functions.
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 have
function-mutator
to handle this. Some functions are just too dynamic and cannot reasonably be parsed but that's not all functions and pylint would be crippled if we just refuse to analyses all decorators. Maybe we could suggest to populatefunction_mutator
only on decorator we're not sure about. Maybe we can add more default values in function-mutator, for well known libs.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.
Brutal opinion here: If I need to start populating a list of decorated functions within pylintrc, I'd likely remove pylint from my workflow instead.
At least to me,
function_mutator
is too cumbersome to be worth considering.