Skip to content
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

mypy behaves differently from other extensions in reporting problems in files located in symlinked directories #255

Closed
bersbersbers opened this issue Jan 19, 2024 · 13 comments · Fixed by #256
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug triage-needed

Comments

@bersbersbers
Copy link

My C:\Code is a junction:

C:\>dir \
 Volume in drive C is SYSTEM

 Directory of C:\

12/21/2023  10:19 AM    <JUNCTION>     Code [C:\ws]

Now, when I open C:\Code\Bug as a workspace, and inspect C:\Code\Bug\bug.py, this is what I see:

image

PyLance, pylint, sonarlint, flake8, and ruff report errors in the correct file. mypy reports them in C:\ws\Bug\bug.py, which means clicking mypy errors in the "Problems" tab opens the file again:

image

This is closely related to microsoft/vscode#100533, but since all the other extensions get it right, I feel mypy should, too.

@karthiknadig
Copy link
Member

Can you share the part of the logs where there is output from both mypy, pylint, and flake8? With mypy we support file and workspace scopes. We expect mypy to report paths for us to report back. I am assuming mypy is reporting resolved path, logs should clarify that.

@bersbersbers
Copy link
Author

Sure!

mypy:

2024-01-19 17:51:46.400 [info] Name: Mypy Type Checker
2024-01-19 17:51:46.400 [info] Module: mypy
2024-01-19 17:51:46.400 [info] Python extension loading
2024-01-19 17:51:46.400 [info] Waiting for interpreter from python extension.
2024-01-19 17:51:46.400 [info] Python extension loaded
2024-01-19 17:51:46.400 [info] Server run command: c:\Code\project\.venv\Scripts\python.exe c:\Users\bers\.vscode\extensions\ms-python.mypy-type-checker-2023.6.0\bundled\tool\lsp_server.py
2024-01-19 17:51:46.400 [info] Server: Start requested.
2024-01-19 17:51:53.386 [info] CWD Server: c:\Code\Bug
2024-01-19 17:51:53.423 [info] Settings used to run Server:
[
    {
        "cwd": "c:\\Code\\Bug",
        "workspace": "file:///c%3A/Code/Bug",
        "args": [],
        "severity": {
            "error": "Error",
            "note": "Information"
        },
        "path": [],
        "ignorePatterns": [],
        "interpreter": [
            "c:\\Code\\project\\.venv\\Scripts\\python.exe"
        ],
        "importStrategy": "useBundled",
        "showNotifications": "off",
        "extraPaths": [],
        "reportingScope": "workspace",
        "preferDaemon": true
    }
]

2024-01-19 17:51:53.433 [info] Global settings:
{
    "cwd": "${workspaceFolder}",
    "workspace": "C:\\Users\\bers\\AppData\\Local\\Programs\\Microsoft VS Code",
    "args": [],
    "severity": {
        "error": "Error",
        "note": "Information"
    },
    "path": [],
    "ignorePatterns": [],
    "interpreter": [],
    "importStrategy": "useBundled",
    "showNotifications": "off",
    "extraPaths": [],
    "reportingScope": "workspace",
    "preferDaemon": true
}

2024-01-19 17:51:53.435 [info] sys.path used to run Server:
   c:\Code\Bug
   c:\Users\bers\.vscode\extensions\ms-python.mypy-type-checker-2023.6.0\bundled\libs
   c:\Users\bers\.vscode\extensions\ms-python.mypy-type-checker-2023.6.0\bundled\tool
   C:\Scoop\apps\python\current\python312.zip
   C:\Scoop\apps\python\current\DLLs
   C:\Scoop\apps\python\current\Lib
   C:\Scoop\apps\python\current
   c:\Code\project\.venv
   c:\Code\project\.venv\Lib\site-packages
2024-01-19 17:51:53.435 [info] Hi!
2024-01-19 17:51:53.439 [info] c:\Code\project\.venv\Scripts\python.exe -m mypy.dmypy --version
2024-01-19 17:51:53.440 [info] CWD Server: c:\Code\Bug
2024-01-19 17:51:53.481 [info] 
dmypy 1.6.1


2024-01-19 17:51:53.487 [info] Version info for linter running for C:\ws\Bug:
dmypy 1.6.1

2024-01-19 17:51:53.488 [info] SUPPORTED mypy>=1.0.0
FOUND mypy==1.6.1

2024-01-19 17:51:53.510 [info] c:\Users\bers\.vscode\extensions\ms-python.mypy-type-checker-2023.6.0\bundled\tool\lsp_server.py:166: DeprecationWarning: 'workspace.get_document' has been deprecated, use 'workspace.get_text_document' instead
  document = LSP_SERVER.workspace.get_document(params.text_document.uri)

2024-01-19 17:51:53.513 [info] [Trace - 5:51:53 PM] Received notification 'window/logMessage'.
2024-01-19 17:51:53.513 [info] Hi!
2024-01-19 17:51:53.516 [info] [Trace - 5:51:53 PM] Received notification 'window/logMessage'.
2024-01-19 17:51:53.516 [info] Hi!
2024-01-19 17:51:53.516 [info] [Trace - 5:51:53 PM] Received notification 'window/logMessage'.
2024-01-19 17:51:53.517 [info] Hi!
2024-01-19 17:51:53.518 [info] [Trace - 5:51:53 PM] Received notification 'window/logMessage'.
2024-01-19 17:51:53.518 [info] c:\Code\project\.venv\Scripts\python.exe -m mypy.dmypy --status-file C:\Users\bers\AppData\Local\Temp\.vscode.dmypy_status\status-8d2a0d54-db58-4f52-a04b-17c706573812.json run -- --no-color-output --no-error-summary --show-absolute-path --show-column-numbers --show-error-codes --no-pretty --show-error-end c:\Code\Bug
2024-01-19 17:51:53.519 [info] [Trace - 5:51:53 PM] Received notification 'window/logMessage'.
2024-01-19 17:51:53.519 [info] CWD Server: c:\Code\Bug
2024-01-19 17:52:00.179 [info] [Trace - 5:52:00 PM] Received notification 'window/logMessage'.
2024-01-19 17:52:00.179 [info] file:///c%3A/Code/Bug/bug.py :
Daemon started
c:\Code\Bug\bug.py:1:11:1:11: error: Incompatible types in assignment (expression has type "int", variable has type "str")  [assignment]

2024-01-19 17:52:00.180 [info] [Trace - 5:52:00 PM] Received notification 'window/logMessage'.
2024-01-19 17:52:00.180 [info] file:///c%3A/Code/Bug/bug.py :
Daemon started
c:\Code\Bug\bug.py:1:11:1:11: error: Incompatible types in assignment (expression has type "int", variable has type "str")  [assignment]

2024-01-19 17:52:00.184 [info] [Trace - 5:52:00 PM] Received notification 'textDocument/publishDiagnostics'.

pylint

2024-01-19 17:51:46.401 [info] Name: Pylint
2024-01-19 17:51:46.401 [info] Module: pylint
2024-01-19 17:51:46.401 [info] Python extension loading
2024-01-19 17:51:46.401 [info] Waiting for interpreter from Python extension.
2024-01-19 17:51:46.401 [info] No interpreter found from setting pylint.interpreter
2024-01-19 17:51:46.401 [info] Getting interpreter from ms-python.python extension for workspace c:\Code\Bug
2024-01-19 17:51:46.401 [info] Python extension loaded
2024-01-19 17:51:46.401 [info] Interpreter from ms-python.python extension for c:\Code\Bug: c:\Code\project\.venv\Scripts\python.exe
2024-01-19 17:51:46.401 [info] No interpreter found from setting pylint.interpreter
2024-01-19 17:51:46.401 [info] Getting interpreter from ms-python.python extension for workspace c:\Code\Bug
2024-01-19 17:51:46.402 [info] Interpreter from ms-python.python extension for c:\Code\Bug: c:\Code\project\.venv\Scripts\python.exe
2024-01-19 17:51:46.402 [info] Server run command: c:\Code\project\.venv\Scripts\python.exe c:\Users\bers\.vscode\extensions\ms-python.pylint-2023.10.1\bundled\tool\lsp_server.py
2024-01-19 17:51:46.402 [info] Server: Start requested.
2024-01-19 17:51:53.385 [info] CWD Server: c:\Code\Bug
2024-01-19 17:51:53.423 [info] Settings used to run Server:
[
    {
        "cwd": "c:\\Code\\Bug",
        "workspace": "file:///c%3A/Code/Bug",
        "args": [],
        "severity": {
            "convention": "Information",
            "error": "Error",
            "fatal": "Error",
            "refactor": "Hint",
            "warning": "Warning",
            "info": "Information"
        },
        "path": [],
        "ignorePatterns": [],
        "interpreter": [
            "c:\\Code\\project\\.venv\\Scripts\\python.exe"
        ],
        "importStrategy": "useBundled",
        "showNotifications": "off",
        "extraPaths": []
    }
]

