-
-
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
Do not lint ignored file on stdin #7220
Do not lint ignored file on stdin #7220
Conversation
Previously pylint would lint a file passed on stdin even if the user meant to ignore the file. This commit fixes that issue.
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.
Thank you, the test is simple and efficient !
I think we also need to cleanup the "old faulty way of doing it" if filtering just before check file make more sense. In particular for multiprocessing we probably want to do the filtering before forking (?)
pylint/lint/pylinter.py
Outdated
@@ -641,6 +641,13 @@ def check(self, files_or_modules: Sequence[str] | str) -> None: | |||
|
|||
filepath = files_or_modules[0] | |||
with fix_import_path(files_or_modules): | |||
if _is_ignored_file( |
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.
Shouldn't we also remove the previous place where we where ignoring some file ? If this is the right place then we don't need to check in the other places it was checked ?
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 am not completely sure I understand. The check was not present previously in this if statement. Do you mean that we should put the check before the second if statement and remove it from all the subsequent if statements?
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're already filtering files somewhere when they are not from stdin, I think there's a kind of refactor to do there so we filter files at the right place and so it's efficient (done only once per run, possibly when using multiprocessing). I would start by checking where _is_ignored_file
is used.
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.
That function is used in two places:
It seems like the expand_modules
function is the place where the filtering of ignored files is meant to take place and the use of _is_ignored_file
while discovering is more of a "hack". Unfortunately expand_modules
does not get called when linting from standard input. Furthermore expand_modules
seems to do two things:
- Expand modules
- Filter ignored files
It might be a good idea to entangle these two concerns. In any case I don't see a way to only filter once. Before expand_modules
you want to filter once to avoid unnecessarily processing any ignored files but you can not filter everything at this stage because you do not have filepaths for the modules yet. Therefore you want to filter again after you have those.
So I am not sure how to proceed from 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.
Thank you for checking this.
It might be a good idea to entangle these two concerns. In any case I don't see a way to only filter once. Before expand_modules you want to filter once to avoid unnecessarily processing any ignored files but you can not filter everything at this stage because you do not have filepaths for the modules yet. Therefore you want to filter again after you have those.
Hmm, it sounds like a bigger refactor than I thought. If we're going to extract the file discovering from PyLinter we could expand modules, reading from stdin and files discovery at the same time, right ? Removing concerns from the PyLinter would be a good thing especially for more efficient multiprocessing (easier to map files to threads), but I don't have a clear vision about the issue we'll face when doing that.
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.
Yes, I think it should be possible to do the discovering, filtering and expanding beforehand and then passing the result to Pylinter.check
but as you said that is going to be a larger refactor.
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.
Would you be willing to give it a try ?
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 would like to give it a try. That said I have no idea how long it will take because it seems like a quite big refactor and I do not have a lot of time to work on this.
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.
Nice to hear, don't worry about deadline there is none :) ! You can open a draft pull request to discuss the refactor with maintainers, early feedback would probably help you.
Pull Request Test Coverage Report for Build 2977710138
💛 - Coveralls |
Do not mind the pypy failure, main is broken. |
This comment has been minimized.
This comment has been minimized.
@Pierre-Sassoulas @cblessing24 Would we be okay with merging this without the refactor? This is breaking the I think it make sense to offer "first-class" support for the extension as a large part of our user base is likely using VS Code. We could potentially get this in |
Right, but this is technical debt and if this kind of treatment isn't DRY we're going to have a bad time in the long term. We already have a bad time now, this issue is clearly a problem of not treating all sources the same way. Often new contributors come, fix an issue they want to fix but are not expert in the codebase so they do not know that there's two places to modify, tests only the one they changed but not the other and we get inconsistencies (new issues are opened, new contributor come, etc.). I think this is a vicious circle. I'm not saying we should not create this technical debt but we should make sure we think about it. |
@cblessing24 I'm quite familiar with this code. Would you be okay with me taking a stab at this refactor? |
Sure, I am totally fine with that. |
My proposed refactor is actually quite small. See: https://github.com/PyCQA/pylint/pull/6528/files In that PR we already extracted the ignore checking into a separate function out of |
🤖 According to the primer, this change has no effect on the checked open source code. 🤖🎉 This comment was generated for commit 9da9b5d |
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.
👍
Previously pylint would lint a file passed on stdin even if the user meant to ignore the file. This commit fixes that issue. Co-authored-by: Daniël van Noord <[email protected]>
Previously pylint would lint a file passed on stdin even if the user meant to ignore the file. This commit fixes that issue. Co-authored-by: Daniël van Noord <[email protected]>
Type of Changes
Description
This PR adds a check to the see whether the filename passed with the
--from-stdin
option is ignored. The input will not be linted if it is. A corresponding test is also included.Closes #4354