microsoft / pylance-release

Documentation and issues for Pylance
Creative Commons Attribution 4.0 International
1.72k stars 766 forks source link

Wrong behaviour of [Unreachable code] #3302

Closed dongchenyu163 closed 2 years ago

dongchenyu163 commented 2 years ago

Environment data

Issue description

Send np.ndarray type parameters to the np.cross() function can cause the unreachable code after the np.cross()function.

Code Snippet

import numpy as np

# Send np.ndarray type to the np.cross() function can cause the [unreachable code] after the np.cross() function.
x: np.ndarray = np.array([1, 2, 3])
y: np.ndarray = np.array([4, 5, 6])

# Correct behaviour after np.cross function.
# x = [1, 2, 3]
# y = [4, 5, 6]

res = np.cross(x, y)
# The code below is all unreachable!

print("Some code should be executed.")
print("Some code should be executed.")
print("Some code should be executed.")
print("Some code should be executed.")
print("Some code should be executed.")

Repro Steps

Just paste code to vscode.

Expected behavior

image

The code after np.cross() function should not be gray colored and get [unreachable code] warning.

Actual behavior

The code block after np.cross() function can be reached when execution. However, Pylance color them with [unreachable code color] image

Logs

[Info  - 12:08:27 PM] (109463) Pylance language server 2022.9.10 (pyright aba41864) starting
[Info  - 12:08:27 PM] (109463) Server root directory: /home/cookteam/.vscode/extensions/ms-python.vscode-pylance-2022.9.10/dist
[Info  - 12:08:27 PM] (109463) Starting service instance "scripts"
[Info  - 12:08:27 PM] (109463) Notebook support: LSP
[Info  - 12:08:27 PM] (109463) Interactive window support: LSP
[Info  - 12:08:27 PM] (109463) virtual workspace: untitled:Untitled-1.ipynb?jupyter-notebook
[Info  - 12:08:27 PM] (109463) Starting service instance "Untitled-1.ipynb"
[Info  - 12:08:27 PM] (109463) No pyproject.toml file found.
[Info  - 12:08:27 PM] (109463) Setting pythonPath for service "Untitled-1.ipynb": "/bin/python3.8"
[Warn  - 12:08:27 PM] (109463) stubPath typings is not a valid directory.
[Info  - 12:08:27 PM] (109463) Assuming Python version 3.8
[Info  - 12:08:27 PM] (109463) Assuming Python platform Linux
[Info  - 12:08:27 PM] (109463) Search paths for <default>
[Info  - 12:08:27 PM] (109463)   /home/cookteam/.vscode/extensions/ms-python.vscode-pylance-2022.9.10/dist/typeshed-fallback/stdlib
[Info  - 12:08:27 PM] (109463)   typings
[Info  - 12:08:27 PM] (109463)   /home/cookteam/.vscode/extensions/ms-python.vscode-pylance-2022.9.10/dist/typeshed-fallback/stubs/...
[Info  - 12:08:27 PM] (109463)   /home/cookteam/.vscode/extensions/ms-python.vscode-pylance-2022.9.10/dist/bundled/stubs
[Info  - 12:08:27 PM] (109463)   /usr/lib/python3.8
[Info  - 12:08:27 PM] (109463)   /usr/lib/python3.8/lib-dynload
[Info  - 12:08:27 PM] (109463)   /home/cookteam/.local/lib/python3.8/site-packages
[Info  - 12:08:27 PM] (109463)   /usr/local/lib/python3.8/dist-packages
[Info  - 12:08:27 PM] (109463)   /usr/local/lib/python3.8/dist-packages/vrep
[Info  - 12:08:27 PM] (109463)   /usr/local/lib/python3.8/dist-packages/cookteam
[Info  - 12:08:27 PM] (109463)   /usr/local/lib/python3.8/dist-packages/cookteam/Calibration
[Info  - 12:08:27 PM] (109463)   /home/cookteam/Workspace/cookteam/idl
[Info  - 12:08:27 PM] (109463)   /usr/lib/python3/dist-packages
[Info  - 12:08:27 PM] (109463)   /usr/lib/python3/dist-packages/OpenRTM_aist
[Info  - 12:08:27 PM] (109463)   /usr/lib/python3/dist-packages/OpenRTM_aist/utils
[Info  - 12:08:27 PM] (109463)   /usr/lib/python3/dist-packages/OpenRTM_aist/RTM_IDL
[Info  - 12:08:27 PM] (109463)   /usr/lib/python3/dist-packages/omniORB/COS
[Info  - 12:08:27 PM] (109463) Searching for source files
[Info  - 12:08:27 PM] (109463) No source files found.
[Info  - 12:08:27 PM] (109463) No configuration file found.
[Info  - 12:08:27 PM] (109463) No pyproject.toml file found.
[Info  - 12:08:27 PM] (109463) Setting pythonPath for service "scripts": "/bin/python3.8"
[Warn  - 12:08:27 PM] (109463) stubPath /home/cookteam/Workspace/cookteam/scripts/typings is not a valid directory.
[Info  - 12:08:27 PM] (109463) Assuming Python version 3.8
[Info  - 12:08:27 PM] (109463) Assuming Python platform Linux
[Info  - 12:08:27 PM] (109463) Search paths for /home/cookteam/Workspace/cookteam/scripts
[Info  - 12:08:28 PM] (109463)   /home/cookteam/.vscode/extensions/ms-python.vscode-pylance-2022.9.10/dist/typeshed-fallback/stdlib
[Info  - 12:08:28 PM] (109463)   /home/cookteam/Workspace/cookteam/scripts
[Info  - 12:08:28 PM] (109463)   /home/cookteam/Workspace/cookteam/scripts/typings
[Info  - 12:08:28 PM] (109463)   /home/cookteam/.vscode/extensions/ms-python.vscode-pylance-2022.9.10/dist/typeshed-fallback/stubs/...
[Info  - 12:08:28 PM] (109463)   /home/cookteam/.vscode/extensions/ms-python.vscode-pylance-2022.9.10/dist/bundled/stubs
[Info  - 12:08:28 PM] (109463)   /usr/lib/python3.8
[Info  - 12:08:28 PM] (109463)   /usr/lib/python3.8/lib-dynload
[Info  - 12:08:28 PM] (109463)   /home/cookteam/.local/lib/python3.8/site-packages
[Info  - 12:08:28 PM] (109463)   /usr/local/lib/python3.8/dist-packages
[Info  - 12:08:28 PM] (109463)   /usr/local/lib/python3.8/dist-packages/vrep
[Info  - 12:08:28 PM] (109463)   /home/cookteam/Workspace/share/scripts/EnvSetup
[Info  - 12:08:28 PM] (109463)   /home/cookteam/Workspace/share/scripts/EnvSetup/Calibration
[Info  - 12:08:28 PM] (109463)   /home/cookteam/Workspace/cookteam/idl
[Info  - 12:08:28 PM] (109463)   /usr/lib/python3/dist-packages
[Info  - 12:08:28 PM] (109463)   /usr/lib/python3/dist-packages/OpenRTM_aist
[Info  - 12:08:28 PM] (109463)   /usr/lib/python3/dist-packages/OpenRTM_aist/utils
[Info  - 12:08:28 PM] (109463)   /usr/lib/python3/dist-packages/OpenRTM_aist/RTM_IDL
[Info  - 12:08:28 PM] (109463)   /usr/lib/python3/dist-packages/omniORB/COS
[Info  - 12:08:28 PM] (109463) Adding fs watcher for library directories:
 /usr/lib/python3.8