2024-01-19 17:51:53.432 [info] Global settings:
{
    "cwd": "${workspaceFolder}",
    "workspace": "C:\\Users\\bers\\AppData\\Local\\Programs\\Microsoft VS Code",
    "args": [],
    "severity": {
        "convention": "Information",
        "error": "Error",
        "fatal": "Error",
        "refactor": "Hint",
        "warning": "Warning",
        "info": "Information"
    },
    "path": [],
    "ignorePatterns": [],
    "interpreter": [],
    "importStrategy": "useBundled",
    "showNotifications": "off",
    "extraPaths": []
}

2024-01-19 17:51:53.435 [info] sys.path used to run Server:
   c:\Code\Bug
   c:\Users\bers\.vscode\extensions\ms-python.pylint-2023.10.1\bundled\libs
   c:\Users\bers\.vscode\extensions\ms-python.pylint-2023.10.1\bundled\tool
   C:\Scoop\apps\python\current\python312.zip
   C:\Scoop\apps\python\current\DLLs
   C:\Scoop\apps\python\current\Lib
   C:\Scoop\apps\python\current
   c:\Code\project\.venv
   c:\Code\project\.venv\Lib\site-packages
2024-01-19 17:51:53.435 [info] c:\Code\project\.venv\Scripts\python.exe -m pylint --version
2024-01-19 17:51:53.439 [info] CWD Linter: c:\Code\Bug
2024-01-19 17:51:53.440 [info] 
pylint 3.0.2
astroid 3.0.1
Python 3.12.1 (tags/v3.12.1:2305ca5, Dec  7 2023, 22:03:25) [MSC v.1937 64 bit (AMD64)]


2024-01-19 17:51:53.481 [info] Version info for linter running for C:\ws\Bug:
pylint 3.0.2
astroid 3.0.1
Python 3.12.1 (tags/v3.12.1:2305ca5, Dec  7 2023, 22:03:25) [MSC v.1937 64 bit (AMD64)]

2024-01-19 17:51:53.486 [info] SUPPORTED pylint>=2.12.2
FOUND pylint==3.0.2

2024-01-19 17:51:53.515 [info] [Trace - 5:51:53 PM] Received notification 'window/logMessage'.
2024-01-19 17:51:53.516 [info] c:\Code\project\.venv\Scripts\python.exe -m pylint --reports=n --output-format=json --clear-cache-post-run=y --from-stdin c:\Code\Bug\bug.py
2024-01-19 17:51:53.516 [info] [Trace - 5:51:53 PM] Received notification 'window/logMessage'.
2024-01-19 17:51:53.516 [info] CWD Linter: c:\Code\Bug
2024-01-19 17:51:53.635 [info] [Trace - 5:51:53 PM] Sending request 'textDocument/codeAction - (1)'.
2024-01-19 17:51:53.636 [info] [Trace - 5:51:53 PM] Sending notification '$/cancelRequest'.
2024-01-19 17:51:53.639 [info] [Trace - 5:51:53 PM] Sending request 'textDocument/codeAction - (2)'.
2024-01-19 17:51:53.961 [info] [Trace - 5:51:53 PM] Sending request 'textDocument/codeAction - (3)'.
2024-01-19 17:51:53.963 [info] [Trace - 5:51:53 PM] Sending notification '$/cancelRequest'.
2024-01-19 17:51:54.234 [info] [Trace - 5:51:54 PM] Received notification 'window/logMessage'.
2024-01-19 17:51:54.234 [info] file:///c%3A/Code/Bug/bug.py :
[
    {
        "type": "convention",
        "module": "bug",
        "obj": "",
        "line": 1,
        "column": 0,
        "endLine": null,
        "endColumn": null,
        "path": "bug.py",
        "symbol": "missing-final-newline",
        "message": "Final newline missing",
        "message-id": "C0304"
    },
    {
        "type": "convention",
        "module": "bug",
        "obj": "",
        "line": 1,
        "column": 0,
        "endLine": null,
        "endColumn": null,
        "path": "bug.py",
        "symbol": "missing-module-docstring",
        "message": "Missing module docstring",
        "message-id": "C0114"
    }
]

