-
Notifications
You must be signed in to change notification settings - Fork 28
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
Can't figure out how to configure extension to allow for gradual adoption #304
Comments
@jrheard Have you looked into setting |
Hey @karthiknadig , thanks for the speedy response! The behavior I'm looking for would look something like this:
To put it another way, it's not the case that I want to type check the whole repo and only ignore messages for certain directories - instead I only want to type check certain deeply nested directories (eg Is this possible? Please let me know if this doesn't make sense. I think that the behavior I'm looking for is reasonable, but it's always possible that I'm coming at this from a confused/incorrect starting point. Thanks! |
I think that this is a sketch of what I have in mind: 1d15b7c . (I just put this together in ten seconds as an illustration after a quick search through the codebase for usage of ignorePatterns - this is obviously not a fully-fledged PR, just an example of the behavior I'm hoping to accomplish here, hopefully with preexisting configuration options). Again, the best outcome for me here would be for this behavior to be configurable solely through |
Were you not able to set a pattern with: https://mypy.readthedocs.io/en/stable/config_file.html#confval-exclude Looking at I think you should be able to use exclude pattern in |
Thanks, I bet that's the ticket. I had a hard time figuring out how to come up with the right combination of
I get this:
But that's a question I should ask the mypy folks rather than you, and again I'm sure I'm missing something obvious here. If I'm hearing you correctly, then once I get my |
Whoops, I spoke too soon! It looks like I get different output when I run mypy directly at the command line:
It looks like the command-line mypy gives me the behavior I want, but the vscode extension invocation of mypy doesn't. Logs here: Click2024-05-29 21:12:50.541 [info] [Trace - 9:12:50 PM] Sending notification 'textDocument/didChange'. 2024-05-29 21:12:50.541 [info] Params: { "textDocument": { "uri": "file:///Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/a/one.py", "version": 14 }, "contentChanges": [ { "range": { "start": { "line": 2, "character": 0 }, "end": { "line": 2, "character": 0 } }, "rangeLength": 0, "text": "\n" } ] }2024-05-29 21:12:51.204 [info] [Trace - 9:12:51 PM] Sending notification 'textDocument/didChange'. 2024-05-29 21:12:51.226 [info] [Trace - 9:12:51 PM] Sending notification 'textDocument/didSave'. 2024-05-29 21:12:51.228 [info] [Trace - 9:12:51 PM] Received notification 'window/logMessage'. 2024-05-29 21:12:51.228 [info] /Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/.venv/bin/python -m mypy --no-color-output --no-error-summary --show-absolute-path --show-column-numbers --show-error-codes --no-pretty --show-error-end /Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro 2024-05-29 21:12:51.228 [info] CWD Server: /Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro 2024-05-29 21:12:51.358 [info] There are no .py[i] files in directory '/Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro' 2024-05-29 21:12:51.358 [info] [Trace - 9:12:51 PM] Received notification 'window/logMessage'. 2024-05-29 21:12:51.358 [info] file:///Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/a/one.py : 2024-05-29 21:12:51.358 [info] [Trace - 9:12:51 PM] Received notification 'textDocument/publishDiagnostics'. |
I would need to look at the settings, and also the |
It looks like it's using version 1.10 if I'm reading this right 👍 I think that I need to quit bugging you for a bit and go figure out how to configure |
Good call - I asked in the mypy gitter, but kept poking around in the meantime, and I think I found the solution. This
I knew there was some setting like this that I used at my last job, and I spent a lot of time with the With this |
Context
I'm trying to figure out how to configure both Mypy and the Mypy vscode extension to only run on files in one or two directories in my codebase. I'm introducing mypy to a preexisting long-lived project, and want to adopt it gradually.
(I'm providing a minimal repro repo, and I'm only talking about wanting to run on one or two specified directories, but please imagine that soon I'll want to run on fifteen or twenty directories that are nested arbitrarily deep into the real-life repo that I'm trying to introduce mypy to. It will be a long time (if ever) before I'm able to run mypy on an entire nontrivial top-level directory in this real-life repo.)
I'm sure that I must be doing something wrong and am hopeful that there's some easy obvious combination of configuration options that will provide the behavior that I want, but I've spent a fair amount of time trying to figure this out and haven't gotten anywhere. Thanks in advance :)
(I've tried the file and workspace reporting scopes and haven't seen a difference in the resulting behavior, fwiw)
Diagnostic Data
Behaviour
Expected Behavior
I should be able to use a combination of
mypy.ini
configuration options and vscode mypy extension settings in order to get the vscode extension to only run on filevscode_mypy_repro/b/good/*.py
in https://github.com/jrheard/vscode_mypy_repro .Actual Behavior
When I run
mypy
at the command line, it only runs on the files that I want it to (which is good!). But when I edit other files (egvscode_mypy_repro/a/one.py
) in vscode, the vscode mypy extension runs on those files too, and shows type errors in those files even though I don't want to see them because I haven't added them to my allow list of files yet.Reproduction Steps:
poetry install
(or just use your global mypy, I don't think this matters)poetry run mypy
(or justmypy
) with no args and see that it only runs onvscode_mypy_repro/b/good/example.py
(which is good!)vscode_mypy_repro/a/one.py
in vscode with the mypy extension installed, edit the file, and see a type error displayed in the vscode editor (this is not what I want, I only want the vscode extension to run on certain allowlisted files/directories)Question: Is there some combination of
mypy.ini
settings and vscode settings that will make it so that both command-line mypy and the vscode extension only typecheck files in thevscode_mypy_repro/b
directory? Ideally this would be achievable using onlymypy.ini
settings so that CI and vscode are both reading from the same place with no further per-developer-machine configuration necessary, but vscode settings are OK if necessary.Thank you!
Logs:
Click here for detailed logs (reporting scope: workspace)
2024-05-29 20:02:33.493 [info] [Trace - 8:02:33 PM] Sending notification 'textDocument/didChange'. 2024-05-29 20:02:33.494 [info] Params: { "textDocument": { "uri": "file:///Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/a/one.py", "version": 8 }, "contentChanges": [ { "range": { "start": { "line": 2, "character": 0 }, "end": { "line": 2, "character": 0 } }, "rangeLength": 0, "text": "\n" } ] }2024-05-29 20:02:39.426 [info] [Trace - 8:02:39 PM] Sending notification 'textDocument/didChange'.
2024-05-29 20:02:39.426 [info] Params: {
"textDocument": {
"uri": "file:///Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/a/one.py",
"version": 9
},
"contentChanges": [
{
"range": {
"start": {
"line": 2,
"character": 0
},
"end": {
"line": 3,
"character": 0
}
},
"rangeLength": 1,
"text": ""
}
]
}
2024-05-29 20:02:39.446 [info] [Trace - 8:02:39 PM] Sending notification 'textDocument/didSave'.
2024-05-29 20:02:39.446 [info] Params: {
"textDocument": {
"uri": "file:///Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/a/one.py"
}
}
2024-05-29 20:02:39.448 [info] /Users/jrheard/.vscode/extensions/ms-python.mypy-type-checker-2023.6.0/bundled/tool/lsp_server.py:172: DeprecationWarning: 'workspace.get_document' has been deprecated, use 'workspace.get_text_document' instead
document = LSP_SERVER.workspace.get_document(params.text_document.uri)
2024-05-29 20:02:39.448 [info] [Trace - 8:02:39 PM] Received notification 'window/logMessage'.
2024-05-29 20:02:39.448 [info] Params: {
"type": 4,
"message": "/Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/.venv/bin/python -m mypy --no-color-output --no-error-summary --show-absolute-path --show-column-numbers --show-error-codes --no-pretty --show-error-end /Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro"
}
2024-05-29 20:02:39.449 [info] /Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/.venv/bin/python -m mypy --no-color-output --no-error-summary --show-absolute-path --show-column-numbers --show-error-codes --no-pretty --show-error-end /Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro
2024-05-29 20:02:39.449 [info] [Trace - 8:02:39 PM] Received notification 'window/logMessage'.
2024-05-29 20:02:39.449 [info] Params: {
"type": 4,
"message": "CWD Server: /Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro"
}
2024-05-29 20:02:39.449 [info] CWD Server: /Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro
2024-05-29 20:02:39.804 [info] [Trace - 8:02:39 PM] Received notification 'window/logMessage'.
2024-05-29 20:02:39.804 [info] Params: {
"type": 4,
"message": "file:///Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/a/one.py :\r\n/Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/c/three.py:3:5:3:12: error: No return value expected [return-value]\n/Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/b/two.py:2:5:2:12: error: No return value expected [return-value]\n/Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/b/good/example.py:2:5:2:12: error: No return value expected [return-value]\n/Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/a/one.py:2:5:2:12: error: No return value expected [return-value]\n"
}
2024-05-29 20:02:39.804 [info] file:///Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/a/one.py :
/Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/c/three.py:3:5:3:12: error: No return value expected [return-value]
/Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/b/two.py:2:5:2:12: error: No return value expected [return-value]
/Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/b/good/example.py:2:5:2:12: error: No return value expected [return-value]
/Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/a/one.py:2:5:2:12: error: No return value expected [return-value]
2024-05-29 20:02:39.804 [info] [Trace - 8:02:39 PM] Received notification 'window/logMessage'.
2024-05-29 20:02:39.804 [info] Params: {
"type": 4,
"message": "file:///Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/a/one.py :\r\n/Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/c/three.py:3:5:3:12: error: No return value expected [return-value]\n/Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/b/two.py:2:5:2:12: error: No return value expected [return-value]\n/Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/b/good/example.py:2:5:2:12: error: No return value expected [return-value]\n/Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/a/one.py:2:5:2:12: error: No return value expected [return-value]\n"
}
2024-05-29 20:02:39.804 [info] file:///Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/a/one.py :
/Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/c/three.py:3:5:3:12: error: No return value expected [return-value]
/Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/b/two.py:2:5:2:12: error: No return value expected [return-value]
/Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/b/good/example.py:2:5:2:12: error: No return value expected [return-value]
/Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/a/one.py:2:5:2:12: error: No return value expected [return-value]
2024-05-29 20:02:39.805 [info] [Trace - 8:02:39 PM] Received notification 'textDocument/publishDiagnostics'.
2024-05-29 20:02:39.805 [info] Params: {
"uri": "file:///Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/c/three.py",
"diagnostics": [
{
"range": {
"start": {
"line": 2,
"character": 4
},
"end": {
"line": 2,
"character": 12
}
},
"message": "No return value expected",
"severity": 1,
"code": "return-value",
"codeDescription": {
"href": "https://mypy.readthedocs.io/en/latest/_refs.html#code-return-value"
},
"source": "Mypy"
}
]
}
2024-05-29 20:02:39.805 [info] [Trace - 8:02:39 PM] Received notification 'textDocument/publishDiagnostics'.
2024-05-29 20:02:39.805 [info] Params: {
"uri": "file:///Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/b/two.py",
"diagnostics": [
{
"range": {
"start": {
"line": 1,
"character": 4
},
"end": {
"line": 1,
"character": 12
}
},
"message": "No return value expected",
"severity": 1,
"code": "return-value",
"codeDescription": {
"href": "https://mypy.readthedocs.io/en/latest/_refs.html#code-return-value"
},
"source": "Mypy"
}
]
}
2024-05-29 20:02:39.805 [info] [Trace - 8:02:39 PM] Received notification 'textDocument/publishDiagnostics'.
2024-05-29 20:02:39.805 [info] Params: {
"uri": "file:///Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/b/good/example.py",
"diagnostics": [
{
"range": {
"start": {
"line": 1,
"character": 4
},
"end": {
"line": 1,
"character": 12
}
},
"message": "No return value expected",
"severity": 1,
"code": "return-value",
"codeDescription": {
"href": "https://mypy.readthedocs.io/en/latest/_refs.html#code-return-value"
},
"source": "Mypy"
}
]
}
2024-05-29 20:02:39.805 [info] [Trace - 8:02:39 PM] Received notification 'textDocument/publishDiagnostics'.
2024-05-29 20:02:39.805 [info] Params: {
"uri": "file:///Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/a/one.py",
"diagnostics": [
{
"range": {
"start": {
"line": 1,
"character": 4
},
"end": {
"line": 1,
"character": 12
}
},
"message": "No return value expected",
"severity": 1,
"code": "return-value",
"codeDescription": {
"href": "https://mypy.readthedocs.io/en/latest/_refs.html#code-return-value"
},
"source": "Mypy"
}
]
}
Click here for detailed logs (reporting scope: file)
2024-05-29 20:03:23.737 [info] [Trace - 8:03:23 PM] Sending notification 'textDocument/didChange'. 2024-05-29 20:03:23.737 [info] Params: { "textDocument": { "uri": "file:///Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/a/one.py", "version": 10 }, "contentChanges": [ { "range": { "start": { "line": 2, "character": 0 }, "end": { "line": 2, "character": 0 } }, "rangeLength": 0, "text": "\n" } ] }2024-05-29 20:03:24.556 [info] [Trace - 8:03:24 PM] Sending notification 'textDocument/didChange'.
2024-05-29 20:03:24.556 [info] Params: {
"textDocument": {
"uri": "file:///Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/a/one.py",
"version": 11
},
"contentChanges": [
{
"range": {
"start": {
"line": 2,
"character": 0
},
"end": {
"line": 3,
"character": 0
}
},
"rangeLength": 1,
"text": ""
}
]
}
2024-05-29 20:03:24.581 [info] [Trace - 8:03:24 PM] Sending notification 'textDocument/didSave'.
2024-05-29 20:03:24.582 [info] Params: {
"textDocument": {
"uri": "file:///Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/a/one.py"
}
}
2024-05-29 20:03:24.583 [info] /Users/jrheard/.vscode/extensions/ms-python.mypy-type-checker-2023.6.0/bundled/tool/lsp_server.py:172: DeprecationWarning: 'workspace.get_document' has been deprecated, use 'workspace.get_text_document' instead
document = LSP_SERVER.workspace.get_document(params.text_document.uri)
2024-05-29 20:03:24.584 [info] [Trace - 8:03:24 PM] Received notification 'window/logMessage'.
2024-05-29 20:03:24.584 [info] Params: {
"type": 4,
"message": "/Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/.venv/bin/python -m mypy --no-color-output --no-error-summary --show-absolute-path --show-column-numbers --show-error-codes --no-pretty --show-error-end /Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/a/one.py"
}
2024-05-29 20:03:24.584 [info] /Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/.venv/bin/python -m mypy --no-color-output --no-error-summary --show-absolute-path --show-column-numbers --show-error-codes --no-pretty --show-error-end /Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/a/one.py
2024-05-29 20:03:24.584 [info] [Trace - 8:03:24 PM] Received notification 'window/logMessage'.
2024-05-29 20:03:24.584 [info] Params: {
"type": 4,
"message": "CWD Server: /Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro"
}
2024-05-29 20:03:24.584 [info] CWD Server: /Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro
2024-05-29 20:03:25.056 [info] [Trace - 8:03:25 PM] Received notification 'window/logMessage'.
2024-05-29 20:03:25.057 [info] Params: {
"type": 4,
"message": "file:///Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/a/one.py :\r\n/Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/a/one.py:2:5:2:12: error: No return value expected [return-value]\n"
}
2024-05-29 20:03:25.057 [info] file:///Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/a/one.py :
/Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/a/one.py:2:5:2:12: error: No return value expected [return-value]
2024-05-29 20:03:25.057 [info] [Trace - 8:03:25 PM] Received notification 'window/logMessage'.
2024-05-29 20:03:25.057 [info] Params: {
"type": 4,
"message": "file:///Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/a/one.py :\r\n/Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/a/one.py:2:5:2:12: error: No return value expected [return-value]\n"
}
2024-05-29 20:03:25.057 [info] file:///Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/a/one.py :
/Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/a/one.py:2:5:2:12: error: No return value expected [return-value]
2024-05-29 20:03:25.057 [info] [Trace - 8:03:25 PM] Received notification 'textDocument/publishDiagnostics'.
2024-05-29 20:03:25.057 [info] Params: {
"uri": "file:///Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro/vscode_mypy_repro/a/one.py",
"diagnostics": [
{
"range": {
"start": {
"line": 1,
"character": 4
},
"end": {
"line": 1,
"character": 12
}
},
"message": "No return value expected",
"severity": 1,
"code": "return-value",
"codeDescription": {
"href": "https://mypy.readthedocs.io/en/latest/_refs.html#code-return-value"
},
"source": "Mypy"
}
]
}
Outcome When Attempting Debugging Steps:
Did running it from the command line work?
Running
poetry run mypy --no-color-output --no-error-summary --show-absolute-path --show-column-numbers --show-error-codes --no-pretty --show-error-en d /Users/jrheard/Library/CloudStorage/Dropbox/dev/vscode_mypy_repro
(which is what the extension runs with reportingScope: workspace, withpoetry run
prefixed) runs mypy on the whole repo, which is not what I want. I'd like to figure out how to configure this command so that the extension and the default command-line mypy tool both only operate on one or two specified directories in the whole repo.The text was updated successfully, but these errors were encountered: