-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Ignore mypy lint errors for other files #15266
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
Conversation
mypy sometimes returns errors for files that aren't the same as the file it was called against. This PR adds some filtering based on the current file name. fixes microsoft#10190
src/client/linters/mypy.ts
Outdated
| } | ||
|
|
||
| protected async runLinter(document: TextDocument, cancellation: CancellationToken): Promise<ILintMessage[]> { | ||
| const messages = await this.run([document.uri.fsPath], document, cancellation, REGEX); |
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.
Another option: generate the regex used to extract the message info at runtime with the current file name substituted instead of the file capture group, causing the messages for the other files to be ignored
src/client/linters/mypy.ts
Outdated
|
|
||
| protected async runLinter(document: TextDocument, cancellation: CancellationToken): Promise<ILintMessage[]> { | ||
| const messages = await this.run([document.uri.fsPath], document, cancellation, REGEX); | ||
| const fileName = document.uri.fsPath.slice(this.getWorkspaceRootPath(document).length + 1); |
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.
original approach was to modify the ILintMessage to include an optional file property and then filter based off that here
regex approach seems less invasive
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.
also wondering the best way to write a test for 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.
Thanks for the PR! Almost there,
|
|
||
| protected async runLinter(document: TextDocument, cancellation: CancellationToken): Promise<ILintMessage[]> { | ||
| const messages = await this.run([document.uri.fsPath], document, cancellation, REGEX); | ||
| const relativeFilePath = document.uri.fsPath.slice(this.getWorkspaceRootPath(document).length + 1); |
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.
document.uri.fsPath gives us "/Users/foo/workspace-project/foo/bar.py" but we want the path relative to the workspace: foo/bar.py
``` ##########Linting Output - mypy########## foo/__init__.py:4:5: error: Statement is unreachable [unreachable] foo/bar.py:2:14: error: Incompatible types in assignment (expression has type "str", variable has type "int") [assignment] Found 2 errors in 2 files (checked 1 source file) ```
Codecov Report
@@ Coverage Diff @@
## main #15266 +/- ##
=======================================
Coverage 65% 65%
=======================================
Files 558 561 +3
Lines 26646 26982 +336
Branches 3840 3914 +74
=======================================
+ Hits 17322 17562 +240
- Misses 8617 8687 +70
- Partials 707 733 +26
|
|
Thanks for the changes, I'll have a look as soon as possible. FYI #15505 could affect this 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.
LGTM once the offset is adjusted via rebase
src/test/linters/mypy.unit.test.ts
Outdated
| [lines[2], undefined], | ||
| ]; | ||
| for (const [line, expected] of tests) { | ||
| const msg = parseLine(line, getRegex('foo/bar.py'), LinterId.MyPy); |
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.
Column offset should be passed as 1.
|
@sbdchd The tests seem to be failing, can you please rebase again? The fixes may have landed on |
|
I think I fixed the tests, I'm having trouble getting the test suite to fail locally If I throw an exception or |
|
Interesting, we generally use |
mypy sometimes returns errors for files that aren't the same as the file
it was called against.
This PR adds some filtering based on the current file name.
Test file structure:
Before:
After:

fixes #10190
related #15216