microsoft / pylance-release

Documentation and issues for Pylance
Creative Commons Attribution 4.0 International
1.68k stars 771 forks source link

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

Open b-a0 opened 3 months ago

b-a0 commented 3 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 3 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 3 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 3 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.