/usr/lib/python3.8/lib-dynload
/home/cookteam/.local/lib/python3.8/site-packages
/usr/local/lib/python3.8/dist-packages
/usr/local/lib/python3.8/dist-packages/vrep
/usr/local/lib/python3.8/dist-packages/cookteam
/usr/local/lib/python3.8/dist-packages/cookteam/Calibration
/home/cookteam/Workspace/cookteam/idl
/usr/lib/python3/dist-packages
/usr/lib/python3/dist-packages/OpenRTM_aist
/usr/lib/python3/dist-packages/OpenRTM_aist/utils
/usr/lib/python3/dist-packages/OpenRTM_aist/RTM_IDL
/usr/lib/python3/dist-packages/omniORB/COS
[Info  - 12:08:28 PM] (109463) Adding fs watcher for directories:
 /home/cookteam/Workspace/cookteam/scripts
[Info  - 12:08:28 PM] (109463) Searching for source files
[Info  - 12:08:28 PM] (109463) Found 47 source files
(109463) [IDX(FG)] index libraries /home/cookteam/Workspace/cookteam/scripts (index) ...
(109463) [IDX(FG)]   read stdlib indices (28ms)
(109463) [IDX(FG)] index libraries /home/cookteam/Workspace/cookteam/scripts (index) [succeed] (28ms)
(109463) [FG] analyzing: Untitled-1.ipynb:pylance-notebook-cell:W0sdW50aXRsZWQ=.py ...
(109463) [FG]   parsing: Untitled-1.ipynb:pylance-notebook-cell:W0sdW50aXRsZWQ=.py (23ms)
(109463) [FG]   parsing: /usr/local/lib/python3.8/dist-packages/IPython/display.py [fs read 0ms] (10ms)
(109463) [FG]   parsing: /home/cookteam/.vscode/extensions/ms-python.vscode-pylance-2022.9.10/dist/typeshed-fallback/stdlib/builtins.pyi [fs read 3ms] (126ms)
(109463) [FG]   binding: /home/cookteam/.vscode/extensions/ms-python.vscode-pylance-2022.9.10/dist/typeshed-fallback/stdlib/builtins.pyi (52ms)
(109463) [FG]   binding: /usr/local/lib/python3.8/dist-packages/IPython/display.py ...
(109463) [FG]     parsing: /usr/local/lib/python3.8/dist-packages/IPython/core/display.py [fs read 2ms] (99ms)
(109463) [FG]     binding: /usr/local/lib/python3.8/dist-packages/IPython/core/display.py (8ms)
(109463) [FG]     parsing: /usr/local/lib/python3.8/dist-packages/IPython/lib/display.py [fs read 0ms] (74ms)
(109463) [FG]     binding: /usr/local/lib/python3.8/dist-packages/IPython/lib/display.py (8ms)
(109463) [FG]   binding: /usr/local/lib/python3.8/dist-packages/IPython/display.py (192ms)
(109463) [FG]   binding: Untitled-1.ipynb:pylance-notebook-cell:W0sdW50aXRsZWQ=.py (0ms)
(109463) [FG]   checking: Untitled-1.ipynb:pylance-notebook-cell:W0sdW50aXRsZWQ=.py (1ms)
(109463) [FG] analyzing: Untitled-1.ipynb:pylance-notebook-cell:W0sdW50aXRsZWQ=.py (405ms)
[Info  - 12:08:28 PM] (109463) Background analysis(1) root directory: /home/cookteam/.vscode/extensions/ms-python.vscode-pylance-2022.9.10/dist
[Info  - 12:08:28 PM] (109463) Background analysis(1) started
(109463) Background analysis message: setConfigOptions
(109463) Background analysis message: setImportResolver
(109463) Background analysis message: ensurePartialStubPackages
(109463) Background analysis message: setTrackedFiles
(109463) Background analysis message: markAllFilesDirty
(109463) Background analysis message: setFileOpened
(109463) Background analysis message: analyze
(109463) [BG(1)] analyzing: /home/cookteam/Workspace/cookteam/scripts/Research/Exp2/bug_report.py ...
(109463) [BG(1)]   parsing: /home/cookteam/Workspace/cookteam/scripts/Research/Exp2/bug_report.py (27ms)
(109463) [BG(1)]   parsing: /home/cookteam/.vscode/extensions/ms-python.vscode-pylance-2022.9.10/dist/typeshed-fallback/stdlib/builtins.pyi [fs read 2ms] (109ms)
(109463) [BG(1)]   binding: /home/cookteam/.vscode/extensions/ms-python.vscode-pylance-2022.9.10/dist/typeshed-fallback/stdlib/builtins.pyi (29ms)
(109463) [BG(1)]   binding: /home/cookteam/Workspace/cookteam/scripts/Research/Exp2/bug_report.py (1ms)
(109463) [BG(1)]   checking: /home/cookteam/Workspace/cookteam/scripts/Research/Exp2/bug_report.py ...
(109463) [BG(1)]     parsing: /home/cookteam/.vscode/extensions/ms-python.vscode-pylance-2022.9.10/dist/typeshed-fallback/stdlib/typing.pyi [fs read 1ms] (33ms)
(109463) [BG(1)]     binding: /home/cookteam/.vscode/extensions/ms-python.vscode-pylance-2022.9.10/dist/typeshed-fallback/stdlib/typing.pyi (10ms)
(109463) [BG(1)]     parsing: /home/cookteam/.vscode/extensions/ms-python.vscode-pylance-2022.9.10/dist/typeshed-fallback/stdlib/typing_extensions.pyi [fs read 0ms] (3ms)
(109463) [BG(1)]     binding: /home/cookteam/.vscode/extensions/ms-python.vscode-pylance-2022.9.10/dist/typeshed-fallback/stdlib/typing_extensions.pyi (1ms)
(109463) [BG(1)]     parsing: /home/cookteam/.vscode/extensions/ms-python.vscode-pylance-2022.9.10/dist/typeshed-fallback/stdlib/_typeshed/__init__.pyi [fs read 1ms] (24ms)
(109463) [BG(1)]     binding: /home/cookteam/.vscode/extensions/ms-python.vscode-pylance-2022.9.10/dist/typeshed-fallback/stdlib/_typeshed/__init__.pyi (2ms)
(109463) [BG(1)]     parsing: /home/cookteam/.vscode/extensions/ms-python.vscode-pylance-2022.9.10/dist/typeshed-fallback/stdlib/abc.pyi [fs read 1ms] (1ms)
(109463) [BG(1)]     binding: /home/cookteam/.vscode/extensions/ms-python.vscode-pylance-2022.9.10/dist/typeshed-fallback/stdlib/abc.pyi (1ms)
(109463) [BG(1)]     parsing: /home/cookteam/.local/lib/python3.8/site-packages/numpy/__init__.pyi [fs read 0ms] (141ms)
(109463) [BG(1)]     binding: /home/cookteam/.local/lib/python3.8/site-packages/numpy/__init__.pyi (26ms)
(109463) [BG(1)]     parsing: /home/cookteam/.local/lib/python3.8/site-packages/numpy/core/multiarray.pyi [fs read 0ms] (14ms)
(109463) [BG(1)]     binding: /home/cookteam/.local/lib/python3.8/site-packages/numpy/core/multiarray.pyi (3ms)
(109463) [BG(1)]     parsing: /home/cookteam/.local/lib/python3.8/site-packages/numpy/typing/__init__.py [fs read 0ms] (9ms)
[Info  - 12:08:28 PM] (109463) Could not resolve source for '._ufunc' in file '/home/cookteam/.local/lib/python3.8/site-packages/numpy/typing/__init__.py'
[Info  - 12:08:28 PM] (109463)   Attempting to resolve relative import
[Info  - 12:08:28 PM] (109463)   Attempting to resolve using root path '/home/cookteam/.local/lib/python3.8/site-packages/numpy/typing'
[Info  - 12:08:28 PM] (109463)   Resolved import with file '/home/cookteam/.local/lib/python3.8/site-packages/numpy/typing/_ufunc.pyi'
[Info  - 12:08:28 PM] (109463)   Attempting to resolve using root path '/home/cookteam/.local/lib/python3.8/site-packages/numpy/typing'
(109463) [BG(1)]     binding: /home/cookteam/.local/lib/python3.8/site-packages/numpy/typing/__init__.py (2ms)
(109463) [BG(1)]     parsing: /home/cookteam/.local/lib/python3.8/site-packages/numpy/typing/_dtype_like.py [fs read 0ms] (1ms)
(109463) [BG(1)]     binding: /home/cookteam/.local/lib/python3.8/site-packages/numpy/typing/_dtype_like.py (1ms)
(109463) [BG(1)]     parsing: /home/cookteam/.local/lib/python3.8/site-packages/numpy/typing/_generic_alias.py [fs read 0ms] (4ms)
(109463) [BG(1)]     binding: /home/cookteam/.local/lib/python3.8/site-packages/numpy/typing/_generic_alias.py (2ms)
(109463) [BG(1)]     parsing: /home/cookteam/.vscode/extensions/ms-python.vscode-pylance-2022.9.10/dist/typeshed-fallback/stdlib/collections/abc.pyi [fs read 0ms] (0ms)
(109463) [BG(1)]     binding: /home/cookteam/.vscode/extensions/ms-python.vscode-pylance-2022.9.10/dist/typeshed-fallback/stdlib/collections/abc.pyi ...
(109463) [BG(1)]       parsing: /home/cookteam/.vscode/extensions/ms-python.vscode-pylance-2022.9.10/dist/typeshed-fallback/stdlib/_collections_abc.pyi [fs read 0ms] (1ms)
(109463) [BG(1)]       binding: /home/cookteam/.vscode/extensions/ms-python.vscode-pylance-2022.9.10/dist/typeshed-fallback/stdlib/_collections_abc.pyi (1ms)
(109463) [BG(1)]     binding: /home/cookteam/.vscode/extensions/ms-python.vscode-pylance-2022.9.10/dist/typeshed-fallback/stdlib/collections/abc.pyi (2ms)
(109463) [BG(1)]     parsing: /home/cookteam/.local/lib/python3.8/site-packages/numpy/typing/_shape.py [fs read 0ms] (0ms)
(109463) [BG(1)]     binding: /home/cookteam/.local/lib/python3.8/site-packages/numpy/typing/_shape.py (0ms)
(109463) [BG(1)]     parsing: /home/cookteam/.vscode/extensions/ms-python.vscode-pylance-2022.9.10/dist/typeshed-fallback/stdlib/enum.pyi [fs read 0ms] (4ms)
(109463) [BG(1)]     binding: /home/cookteam/.vscode/extensions/ms-python.vscode-pylance-2022.9.10/dist/typeshed-fallback/stdlib/enum.pyi (7ms)
(109463) [BG(1)]     parsing: /home/cookteam/.local/lib/python3.8/site-packages/numpy/typing/_array_like.py [fs read 0ms] (1ms)
(109463) [BG(1)]     binding: /home/cookteam/.local/lib/python3.8/site-packages/numpy/typing/_array_like.py (1ms)
(109463) [BG(1)]     parsing: /home/cookteam/.local/lib/python3.8/site-packages/numpy/typing/_nested_sequence.py [fs read 0ms] (2ms)
(109463) [BG(1)]     binding: /home/cookteam/.local/lib/python3.8/site-packages/numpy/typing/_nested_sequence.py (0ms)
(109463) [BG(1)]     parsing: /home/cookteam/.local/lib/python3.8/site-packages/numpy/core/numeric.pyi [fs read 1ms] (5ms)
(109463) [BG(1)]     binding: /home/cookteam/.local/lib/python3.8/site-packages/numpy/core/numeric.pyi (2ms)
(109463) [BG(1)]   checking: /home/cookteam/Workspace/cookteam/scripts/Research/Exp2/bug_report.py (400ms)
(109463) [BG(1)] analyzing: /home/cookteam/Workspace/cookteam/scripts/Research/Exp2/bug_report.py (570ms)
(109463) Background analysis message: getSemanticTokens full
(109463) [BG(1)] getSemanticTokens full at /home/cookteam/Workspace/cookteam/scripts/Research/Exp2/bug_report.py (3ms)
(109463) Background analysis message: getSemanticTokens range
(109463) [BG(1)] getSemanticTokens range 0:0 - 18:0 at /home/cookteam/Workspace/cookteam/scripts/Research/Exp2/bug_report.py (2ms)
(109463) Background analysis message: resumeAnalysis
(109463) [FG] parsing: /home/cookteam/Workspace/cookteam/scripts/Research/Exp2/bug_report.py (14ms)
(109463) [FG] parsing: /home/cookteam/.vscode/extensions/ms-python.vscode-pylance-2022.9.10/dist/typeshed-fallback/stdlib/builtins.pyi [fs read 1ms] (81ms)
(109463) [FG] binding: /home/cookteam/.vscode/extensions/ms-python.vscode-pylance-2022.9.10/dist/typeshed-fallback/stdlib/builtins.pyi (19ms)
(109463) [FG] binding: /home/cookteam/Workspace/cookteam/scripts/Research/Exp2/bug_report.py (13ms)
debonte commented 2 years ago

Duplicate of https://github.com/microsoft/pylance-release/issues/3277