2024-01-19 17:51:54.237 [info] [Trace - 5:51:54 PM] Received notification 'textDocument/publishDiagnostics'.
2024-01-19 17:51:54.245 [info] [Trace - 5:51:54 PM] Received response 'textDocument/codeAction - (1)' in 610ms.
2024-01-19 17:51:54.248 [info] [Trace - 5:51:54 PM] Received response 'textDocument/codeAction - (2)' in 609ms.
2024-01-19 17:51:54.250 [info] [Trace - 5:51:54 PM] Received response 'textDocument/codeAction - (3)' in 288ms.
2024-01-19 17:51:54.354 [info] [Trace - 5:51:54 PM] Sending request 'textDocument/codeAction - (4)'.
2024-01-19 17:51:54.362 [info] [Trace - 5:51:54 PM] Received response 'textDocument/codeAction - (4)' in 8ms.
2024-01-19 17:51:55.659 [info] [Trace - 5:51:55 PM] Sending request 'textDocument/codeAction - (5)'.
2024-01-19 17:51:55.672 [info] [Trace - 5:51:55 PM] Received response 'textDocument/codeAction - (5)' in 13ms.
2024-01-19 17:51:55.750 [info] [Trace - 5:51:55 PM] Sending request 'textDocument/codeAction - (6)'.
2024-01-19 17:51:55.755 [info] [Trace - 5:51:55 PM] Received response 'textDocument/codeAction - (6)' in 4ms.
2024-01-19 17:52:05.777 [info] [Trace - 5:52:05 PM] Sending request 'textDocument/codeAction - (7)'.
2024-01-19 17:52:05.782 [info] [Trace - 5:52:05 PM] Received response 'textDocument/codeAction - (7)' in 4ms.
2024-01-19 17:52:06.539 [info] [Trace - 5:52:06 PM] Sending request 'textDocument/codeAction - (8)'.
2024-01-19 17:52:06.543 [info] [Trace - 5:52:06 PM] Received response 'textDocument/codeAction - (8)' in 4ms.

flake8

2024-01-19 17:51:46.397 [info] Name: Flake8
2024-01-19 17:51:46.397 [info] Module: flake8
2024-01-19 17:51:46.397 [info] Python extension loading
2024-01-19 17:51:46.397 [info] Waiting for interpreter from Python extension.
2024-01-19 17:51:46.397 [info] No interpreter found from setting flake8.interpreter
2024-01-19 17:51:46.397 [info] Getting interpreter from ms-python.python extension for workspace c:\Code\Bug
2024-01-19 17:51:46.397 [info] Python extension loaded
2024-01-19 17:51:46.397 [info] Interpreter from ms-python.python extension for c:\Code\Bug: c:\Code\project\.venv\Scripts\python.exe
2024-01-19 17:51:46.397 [info] No interpreter found from setting flake8.interpreter
2024-01-19 17:51:46.397 [info] Getting interpreter from ms-python.python extension for workspace c:\Code\Bug
2024-01-19 17:51:46.398 [info] Interpreter from ms-python.python extension for c:\Code\Bug: c:\Code\project\.venv\Scripts\python.exe
2024-01-19 17:51:46.398 [info] Server run command: c:\Code\project\.venv\Scripts\python.exe c:\Users\bers\.vscode\extensions\ms-python.flake8-2023.10.0\bundled\tool\lsp_server.py
2024-01-19 17:51:46.398 [info] Server: Start requested.
2024-01-19 17:51:53.384 [info] CWD Server: c:\Code\Bug
2024-01-19 17:51:53.423 [info] sys.path used to run Server:
   c:\Users\bers\.vscode\extensions\ms-python.flake8-2023.10.0\bundled\libs
   c:\Users\bers\.vscode\extensions\ms-python.flake8-2023.10.0\bundled\tool
   C:\Scoop\apps\python\current\python312.zip
   C:\Scoop\apps\python\current\DLLs
   C:\Scoop\apps\python\current\Lib
   C:\Scoop\apps\python\current
   c:\Code\project\.venv
   c:\Code\project\.venv\Lib\site-packages
