microsoft / pylance-release

Documentation and issues for Pylance
Creative Commons Attribution 4.0 International
1.69k stars 770 forks source link

Invalid python code like `x2+2-3` without red squiggle. #6215

Closed ttSpace closed 1 week ago

ttSpace commented 1 month ago

Environment data

Code Snippet

x2+2-3 

Repro Steps

  1. Open a new python file.
  2. Type invalid python into it. Like x2+2-3 on a single line.
  3. Verify you get a red squiggle.

Expected behavior

Get a red squiggle.

Actual behavior

image

Logs

Output for Python Language Server in the Output panel

``` 2024-08-01 08:52:18.598 [info] (Client) Pylance async client (2024.7.104) started with python extension (2024.13.2024073102) 2024-08-01 08:52:20.933 [info] [Info - 8:52:20 AM] (22824) Server root directory: file:///c%3A/Users/vting/.vscode-insiders/extensions/ms-python.vscode-pylance-2024.7.104/dist 2024-08-01 08:52:20.933 [info] [Info - 8:52:20 AM] (22824) Experimental Pylance language server 2024.7.104 (pyright version 1.1.373, commit ee424479) starting 2024-08-01 08:52:20.933 [info] [Info - 8:52:20 AM] (22824) Starting service instance "Folder5" 2024-08-01 08:52:20.963 [info] [Info - 8:52:20 AM] (22824) Setting pythonPath for service "Folder5": "C:\Python310\python.exe" 2024-08-01 08:52:20.964 [info] [Info - 8:52:20 AM] (22824) Setting environmentName for service "Folder5": "3.10.11 (global)" 2024-08-01 08:52:20.964 [info] [Info - 8:52:20 AM] (22824) No include entries specified; assuming c:\Users\vting\Downloads\Folder5 2024-08-01 08:52:20.965 [info] [Info - 8:52:20 AM] (22824) Auto-excluding **/node_modules 2024-08-01 08:52:20.965 [info] [Info - 8:52:20 AM] (22824) Auto-excluding **/__pycache__ 2024-08-01 08:52:20.965 [info] [Info - 8:52:20 AM] (22824) Auto-excluding **/.* 2024-08-01 08:52:21.118 [info] [Info - 8:52:21 AM] (22824) Assuming Python version 3.10.11.final.0 2024-08-01 08:52:21.347 [info] [Info - 8:52:21 AM] (22824) Found 1 source file 2024-08-01 08:52:21.552 [info] [Info - 8:52:21 AM] (22824) Background analysis(1) root directory: file:///c%3A/Users/vting/.vscode-insiders/extensions/ms-python.vscode-pylance-2024.7.104/dist 2024-08-01 08:52:21.552 [info] [Info - 8:52:21 AM] (22824) Background analysis(1) started 2024-08-01 08:52:21.948 [info] [Info - 8:52:21 AM] (22824) Indexer background runner(2) root directory: file:///c%3A/Users/vting/.vscode-insiders/extensions/ms-python.vscode-pylance-2024.7.104/dist (index) 2024-08-01 08:52:21.948 [info] [Info - 8:52:21 AM] (22824) Indexing(2) started 2024-08-01 08:52:22.600 [info] [Info - 8:52:22 AM] (22824) scanned(2) 20 files over 1 exec env 2024-08-01 08:52:22.938 [info] [Info - 8:52:22 AM] (22824) indexed(2) 9 files over 1 exec env 2024-08-01 08:52:22.957 [info] [Info - 8:52:22 AM] (22824) Indexing finished(2). 2024-08-01 08:52:49.923 [info] (22824) No configuration file found. 2024-08-01 08:52:49.923 [info] (22824) No pyproject.toml file found. 2024-08-01 08:52:49.923 [info] [Info - 8:52:49 AM] (22824) Setting pythonPath for service "Folder5": "C:\Python310\python.exe" 2024-08-01 08:52:49.924 [info] [Info - 8:52:49 AM] (22824) Setting environmentName for service "Folder5": "3.10.11 (global)" 2024-08-01 08:52:49.924 [info] [Info - 8:52:49 AM] (22824) No include entries specified; assuming c:\Users\vting\Downloads\Folder5 2024-08-01 08:52:49.924 [info] [Info - 8:52:49 AM] (22824) Auto-excluding **/node_modules 2024-08-01 08:52:49.924 [info] [Info - 8:52:49 AM] (22824) Auto-excluding **/__pycache__ 2024-08-01 08:52:49.924 [info] [Info - 8:52:49 AM] (22824) Auto-excluding **/.* 2024-08-01 08:52:50.140 [info] [Info - 8:52:50 AM] (22824) Assuming Python version 3.10.11.final.0 2024-08-01 08:52:50.140 [info] (22824) Assuming Python platform Windows 2024-08-01 08:52:50.473 [info] [Info - 8:52:50 AM] (22824) Search paths for file:///c%3A/Users/vting/Downloads/Folder5 2024-08-01 08:52:50.473 [info] [Info - 8:52:50 AM] (22824) c:\Users\vting\.vscode-insiders\extensions\ms-python.vscode-pylance-2024.7.104\dist\typeshed-fallback\stdlib 2024-08-01 08:52:50.474 [info] [Info - 8:52:50 AM] (22824) c:\Users\vting\Downloads\Folder5 2024-08-01 08:52:50.474 [info] [Info - 8:52:50 AM] (22824) c:\Users\vting\Downloads\Folder5\typings 2024-08-01 08:52:50.474 [info] [Info - 8:52:50 AM] (22824) c:\Users\vting\.vscode-insiders\extensions\ms-python.vscode-pylance-2024.7.104\dist\typeshed-fallback\stubs\... 2024-08-01 08:52:50.474 [info] [Info - 8:52:50 AM] (22824) c:\Users\vting\.vscode-insiders\extensions\ms-python.vscode-pylance-2024.7.104\dist\bundled\stubs 2024-08-01 08:52:50.474 [info] [Info - 8:52:50 AM] (22824) c:\Python310\DLLs 2024-08-01 08:52:50.474 [info] [Info - 8:52:50 AM] (22824) c:\Python310\Lib 2024-08-01 08:52:50.474 [info] [Info - 8:52:50 AM] (22824) c:\Python310 2024-08-01 08:52:50.474 [info] [Info - 8:52:50 AM] (22824) c:\Python310\Lib\site-packages 2024-08-01 08:52:50.475 [info] [Info - 8:52:50 AM] (22824) Adding fs watcher for library directories: file:///c%3A/Python310/DLLs file:///c%3A/Python310/Lib file:///c%3A/Python310 file:///c%3A/Python310/Lib/site-packages 2024-08-01 08:52:50.475 [info] [Info - 8:52:50 AM] (22824) Adding fs watcher for directories: file:///c%3A/Users/vting/Downloads/Folder5 2024-08-01 08:52:50.475 [info] (22824) Searching for source files 2024-08-01 08:52:50.478 [info] [Info - 8:52:50 AM] (22824) Found 1 source file 2024-08-01 08:52:50.664 [info] (22824) Attempting to resolve using local imports: __builtins__ 2024-08-01 08:52:50.665 [info] (22824) [BG(1)] analyzing: file:///c%3A/Users/vting/Downloads/Folder5/a.py ... 2024-08-01 08:52:50.665 [info] (22824) [BG(1)] parsing: file:///c%3A/Users/vting/Downloads/Folder5/a.py (103ms) 2024-08-01 08:52:50.737 [info] (22824) [BG(1)] parsing: file:///c%3A/Users/vting/.vscode-insiders/extensions/ms-python.vscode-pylance-2024.7.104/dist/typeshed-fallback/stdlib/builtins.pyi [fs read 1ms] (78ms) 2024-08-01 08:52:50.779 [info] (22824) [BG(1)] binding: file:///c%3A/Users/vting/.vscode-insiders/extensions/ms-python.vscode-pylance-2024.7.104/dist/typeshed-fallback/stdlib/builtins.pyi (30ms) 2024-08-01 08:52:50.779 [info] (22824) [BG(1)] binding: file:///c%3A/Users/vting/Downloads/Folder5/a.py (0ms) 2024-08-01 08:52:50.832 [info] (22824) [BG(1)] checking: file:///c%3A/Users/vting/Downloads/Folder5/a.py ... 2024-08-01 08:52:50.833 [info] (22824) [BG(1)] parsing: file:///c%3A/Users/vting/.vscode-insiders/extensions/ms-python.vscode-pylance-2024.7.104/dist/typeshed-fallback/stdlib/typing.pyi [fs read 1ms] (42ms) 2024-08-01 08:52:50.833 [info] (22824) [BG(1)] binding: file:///c%3A/Users/vting/.vscode-insiders/extensions/ms-python.vscode-pylance-2024.7.104/dist/typeshed-fallback/stdlib/typing.pyi (7ms) 2024-08-01 08:52:50.845 [info] (22824) [BG(1)] parsing: file:///c%3A/Users/vting/.vscode-insiders/extensions/ms-python.vscode-pylance-2024.7.104/dist/typeshed-fallback/stdlib/types.pyi [fs read 0ms] (8ms) 2024-08-01 08:52:50.884 [info] (22824) [BG(1)] binding: file:///c%3A/Users/vting/.vscode-insiders/extensions/ms-python.vscode-pylance-2024.7.104/dist/typeshed-fallback/stdlib/types.pyi (14ms) 2024-08-01 08:52:50.884 [info] (22824) [BG(1)] parsing: file:///c%3A/Users/vting/.vscode-insiders/extensions/ms-python.vscode-pylance-2024.7.104/dist/typeshed-fallback/stdlib/_typeshed/__init__.pyi [fs read 0ms] (7ms) 2024-08-01 08:52:50.884 [info] (22824) [BG(1)] binding: file:///c%3A/Users/vting/.vscode-insiders/extensions/ms-python.vscode-pylance-2024.7.104/dist/typeshed-fallback/stdlib/_typeshed/__init__.pyi (2ms) 2024-08-01 08:52:50.885 [info] (22824) [BG(1)] parsing: file:///c%3A/Users/vting/.vscode-insiders/extensions/ms-python.vscode-pylance-2024.7.104/dist/typeshed-fallback/stdlib/abc.pyi [fs read 1ms] (2ms) 2024-08-01 08:52:50.885 [info] (22824) [BG(1)] binding: file:///c%3A/Users/vting/.vscode-insiders/extensions/ms-python.vscode-pylance-2024.7.104/dist/typeshed-fallback/stdlib/abc.pyi (0ms) 2024-08-01 08:52:50.885 [info] (22824) [BG(1)] checking: file:///c%3A/Users/vting/Downloads/Folder5/a.py (105ms) 2024-08-01 08:52:50.885 [info] [Info - 8:52:50 AM] (22824) Heap stats: total_memory_size=32768MB, total_free_size=18086MB, total_heap_size=52MB, used_heap_size=44MB, cross_worker_used_heap_size=44MB, total_physical_size=52MB, total_available_size=4050MB, heap_size_limit=4096MB 2024-08-01 08:52:50.885 [info] (22824) [BG(1)] analyzing: file:///c%3A/Users/vting/Downloads/Folder5/a.py (318ms) 2024-08-01 08:52:50.894 [info] (22824) [BG(1)] indexing: file:///c%3A/Users/vting/Downloads/Folder5/a.py [found 0] (0ms) 2024-08-01 08:52:50.894 [info] (22824) Indexing Done: file:///c%3A/Users/vting/Downloads/Folder5/a.py 2024-08-01 08:52:51.056 [info] (22824) Attempting to resolve using local imports: __builtins__ 2024-08-01 08:52:51.056 [info] (22824) [FG] parsing: file:///c%3A/Users/vting/Downloads/Folder5/a.py (58ms) 2024-08-01 08:52:51.181 [info] (22824) [FG] parsing: file:///c%3A/Users/vting/.vscode-insiders/extensions/ms-python.vscode-pylance-2024.7.104/dist/typeshed-fallback/stdlib/builtins.pyi [fs read 4ms] (146ms) 2024-08-01 08:52:51.213 [info] (22824) [FG] binding: file:///c%3A/Users/vting/.vscode-insiders/extensions/ms-python.vscode-pylance-2024.7.104/dist/typeshed-fallback/stdlib/builtins.pyi (32ms) 2024-08-01 08:52:51.213 [info] (22824) [FG] binding: file:///c%3A/Users/vting/Downloads/Folder5/a.py (0ms) 2024-08-01 08:52:51.214 [info] (22824) pytest configurations: {"message":"script","classes":["Test"],"files":["test_*.py","*_test.py"],"functions":["test"]} 2024-08-01 08:52:51.356 [info] (22824) [BG(1)] SemanticTokens delta previousResultId:1722502341981 at file:///c%3A/Users/vting/Downloads/Folder5/a.py (1ms) 2024-08-01 08:52:51.398 [info] [Info - 8:52:51 AM] (22824) Indexer background runner(3) root directory: file:///c%3A/Users/vting/.vscode-insiders/extensions/ms-python.vscode-pylance-2024.7.104/dist (index) 2024-08-01 08:52:51.399 [info] [Info - 8:52:51 AM] (22824) Indexing(3) started 2024-08-01 08:52:51.476 [info] (22824) pytest configurations: {"message":"script","classes":["Test"],"files":["test_*.py","*_test.py"],"functions":["test"]} 2024-08-01 08:52:51.641 [info] (22824) [IDX(3)] scan packages file:///c%3A/Users/vting/Downloads/Folder5 ... 2024-08-01 08:52:51.641 [info] (22824) [IDX(3)] read stdlib indices (30ms) 2024-08-01 08:52:52.078 [info] (22824) [IDX(3)] scan packages file:///c%3A/Users/vting/Downloads/Folder5 (468ms) 2024-08-01 08:52:52.079 [info] [Info - 8:52:52 AM] (22824) scanned(3) 20 files over 1 exec env 2024-08-01 08:52:52.419 [info] (22824) [IDX(3)] index packages file:///c%3A/Users/vting/Downloads/Folder5 ... 2024-08-01 08:52:52.419 [info] (22824) [IDX(3)] index execution environment file:///c%3A/Users/vting/Downloads/Folder5 ... 2024-08-01 08:52:52.419 [info] (22824) [IDX(3)] indexing: file:///c%3A/Python310/Lib/concurrent/__init__.py [skipped: no '__all__' defined] (2ms) 2024-08-01 08:52:52.419 [info] (22824) [IDX(3)] indexing: file:///c%3A/Python310/Lib/distutils/__init__.py [skipped: no '__all__' defined] (1ms) 2024-08-01 08:52:52.419 [info] (22824) [IDX(3)] indexing: file:///c%3A/Python310/Lib/idlelib/__init__.py [skipped: no '__all__' defined] (1ms) 2024-08-01 08:52:52.419 [info] (22824) [IDX(3)] indexing: file:///c%3A/Python310/Lib/lib2to3/__init__.py [skipped: no '__all__' defined] (1ms) 2024-08-01 08:52:52.419 [info] (22824) [IDX(3)] indexing: file:///c%3A/Python310/Lib/pydoc_data/__init__.py [skipped: no '__all__' defined] (1ms) 2024-08-01 08:52:52.420 [info] (22824) [IDX(3)] indexing: file:///c%3A/Python310/Lib/test/__init__.py [skipped: no '__all__' defined] (1ms) 2024-08-01 08:52:52.420 [info] (22824) [IDX(3)] indexing: file:///c%3A/Python310/Lib/turtledemo/__init__.py [skipped: no '__all__' defined] (1ms) 2024-08-01 08:52:52.420 [info] (22824) [IDX(3)] indexing: file:///c%3A/Python310/Lib/urllib/__init__.py [skipped: no '__all__' defined] (1ms) 2024-08-01 08:52:52.420 [info] (22824) [IDX(3)] indexing: file:///c%3A/Python310/Lib/wsgiref/__init__.py [skipped: no '__all__' defined] (1ms) 2024-08-01 08:52:52.420 [info] (22824) [IDX(3)] indexing: file:///c%3A/Python310/Lib/xmlrpc/__init__.py [skipped: no '__all__' defined] (1ms) 2024-08-01 08:52:52.420 [info] (22824) [IDX(3)] indexing: file:///c%3A/Python310/Lib/site-packages/tzdata/__init__.py [skipped: no '__all__' defined] (2ms) 2024-08-01 08:52:52.420 [info] (22824) [IDX(3)] index execution environment file:///c%3A/Users/vting/Downloads/Folder5 [found 1522 in 9 files] (26ms) 2024-08-01 08:52:52.420 [info] (22824) [IDX(3)] index packages file:///c%3A/Users/vting/Downloads/Folder5 [found 1522 in 1 exec envs] (86ms) 2024-08-01 08:52:52.420 [info] [Info - 8:52:52 AM] (22824) indexed(3) 9 files over 1 exec env 2024-08-01 08:52:52.445 [info] [Info - 8:52:52 AM] (22824) Indexing finished(3). ```

StellaHuang95 commented 1 month ago

If you go to your settings.json file, do you have typeCheckingMode set to off?

heejaechang commented 1 month ago

@ttSpace I am not sure what you meant by invalid. x2+2-3 looks like syntactically valid code. if you are talking about x2 being used before defined. and you want to make it error rather than warning.

you have 2 choices.

in settings.json, you can either change

"python.analysis.typeCheckingMode" to "basic" or "strict"

or set that specific diagnostic as error with typecheckingmode: off

"python.analysis.diagnosticSeverityOverrides": {
        "reportUndefinedVariable": "error"
    },
ttSpace commented 1 month ago

@StellaHuang95 Yes, the typeCheckingMode is off. BTW, I saw in the document that the default value for this setting is "error".

image

image

StellaHuang95 commented 1 month ago

I see, looks like packages\vscode-pylance\package.json and packages\pyright\packages\vscode-pyright\package.json have inconsistent default value. But I guess that's because pyright's default typeCheckingMode is standard, while pylance's is off.

heejaechang commented 1 week ago

I will close the issue since it works as expected for off mode.