Uncategorized

visual studio code – VSCode Python/Pylance Extension is not listing dynamic use of method in references


Problem Description

When i’m using Pylance as Python Language Server it won’t show me references for use of the methods.

I’m passing the TestClass1 Object to the TestClass2 Object.

If i’m going to the classes1.py file and hit ‘Find all References’ i am just getting the reference inside that file (which is the definition of the method).

Faulty references to the method in classes1.py

src/folder1/classes1.py:
class TestClass1():
    def __init__(self, word):
        self.word = word
        
    def print(self):
        print(f"Word: {self.word}")
src/folder2/classes2.py:
class TestClass2:
    def __init__(self, printer):
        self.printer = printer

    def testprint(self):
        self.printer.print()
        
main.py:
from src.folder2.classes2 import TestClass2

printer = TestClass1("Hello World")
def main():
    test = TestClass2(printer)
    test.testprint()

if __name__ == "__main__":
    main()

All filepaths are relative to the project folder.

Project Structure

Debug Log from Python Language Server(Pylance)

2024-01-18 23:45:03.318 [info] [Info  - 11:45:03 PM] (21748) Pylance language server 2023.12.1 (pyright a78e2b10) starting
2024-01-18 23:45:03.318 [info] [Info  - 11:45:03 PM] (21748) Server root directory: C:\Users\mschee1\.vscode\extensions\ms-python.vscode-pylance-2023.12.1\dist
2024-01-18 23:45:03.329 [info] [Info  - 11:45:03 PM] (21748) Starting service instance "test"
2024-01-18 23:45:03.383 [info] (21748) No configuration file found.
2024-01-18 23:45:03.385 [info] (21748) No pyproject.toml file found.
2024-01-18 23:45:03.385 [info] [Info  - 11:45:03 PM] (21748) Setting pythonPath for service "test": "c:\Daten\VSCode\Python\test\.venv\Scripts\python.exe"
2024-01-18 23:45:03.386 [info] [Info  - 11:45:03 PM] (21748) Setting environmentName for service "test": "3.12.0 (.venv venv)"
2024-01-18 23:45:03.522 [info] [Info  - 11:45:03 PM] (21748) Assuming Python version 3.12
2024-01-18 23:45:03.522 [info] (21748) Assuming Python platform Windows
2024-01-18 23:45:03.708 [info] [Info  - 11:45:03 PM] (21748) Search paths for C:\Daten\VSCode\Python\test
2024-01-18 23:45:03.708 [info] [Info  - 11:45:03 PM] (21748)   C:\Users\mschee1\.vscode\extensions\ms-python.vscode-pylance-2023.12.1\dist\typeshed-fallback\stdlib
2024-01-18 23:45:03.709 [info] [Info  - 11:45:03 PM] (21748)   C:\Daten\VSCode\Python\test
2024-01-18 23:45:03.709 [info] [Info  - 11:45:03 PM] (21748)   C:\Daten\VSCode\Python\test\src
2024-01-18 23:45:03.709 [info] [Info  - 11:45:03 PM] (21748)   C:\Daten\VSCode\Python\test\typings
2024-01-18 23:45:03.709 [info] [Info  - 11:45:03 PM] (21748)   C:\Users\mschee1\.vscode\extensions\ms-python.vscode-pylance-2023.12.1\dist\typeshed-fallback\stubs\...
2024-01-18 23:45:03.710 [info] [Info  - 11:45:03 PM] (21748)   C:\Users\mschee1\.vscode\extensions\ms-python.vscode-pylance-2023.12.1\dist\bundled\stubs
2024-01-18 23:45:03.710 [info] [Info  - 11:45:03 PM] (21748)   C:\Daten\Programs\Python312\DLLs
2024-01-18 23:45:03.710 [info] [Info  - 11:45:03 PM] (21748)   C:\Daten\Programs\Python312\Lib
2024-01-18 23:45:03.710 [info] [Info  - 11:45:03 PM] (21748)   C:\Daten\Programs\Python312
2024-01-18 23:45:03.711 [info] [Info  - 11:45:03 PM] (21748)   C:\Daten\VSCode\Python\test\.venv
2024-01-18 23:45:03.711 [info] [Info  - 11:45:03 PM] (21748)   C:\Daten\VSCode\Python\test\.venv\Lib\site-packages
2024-01-18 23:45:03.711 [info] [Info  - 11:45:03 PM] (21748) Adding fs watcher for library directories:
 C:\Daten\Programs\Python312\DLLs