2024-01-19 17:51:53.432 [info] Settings used to run Server:
[
    {
        "cwd": "c:\\Code\\Bug",
        "workspace": "file:///c%3A/Code/Bug",
        "args": [],
        "severity": {
            "E": "Error",
            "F": "Error",
            "I": "Information",
            "W": "Warning"
        },
        "path": [],
        "ignorePatterns": [],
        "interpreter": [
            "c:\\Code\\project\\.venv\\Scripts\\python.exe"
        ],
        "importStrategy": "useBundled",
        "showNotifications": "off"
    }
]

2024-01-19 17:51:53.435 [info] Global settings:
{
    "cwd": "${workspaceFolder}",
    "workspace": "C:\\Users\\bers\\AppData\\Local\\Programs\\Microsoft VS Code",
    "args": [],
    "severity": {
        "E": "Error",
        "F": "Error",
        "I": "Information",
        "W": "Warning"
    },
    "path": [],
    "ignorePatterns": [],
    "interpreter": [],
    "importStrategy": "useBundled",
    "showNotifications": "off"
}

2024-01-19 17:51:53.435 [info] c:\Code\project\.venv\Scripts\python.exe -m flake8 --version
2024-01-19 17:51:53.439 [info] CWD Linter: c:\Code\Bug
2024-01-19 17:51:53.440 [info] 
6.1.0 (mccabe: 0.7.0, pycodestyle: 2.11.1, pyflakes: 3.1.0) CPython 3.12.1 on
Windows


2024-01-19 17:51:53.481 [info] Version info for linter running for C:\ws\Bug:
6.1.0 (mccabe: 0.7.0, pycodestyle: 2.11.1, pyflakes: 3.1.0) CPython 3.12.1 on
Windows

2024-01-19 17:51:53.485 [info] SUPPORTED flake8>=5.0.0
FOUND flake8==6.1.0

2024-01-19 17:51:53.514 [info] [Trace - 5:51:53 PM] Received notification 'window/logMessage'.
2024-01-19 17:51:53.514 [info] c:\Code\project\.venv\Scripts\python.exe -m flake8 --format='%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s' c:\Code\Bug\bug.py
2024-01-19 17:51:53.515 [info] [Trace - 5:51:53 PM] Received notification 'window/logMessage'.
2024-01-19 17:51:53.515 [info] CWD Linter: c:\Code\Bug
2024-01-19 17:51:53.633 [info] [Trace - 5:51:53 PM] Received notification 'window/logMessage'.
2024-01-19 17:51:53.633 [info] file:///c%3A/Code/Bug/bug.py :
'1,2,E,E203:whitespace before ':''
'1,12,W,W292:no newline at end of file'

2024-01-19 17:51:53.639 [info] [Trace - 5:51:53 PM] Sending request 'textDocument/codeAction - (1)'.
2024-01-19 17:51:53.646 [info] [Trace - 5:51:53 PM] Received notification 'textDocument/publishDiagnostics'.
2024-01-19 17:51:53.656 [info] [Trace - 5:51:53 PM] Received response 'textDocument/codeAction - (1)' in 17ms.
2024-01-19 17:51:53.960 [info] [Trace - 5:51:53 PM] Sending request 'textDocument/codeAction - (2)'.
2024-01-19 17:51:54.009 [info] [Trace - 5:51:53 PM] Received response 'textDocument/codeAction - (2)' in 49ms.
2024-01-19 17:51:54.353 [info] [Trace - 5:51:54 PM] Sending request 'textDocument/codeAction - (3)'.
2024-01-19 17:51:54.363 [info] [Trace - 5:51:54 PM] Received response 'textDocument/codeAction - (3)' in 9ms.
2024-01-19 17:51:55.659 [info] [Trace - 5:51:55 PM] Sending request 'textDocument/codeAction - (4)'.
2024-01-19 17:51:55.672 [info] [Trace - 5:51:55 PM] Received response 'textDocument/codeAction - (4)' in 13ms.
2024-01-19 17:51:55.750 [info] [Trace - 5:51:55 PM] Sending request 'textDocument/codeAction - (5)'.
2024-01-19 17:51:55.756 [info] [Trace - 5:51:55 PM] Received response 'textDocument/codeAction - (5)' in 6ms.
2024-01-19 17:52:05.776 [info] [Trace - 5:52:05 PM] Sending request 'textDocument/codeAction - (6)'.
2024-01-19 17:52:05.781 [info] [Trace - 5:52:05 PM] Received response 'textDocument/codeAction - (6)' in 5ms.
2024-01-19 17:52:06.539 [info] [Trace - 5:52:06 PM] Sending request 'textDocument/codeAction - (7)'.
2024-01-19 17:52:06.545 [info] [Trace - 5:52:06 PM] Received response 'textDocument/codeAction - (7)' in 6ms.
2024-01-19 17:53:29.654 [info] [Trace - 5:53:29 PM] Sending notification 'textDocument/didOpen'.
2024-01-19 17:53:29.659 [info] [Trace - 5:53:29 PM] Received notification 'window/logMessage'.
2024-01-19 17:53:29.659 [info] [Info  - 5:53:29 PM] Skipping linting for untitled:Untitled-2 skipped: not supported
2024-01-19 17:53:29.659 [info] [Trace - 5:53:29 PM] Received notification 'textDocument/publishDiagnostics'.

Result:
image

@karthiknadig karthiknadig self-assigned this Jan 19, 2024
@karthiknadig karthiknadig added the bug Issue identified by VS Code Team member as probable bug label Jan 19, 2024
@karthiknadig
Copy link
Member

Can you test with this build and see if it works? https://github.com/microsoft/vscode-mypy/actions/runs/7590298754/artifacts/1182327203

@bersbersbers
Copy link
Author

@karthiknadig tested it, same behavior. But that's hardly surprising, since the new function does exactly the same thing as the old one :)

image

@karthiknadig
Copy link
Member

@bersbersbers Sorry about that. Let me push the correct one.

@karthiknadig
Copy link
Member

@bersbersbers
Copy link
Author

That's much better :) Thank you!
image

There's still this in the logs - not sure if you want to fix it. It does not seem to impact me:

2024-01-20 06:34:02.936 [info] Version info for linter running for C:\ws\Bug:
dmypy 1.7.1

@karthiknadig
Copy link
Member

@bersbersbers we by default use resolved paths, for easier mapping when working with workspace scope. You can force the current working directory to be the path you want by setting it explicitly. You can set it like "mypy-type-checker.cwd": "${workspaceFolder}".

But I need to re-evaluate how this is done for each case. It might be working fine, but I feel like since the working dir for mypy is different from the directory it is actually running in. I suspect it might run into other issues.

@ktbarrett
Copy link

ktbarrett commented Jun 7, 2024

I recently ran into this same issue, but my entire workspace was opened via a symlinked directory. Nothing worked. Opening the same workspace via the physical path resolved the issue.

You might be able to take the same approach as git support did.

@Hnasar
Copy link

Hnasar commented Sep 12, 2024

This is still an issue one of our team members ran into today. Has there been any update on this very hard-to-debug bug?

The Ruff extension, for example, handles this properly and is able to report errors on a symlinked repo.

@bersbersbers
Copy link
Author

I remember #256 fixed this for me, but it has yet to be merged.

@karthiknadig
Copy link
Member

@Hnasar @ktbarrett Can you try this build and let me know if it works for you. This fell of my radar, I can merge it if you can confirm: https://github.com/microsoft/vscode-mypy/actions/runs/10843266187/artifacts/1928229507

@ktbarrett
Copy link

@karthiknadig It seems to work for me. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug triage-needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants