microsoft / pylance-release

Documentation and issues for Pylance
Creative Commons Attribution 4.0 International
1.71k stars 765 forks source link

Pylance reports problems in interactive window without a way to ignore them #6617

Open b-a0 opened 7 months ago

b-a0 commented 7 months ago

Environment data

Basically https://github.com/microsoft/vscode-jupyter/issues/8289.
The last comment there indicated that if the issue still occurs it should be reported under the appropriate repository.

debonte commented 7 months ago

I'm unable to repro this. For example, there's no diagnostic shown in the screenshot below, whereas in a normal .py file x: int = "str" would generate a diagnostic. I have python.analysis.typeCheckingMode set to "basic".

Can you provide steps to reproduce this issue? And a screenshot?

image

Unless you're referring to the behavior below where diagnostics are shown within "cells" marked by #%% in a .py file? If so, I'd say that's by design. Also, I believe the main point of https://github.com/microsoft/vscode-jupyter/issues/8289 was that code once executed in the Interactive Window can't be changed/fixed, so showing diagnostics there is distracting. But in this scenario you can modify the code, so showing diagnostics makes sense.

image

b-a0 commented 7 months ago

It's not about the # %% cells, but about the unchangeable, executed code in the Interactive Window.

Steps to reproduce:

  1. Have a workspace with the following .vscode/ content:
    settings.json
{
    "python.analysis.typeCheckingMode": "basic",
    "python.testing.unittestEnabled": false,
    "python.testing.pytestEnabled": true,
}

launch.json ```json { // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "PowerShell Launch Current File", "type": "PowerShell", "request": "launch", "script": "${file}", "cwd": "${cwd}" }, { "name": "Python: Current File", "type": "debugpy", "request": "launch", "program": "${file}", "console": "internalConsole", "justMyCode": true, "env": { "PYDEVD_WARN_SLOW_RESOLVE_TIMEOUT": "5" } } ] } ```
  1. Create the following conda environment
environment.yml ```yaml name: my_env channels: - conda-forge - defaults dependencies: - black - bokeh - cairo - datashader - gdal - geopandas - holoviews - hvplot - ipykernel - isort - jupyter - matplotlib - movingpandas - networkx - openpyxl - pandas - pandoc - pandocfilters - panel - pip - plotly - polars - psycopg2 - pyarrow - python-kaleido - python=3.11 - scipy - shapely - sqlalchemy - tabulate - tqdm - pqdm - geographiclib - pytest - pip: - osrm-py==0.5 ```
  1. Open a new Interactive Window via the command palette (Jupyter: Create Interactive Window)
  2. Select the kernel created in step 2
  3. Run x: int = "str" in the interactive window
  4. Open the Problems panel

image

Below are my overall VS Code user settings. As you can see I've tried excluding the interactive window from Pylance analysis through the key python.analysis.exclude, but that does not seem to work (or I'm using the wrong search string here).

VS Code settings ```json { "[python]": { "editor.defaultFormatter": "ms-python.black-formatter", "editor.formatOnSave": true, "editor.codeActionsOnSave": { "source.organizeImports": "explicit" } }, "autoDocstring.docstringFormat": "numpy", "black-formatter.args": [ "--line-length", "100" ], "black-formatter.importStrategy": "useBundled", "debug.focusEditorOnBreak": false, "debug.openDebug": "neverOpen", "diffEditor.experimental.showMoves": true, "editor.acceptSuggestionOnCommitCharacter": false, "editor.acceptSuggestionOnEnter": "off", "editor.accessibilitySupport": "off", "editor.minimap.enabled": false, "editor.padding.bottom": 300, "editor.quickSuggestionsDelay": 50, "editor.scrollBeyondLastLine": false, "editor.snippetSuggestions": "none", "explorer.confirmDelete": false, "explorer.confirmDragAndDrop": false, "explorer.sortOrder": "type", "extensions.ignoreRecommendations": true, "flake8.args": [ "--max-line-length=100", "--ignore=E712,W503" ], "git.autofetch": true, "git.confirmSync": false, "git.inputValidationSubjectLength": null, "git.suggestSmartCommit": false, "isort.args": [ "--profile", "black" ], "isort.serverEnabled": false, "jupyter.askForKernelRestart": false, "jupyter.interactiveWindow.textEditor.executeSelection": true, "jupyter.widgetScriptSources": [ "jsdelivr.com", "unpkg.com" ], "mergeEditor.diffAlgorithm": "legacy", "notebook.codeActionsOnSave": { "source.organizeImports": true }, "notebook.diff.ignoreMetadata": true, "notebook.diff.ignoreOutputs": true, "notebook.formatOnSave.enabled": true, "powershell.promptToUpdatePowerShell": false, "python.analysis.autoFormatStrings": true, "python.analysis.autoImportCompletions": false, "python.analysis.completeFunctionParens": true, "python.analysis.diagnosticSeverityOverrides": { "reportOptionalMemberAccess": "none" }, "python.analysis.exclude": [ "Interactive*" ], "python.analysis.extraPaths": [], "python.analysis.fixAll": [ "source.unusedImports" ], "python.analysis.packageIndexDepths": [ { "name": "imb", "depth": 2 }, { "name": "sklearn", "depth": 2 }, { "name": "matplotlib", "depth": 2 }, { "name": "scipy", "depth": 2 }, { "name": "django", "depth": 2 }, { "name": "flask", "depth": 2 }, { "name": "fastapi", "depth": 2 } ], "python.formatting.provider": "none", "terminal.integrated.commandsToSkipShell": [ "matlab.interrupt" ], "window.commandCenter": false, "workbench.startupEditor": "none" } ```
debonte commented 7 months ago

Oh, sorry, I was actually reproing this behavior with my example above, but I assumed that the diagnostic position would be underlined with a red squiggly in the Interactive Window. It was not, but it still appears in the Problems pane.

heejaechang commented 1 day ago

this also feels like it should be handled by jupyter extension?

debonte commented 1 day ago

this also feels like it should be handled by jupyter extension?

Yeah, if it still repros we should transfer it to them. Seems like this was missed in https://github.com/microsoft/vscode-jupyter/issues/8289 or a regression.

debonte commented 22 hours ago

This issue still repros. Transferring to vscode-jupyter.

Jupyter: v2024.11.2024103001 (pre-release) Python: v2024.19.2024103001 (pre-release) Pylance: v2024.10.103 (pre-release) VS Code: 1.96.0-insider

debonte commented 20 hours ago

Chatted with Don about this. The code that suppressed diagnostics in https://github.com/microsoft/vscode-jupyter/issues/8289 was in the jupyter-lsp-middleware which we no longer use. Also, he felt that the decision of whether to suppress diagnostics in the IW should be handled per language. So:

  1. We need to decide if we really want to suppress diagnostics in the IW -- not return them at all.
  2. If we return diagnostics, we need to understand why the squiggles are not appearing.
  3. If we return diagnostics, we need to ensure that they can be suppressed by users via the ignore config setting.
luabud commented 2 hours ago

I think it's fair to display diagnostics on the input box only, but not on executed blocks/cells as one can't go back to fix issues.

3 is also a great point, I'm not sure what would be the value we'd support in this case though. I'm also unsure if we should handle IW and the Native REPL differently?

cc @cwebster-99