C:\Daten\Programs\Python312\Lib
C:\Daten\Programs\Python312
C:\Daten\VSCode\Python\test\.venv
C:\Daten\VSCode\Python\test\.venv\Lib\site-packages
2024-01-18 23:45:03.712 [info] [Info  - 11:45:03 PM] (21748) Adding fs watcher for directories:
 C:\Daten\VSCode\Python\test
2024-01-18 23:45:03.713 [info] (21748) Searching for source files
2024-01-18 23:45:03.722 [info] [Info  - 11:45:03 PM] (21748) Found 3 source files
2024-01-18 23:45:03.722 [info] (21748) pytest configurations: {"message":"script","classes":["Test"],"files":["test_*.py","*_test.py"],"functions":["test"]}
2024-01-18 23:45:03.723 [info] (21748) pytest configurations: {"message":"script","classes":["Test"],"files":["test_*.py","*_test.py"],"functions":["test"]}
2024-01-18 23:45:03.788 [info] (21748) [FG] parsing: C:\Daten\VSCode\Python\test\src\folder1\classes1.py (17ms)
2024-01-18 23:45:03.885 [info] (21748) [FG] parsing: C:\Users\mschee1\.vscode\extensions\ms-python.vscode-pylance-2023.12.1\dist\typeshed-fallback\stdlib\builtins.pyi [fs read 3ms] (95ms)
2024-01-18 23:45:03.923 [info] (21748) [FG] binding: C:\Users\mschee1\.vscode\extensions\ms-python.vscode-pylance-2023.12.1\dist\typeshed-fallback\stdlib\builtins.pyi (38ms)
2024-01-18 23:45:03.925 [info] (21748) [FG] binding: C:\Daten\VSCode\Python\test\src\folder1\classes1.py (2ms)
2024-01-18 23:45:04.266 [info] FEHLER: Der Prozess "27548" wurde nicht gefunden.

2024-01-18 23:45:04.277 [info] (21748) pytest configurations: {"message":"request cancelled","classes":["Test"],"files":["test_*.py","*_test.py"],"functions":["test"]}
2024-01-18 23:45:04.312 [info] (21748) [IDX(2)] scan packages C:\Daten\VSCode\Python\test ...
2024-01-18 23:45:04.312 [info] (21748) [IDX(2)]   read stdlib indices (43ms)
2024-01-18 23:45:04.375 [info] (21748) [BG(1)] analyzing: C:\Daten\VSCode\Python\test\src\folder1\classes1.py ...
2024-01-18 23:45:04.375 [info] (21748) [BG(1)]   parsing: C:\Daten\VSCode\Python\test\src\folder1\classes1.py (95ms)
2024-01-18 23:45:04.474 [info] (21748) [BG(1)]   parsing: C:\Users\mschee1\.vscode\extensions\ms-python.vscode-pylance-2023.12.1\dist\typeshed-fallback\stdlib\builtins.pyi [fs read 4ms] (98ms)
2024-01-18 23:45:04.503 [info] (21748) [BG(1)]   binding: C:\Users\mschee1\.vscode\extensions\ms-python.vscode-pylance-2023.12.1\dist\typeshed-fallback\stdlib\builtins.pyi (28ms)
2024-01-18 23:45:04.504 [info] (21748) [BG(1)]   binding: C:\Daten\VSCode\Python\test\src\folder1\classes1.py (0ms)
2024-01-18 23:45:04.553 [info] (21748) [BG(1)]   checking: C:\Daten\VSCode\Python\test\src\folder1\classes1.py ...
2024-01-18 23:45:04.553 [info] (21748) [BG(1)]     parsing: C:\Users\mschee1\.vscode\extensions\ms-python.vscode-pylance-2023.12.1\dist\typeshed-fallback\stdlib\typing.pyi [fs read 1ms] (32ms)
2024-01-18 23:45:04.567 [info] (21748) [BG(1)]     binding: C:\Users\mschee1\.vscode\extensions\ms-python.vscode-pylance-2023.12.1\dist\typeshed-fallback\stdlib\typing.pyi (10ms)
2024-01-18 23:45:04.575 [info] (21748) [BG(1)]     parsing: C:\Users\mschee1\.vscode\extensions\ms-python.vscode-pylance-2023.12.1\dist\typeshed-fallback\stdlib\typing_extensions.pyi [fs read 0ms] (5ms)
2024-01-18 23:45:04.578 [info] (21748) [BG(1)]     binding: C:\Users\mschee1\.vscode\extensions\ms-python.vscode-pylance-2023.12.1\dist\typeshed-fallback\stdlib\typing_extensions.pyi (3ms)
2024-01-18 23:45:04.614 [info] (21748) [BG(1)]     parsing: C:\Users\mschee1\.vscode\extensions\ms-python.vscode-pylance-2023.12.1\dist\typeshed-fallback\stdlib\_typeshed\__init__.pyi [fs read 1ms] (11ms)
2024-01-18 23:45:04.614 [info] (21748) [BG(1)]     binding: C:\Users\mschee1\.vscode\extensions\ms-python.vscode-pylance-2023.12.1\dist\typeshed-fallback\stdlib\_typeshed\__init__.pyi (3ms)
2024-01-18 23:45:04.623 [info] (21748) [BG(1)]     parsing: C:\Users\mschee1\.vscode\extensions\ms-python.vscode-pylance-2023.12.1\dist\typeshed-fallback\stdlib\types.pyi [fs read 1ms] (10ms)
2024-01-18 23:45:04.633 [info] (21748) [BG(1)]     binding: C:\Users\mschee1\.vscode\extensions\ms-python.vscode-pylance-2023.12.1\dist\typeshed-fallback\stdlib\types.pyi (10ms)
2024-01-18 23:45:04.644 [info] (21748) [BG(1)]     parsing: C:\Users\mschee1\.vscode\extensions\ms-python.vscode-pylance-2023.12.1\dist\typeshed-fallback\stdlib\abc.pyi [fs read 1ms] (2ms)
2024-01-18 23:45:04.645 [info] (21748) [BG(1)]     binding: C:\Users\mschee1\.vscode\extensions\ms-python.vscode-pylance-2023.12.1\dist\typeshed-fallback\stdlib\abc.pyi (1ms)
2024-01-18 23:45:04.677 [info] (21748) [BG(1)]   checking: C:\Daten\VSCode\Python\test\src\folder1\classes1.py (173ms)
2024-01-18 23:45:04.677 [info] (21748) [BG(1)] analyzing: C:\Daten\VSCode\Python\test\src\folder1\classes1.py (398ms)
2024-01-18 23:45:04.682 [info] (21748) [BG(1)] getSemanticTokens full at C:\Daten\VSCode\Python\test\src\folder1\classes1.py (4ms)
2024-01-18 23:45:04.684 [info] (21748) [BG(1)] getSemanticTokens range 0:0 - 5:35 at C:\Daten\VSCode\Python\test\src\folder1\classes1.py (2ms)
2024-01-18 23:45:04.717 [info] (21748) [FG] parsing: C:\Users\mschee1\.vscode\extensions\ms-python.vscode-pylance-2023.12.1\dist\typeshed-fallback\stdlib\typing.pyi [fs read 1ms] (24ms)
2024-01-18 23:45:04.728 [info] (21748) [FG] binding: C:\Users\mschee1\.vscode\extensions\ms-python.vscode-pylance-2023.12.1\dist\typeshed-fallback\stdlib\typing.pyi (10ms)
2024-01-18 23:45:04.737 [info] (21748) [FG] parsing: C:\Users\mschee1\.vscode\extensions\ms-python.vscode-pylance-2023.12.1\dist\typeshed-fallback\stdlib\typing_extensions.pyi [fs read 1ms] (7ms)
2024-01-18 23:45:04.740 [info] (21748) [FG] binding: C:\Users\mschee1\.vscode\extensions\ms-python.vscode-pylance-2023.12.1\dist\typeshed-fallback\stdlib\typing_extensions.pyi (3ms)
2024-01-18 23:45:04.771 [info] (21748) [FG] parsing: C:\Users\mschee1\.vscode\extensions\ms-python.vscode-pylance-2023.12.1\dist\typeshed-fallback\stdlib\_typeshed\__init__.pyi [fs read 1ms] (9ms)
2024-01-18 23:45:04.771 [info] (21748) [FG] binding: C:\Users\mschee1\.vscode\extensions\ms-python.vscode-pylance-2023.12.1\dist\typeshed-fallback\stdlib\_typeshed\__init__.pyi (2ms)
2024-01-18 23:45:04.781 [info] (21748) [FG] parsing: C:\Users\mschee1\.vscode\extensions\ms-python.vscode-pylance-2023.12.1\dist\typeshed-fallback\stdlib\types.pyi [fs read 1ms] (10ms)
2024-01-18 23:45:04.789 [info] (21748) [FG] binding: C:\Users\mschee1\.vscode\extensions\ms-python.vscode-pylance-2023.12.1\dist\typeshed-fallback\stdlib\types.pyi (7ms)
2024-01-18 23:45:04.795 [info] (21748) [FG] parsing: C:\Users\mschee1\.vscode\extensions\ms-python.vscode-pylance-2023.12.1\dist\typeshed-fallback\stdlib\abc.pyi [fs read 0ms] (1ms)
2024-01-18 23:45:04.797 [info] (21748) [FG] binding: C:\Users\mschee1\.vscode\extensions\ms-python.vscode-pylance-2023.12.1\dist\typeshed-fallback\stdlib\abc.pyi (2ms)
2024-01-18 23:45:04.803 [info] (21748) [BG(1)] indexing: C:\Daten\VSCode\Python\test\main.py ...
2024-01-18 23:45:04.803 [info] (21748) [BG(1)]   parsing: C:\Daten\VSCode\Python\test\main.py [fs read 1ms] (7ms)
2024-01-18 23:45:04.803 [info] (21748) [BG(1)]   binding: C:\Daten\VSCode\Python\test\main.py (0ms)
2024-01-18 23:45:04.804 [info] (21748) [BG(1)] indexing: C:\Daten\VSCode\Python\test\main.py [found 2] (8ms)
2024-01-18 23:45:04.804 [info] (21748) [BG(1)] indexing: C:\Daten\VSCode\Python\test\src\folder1\classes1.py [found 1] (1ms)
2024-01-18 23:45:04.804 [info] (21748) [BG(1)] indexing: C:\Daten\VSCode\Python\test\src\folder2\classes2.py ...
2024-01-18 23:45:04.805 [info] (21748) [BG(1)]   parsing: C:\Daten\VSCode\Python\test\src\folder2\classes2.py [fs read 1ms] (5ms)
2024-01-18 23:45:04.805 [info] (21748) [BG(1)]   binding: C:\Daten\VSCode\Python\test\src\folder2\classes2.py (0ms)
2024-01-18 23:45:04.805 [info] (21748) [BG(1)] indexing: C:\Daten\VSCode\Python\test\src\folder2\classes2.py [found 1] (6ms)
2024-01-18 23:45:04.806 [info] (21748) pytest configurations: {"message":"script","classes":["Test"],"files":["test_*.py","*_test.py"],"functions":["test"]}
2024-01-18 23:45:05.059 [info] (21748) IntelliCode model c:\Users\mschee1\.vscode\extensions\visualstudioexptteam.vscodeintellicode-1.2.30\dist\bundledModels\python_intellisense-members-lstm-pylance
2024-01-18 23:45:05.198 [info] (21748) [IDX(2)] scan packages C:\Daten\VSCode\Python\test (904ms)
2024-01-18 23:45:05.266 [info] (21748) [IDX(2)] index packages C:\Daten\VSCode\Python\test ...
2024-01-18 23:45:05.266 [info] (21748) [IDX(2)]   index execution environment C:\Daten\VSCode\Python\test ...
2024-01-18 23:45:05.267 [info] (21748) [IDX(2)]     indexing: C:\Daten\Programs\Python312\Lib\concurrent\__init__.py [skipped: no '__all__' defined] (1ms)
2024-01-18 23:45:05.267 [info] (21748) [IDX(2)]     indexing: C:\Daten\Programs\Python312\Lib\idlelib\__init__.py [skipped: no '__all__' defined] (0ms)
2024-01-18 23:45:05.267 [info] (21748) [IDX(2)]     indexing: C:\Daten\Programs\Python312\Lib\lib2to3\__init__.py [skipped: no '__all__' defined] (1ms)
2024-01-18 23:45:05.267 [info] (21748) [IDX(2)]     indexing: C:\Daten\Programs\Python312\Lib\pydoc_data\__init__.py [skipped: no '__all__' defined] (0ms)
2024-01-18 23:45:05.268 [info] (21748) [IDX(2)]     indexing: C:\Daten\Programs\Python312\Lib\test\__init__.py [skipped: no '__all__' defined] (1ms)
2024-01-18 23:45:05.268 [info] (21748) [IDX(2)]     indexing: C:\Daten\Programs\Python312\Lib\turtledemo\__init__.py [skipped: no '__all__' defined] (0ms)
2024-01-18 23:45:05.269 [info] (21748) [IDX(2)]     indexing: C:\Daten\Programs\Python312\Lib\urllib\__init__.py [skipped: no '__all__' defined] (1ms)
2024-01-18 23:45:05.270 [info] (21748) [IDX(2)]     indexing: C:\Daten\Programs\Python312\Lib\wsgiref\__init__.py [skipped: no '__all__' defined] (1ms)
2024-01-18 23:45:05.270 [info] (21748) [IDX(2)]     indexing: C:\Daten\Programs\Python312\Lib\xmlrpc\__init__.py [skipped: no '__all__' defined] (0ms)
2024-01-18 23:45:05.271 [info] (21748) [IDX(2)]     indexing: C:\Daten\Programs\Python312\Lib\__phello__\__init__.py [skipped: no '__all__' defined] (1ms)
2024-01-18 23:45:05.271 [info] (21748) [IDX(2)]     indexing: C:\Daten\VSCode\Python\test\.venv\Lib\site-packages\shiboken6_generator\__init__.py [skipped: no '__all__' defined] (0ms)
2024-01-18 23:45:05.272 [info] (21748) [IDX(2)]   index execution environment C:\Daten\VSCode\Python\test [found 23 in 4 files] (18ms)
2024-01-18 23:45:05.272 [info] (21748) [IDX(2)] index packages C:\Daten\VSCode\Python\test [found 23 in 1 exec envs] (23ms)
2024-01-18 23:45:05.771 [info] (21748) Loading ONNX runtime...
2024-01-18 23:45:05.772 [info] (21748) Loaded ONNX runtime. Creating IntelliCode session...
2024-01-18 23:45:05.933 [info] 2024-01-18 23:45:05.924077 [I:onnxruntime:, inference_session.cc:328 operator()] Flush-to-zero and denormal-as-zero are off

2024-01-18 23:45:05.933 [info] 2024-01-18 23:45:05.925846 [I:onnxruntime:, inference_session.cc:336 ConstructorCommon] Creating and using per session threadpools since use_per_session_threads_ is true
2024-01-18 23:45:05.925986 [I:onnxruntime:, inference_session.cc:354 ConstructorCommon] Dynamic block base set to 0

2024-01-18 23:45:06.000 [info] 2024-01-18 23:45:05.992547 [I:onnxruntime:, inference_session.cc:1400 Initialize] Initializing session.

2024-01-18 23:45:06.000 [info] 2024-01-18 23:45:05.992816 [I:onnxruntime:, inference_session.cc:1437 Initialize] Adding default CPU execution provider.

2024-01-18 23:45:06.103 [info] 2024-01-18 23:45:06.095013 [I:onnxruntime:, graph.cc:3556 CleanUnusedInitializersAndNodeArgs] Removing initializer 'pred_embedding_to_output_layer/einsum_1/mul/x:0'. It is no longer used by any node.

2024-01-18 23:45:06.122 [info] 2024-01-18 23:45:06.114061 [I:onnxruntime:, graph.cc:3619 CleanUnusedInitializersAndNodeArgs] Removing NodeArg 'rnn/transpose'. It is no longer used by any node.

2024-01-18 23:45:06.122 [info] 2024-01-18 23:45:06.114316 [I:onnxruntime:, graph.cc:3619 CleanUnusedInitializersAndNodeArgs] Removing NodeArg 'Gather_out0'. It is no longer used by any node.
2024-01-18 23:45:06.114458 [I:onnxruntime:, graph.cc:3619 CleanUnusedInitializersAndNodeArgs] Removing NodeArg 'Transpose_out0'. It is no longer used by any node.

2024-01-18 23:45:06.191 [info] 2024-01-18 23:45:06.183287 [V:onnxruntime:, session_state.cc:1142 VerifyEachNodeIsAssignedToAnEp] Node placements
2024-01-18 23:45:06.183828 [V:onnxruntime:, session_state.cc:1145 VerifyEachNodeIsAssignedToAnEp]  All nodes placed on [CPUExecutionProvider]. Number of nodes: 56

2024-01-18 23:45:06.210 [info] 2024-01-18 23:45:06.202187 [V:onnxruntime:, session_state.cc:126 CreateGraphInfo] SaveMLValueNameIndexMapping

2024-01-18 23:45:06.210 [info] 2024-01-18 23:45:06.202907 [V:onnxruntime:, session_state.cc:172 CreateGraphInfo] Done saving OrtValue mappings.

2024-01-18 23:45:06.211 [info] 2024-01-18 23:45:06.203577 [I:onnxruntime:, allocation_planner.cc:2401 CreateGraphPartitioner] Use DeviceBasedPartition as default

2024-01-18 23:45:06.215 [info] 2024-01-18 23:45:06.207844 [I:onnxruntime:, session_state_utils.cc:201 SaveInitializedTensors] Saving initialized tensors.

2024-01-18 23:45:06.273 [info] 2024-01-18 23:45:06.263265 [I:onnxruntime:, session_state_utils.cc:345 SaveInitializedTensors] Done saving initialized tensors

2024-01-18 23:45:06.287 [info] 2024-01-18 23:45:06.279448 [I:onnxruntime:, inference_session.cc:1774 Initialize] Session successfully initialized.

2024-01-18 23:45:06.288 [info] (21748) Created IntelliCode session.
2024-01-18 23:45:06.289 [info] (21748) Initialize deeplearning succeeded
2024-01-18 23:45:15.387 [info] (21748) [FG] parsing: C:\Daten\VSCode\Python\test\main.py [fs read 0ms] (6ms)
2024-01-18 23:45:15.389 [info] (21748) [FG] binding: C:\Daten\VSCode\Python\test\main.py (1ms)
2024-01-18 23:45:15.395 [info] (21748) [FG] parsing: C:\Daten\VSCode\Python\test\src\folder2\classes2.py [fs read 1ms] (2ms)
2024-01-18 23:45:15.396 [info] (21748) [FG] binding: C:\Daten\VSCode\Python\test\src\folder2\classes2.py (0ms)

When i’m switching to Jedi Language Server it works perfectly fine. But Jedi on the other hand is not really usable because i get an bug when trying to rename symbols. In every file that it refactored the code to the new symbol name it just adds new lines in between the code.

Expected Result from Pylance

I played with some settings but whichever setting i manipulate, nothing has worked.

{
    "python.languageServer": "Pylance",
    "python.analysis.autoImportCompletions": true,
    "python.analysis.typeCheckingMode": "basic"
}



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *