A combination of property deleters and the abc.ABCMeta class produces the above error in the Pylance logs when trying to access a property of an instance of the class. I actually discovered this while using the Time class from Astropy, but I realise that's a very complicated class. Hopefully the snippet below makes this clearer.
No error
Problem: "An internal error occurred while performing type checking", see logs below.
[Info - 15:55:10] Pylance language server 2020.7.1 starting
[Info - 15:55:10] Server root directory: /home/martin/.vscode/extensions/ms-python.vscode-pylance-2020.7.1/server
[Info - 15:55:10] Setting pythonPath for service "<default>": "/usr/bin/python3"
[Info - 15:55:10] stubPath typings is not a valid directory.
[Info - 15:55:10] Assuming Python version 3.6
[Info - 15:55:10] Assuming Python platform Linux
[Info - 15:55:10] Searching for source files
[Info - 15:55:10] No source files found.
IntelliCode model /home/martin/.vscode/extensions/visualstudioexptteam.vscodeintellicode-1.2.9/cache/15708AE89896CA5DF1690433B7A8D93D28B7_215F8B4FAB1F4663ABD624559FD205B9
Loading ONNX runtime...
Loaded ONNX runtime. Creating IntelliCode session...
2020-07-15 14:55:10.630057549 [I:onnxruntime:, inference_session.cc:174 ConstructorCommon] Creating and using per session threadpools since use_per_session_threads_ is true
2020-07-15 14:55:10.630517091 [W:onnxruntime:, graph.cc:814 Graph] Initializer embeddings_matrix:0_quantized appears in graph inputs and will not be treated as constant value/weight. This may fail some of the graph optimizations, like const folding. Move it out of graph inputs if there is no need to override it, by either re-generating the model with latest exporter/converter or with the tool onnxruntime/tools/python/remove_initializer_from_input.py.
2020-07-15 14:55:10.630533944 [W:onnxruntime:, graph.cc:814 Graph] Initializer embeddings_matrix:0_scale appears in graph inputs and will not be treated as constant value/weight. This may fail some of the graph optimizations, like const folding. Move it out of graph inputs if there is no need to override it, by either re-generating the model with latest exporter/converter or with the tool onnxruntime/tools/python/remove_initializer_from_input.py.
2020-07-15 14:55:10.630543198 [W:onnxruntime:, graph.cc:814 Graph] Initializer embeddings_matrix:0_zero_point appears in graph inputs and will not be treated as constant value/weight. This may fail some of the graph optimizations, like const folding. Move it out of graph inputs if there is no need to override it, by either re-generating the model with latest exporter/converter or with the tool onnxruntime/tools/python/remove_initializer_from_input.py.
2020-07-15 14:55:10.630565238 [W:onnxruntime:, graph.cc:814 Graph] Initializer fixed_quantization_range_uint8 appears in graph inputs and will not be treated as constant value/weight. This may fail some of the graph optimizations, like const folding. Move it out of graph inputs if there is no need to override it, by either re-generating the model with latest exporter/converter or with the tool onnxruntime/tools/python/remove_initializer_from_input.py.
2020-07-15 14:55:10.630572752 [W:onnxruntime:, graph.cc:814 Graph] Initializer fixed_zero appears in graph inputs and will not be treated as constant value/weight. This may fail some of the graph optimizations, like const folding. Move it out of graph inputs if there is no need to override it, by either re-generating the model with latest exporter/converter or with the tool onnxruntime/tools/python/remove_initializer_from_input.py.
2020-07-15 14:55:10.631386163 [I:onnxruntime:, inference_session.cc:830 Initialize] Initializing session.
2020-07-15 14:55:10.631401230 [I:onnxruntime:, inference_session.cc:848 Initialize] Adding default CPU execution provider.
2020-07-15 14:55:10.632458538 [I:onnxruntime:, reshape_fusion.cc:37 ApplyImpl] Total fused reshape node count: 0
2020-07-15 14:55:10.632797834 [I:onnxruntime:, reshape_fusion.cc:37 ApplyImpl] Total fused reshape node count: 0
2020-07-15 14:55:10.633824886 [V:onnxruntime:, inference_session.cc:671 TransformGraph] Node placements
2020-07-15 14:55:10.633837746 [V:onnxruntime:, inference_session.cc:673 TransformGraph] All nodes have been placed on [CPUExecutionProvider].
2020-07-15 14:55:10.633873744 [I:onnxruntime:, session_state.cc:25 SetGraph] SaveMLValueNameIndexMapping
2020-07-15 14:55:10.633977172 [I:onnxruntime:, session_state.cc:70 SetGraph] Done saving OrtValue mappings.
2020-07-15 14:55:10.634601250 [I:onnxruntime:, session_state_initializer.cc:178 SaveInitializedTensors] Saving initialized tensors.
2020-07-15 14:55:10.661032241 [I:onnxruntime:, session_state_initializer.cc:223 SaveInitializedTensors] Done saving initialized tensors
2020-07-15 14:55:10.663214588 [I:onnxruntime:, inference_session.cc:919 Initialize] Session successfully initialized.
Created IntelliCode session.
[Info - 15:55:10] Background analysis root directory: /home/martin/.vscode/extensions/ms-python.vscode-pylance-2020.7.1/server
[Info - 15:55:10] Background analysis started
[BG] analyzing: /home/martin/test2.py ...
[BG] parsing: /home/martin/test2.py (85ms)
[BG] parsing: /home/martin/.vscode/extensions/ms-python.vscode-pylance-2020.7.1/server/typeshed-fallback/stdlib/2and3/builtins.pyi (166ms)
[BG] binding: /home/martin/.vscode/extensions/ms-python.vscode-pylance-2020.7.1/server/typeshed-fallback/stdlib/2and3/builtins.pyi (86ms)
[BG] binding: /home/martin/test2.py (3ms)
[BG] checking: /home/martin/test2.py ...
[BG] parsing: /home/martin/.vscode/extensions/ms-python.vscode-pylance-2020.7.1/server/typeshed-fallback/stdlib/3/abc.pyi (8ms)
[BG] binding: /home/martin/.vscode/extensions/ms-python.vscode-pylance-2020.7.1/server/typeshed-fallback/stdlib/3/abc.pyi (1ms)
[BG] parsing: /home/martin/.vscode/extensions/ms-python.vscode-pylance-2020.7.1/server/typeshed-fallback/stdlib/3/typing.pyi (55ms)
[BG] binding: /home/martin/.vscode/extensions/ms-python.vscode-pylance-2020.7.1/server/typeshed-fallback/stdlib/3/typing.pyi (16ms)
[Error - 15:55:11] An internal error occurred while while performing type checking for /home/martin/test2.py: TypeError: Cannot read property 'category' of undefined
at $t (/home/martin/.vscode/extensions/ms-python.vscode-pylance-2020.7.1/server/pyright.bundle.js:1:307871)
at qt (/home/martin/.vscode/extensions/ms-python.vscode-pylance-2020.7.1/server/pyright.bundle.js:1:305811)
at /home/martin/.vscode/extensions/ms-python.vscode-pylance-2020.7.1/server/pyright.bundle.js:1:304752
at Wt (/home/martin/.vscode/extensions/ms-python.vscode-pylance-2020.7.1/server/pyright.bundle.js:1:305039)
at $t (/home/martin/.vscode/extensions/ms-python.vscode-pylance-2020.7.1/server/pyright.bundle.js:1:310097)
at Gt (/home/martin/.vscode/extensions/ms-python.vscode-pylance-2020.7.1/server/pyright.bundle.js:1:307557)
at $t (/home/martin/.vscode/extensions/ms-python.vscode-pylance-2020.7.1/server/pyright.bundle.js:1:307959)
at Xt (/home/martin/.vscode/extensions/ms-python.vscode-pylance-2020.7.1/server/pyright.bundle.js:1:315783)
at Jt (/home/martin/.vscode/extensions/ms-python.vscode-pylance-2020.7.1/server/pyright.bundle.js:1:315366)
at Ce (/home/martin/.vscode/extensions/ms-python.vscode-pylance-2020.7.1/server/pyright.bundle.js:1:218159)
[BG] checking: /home/martin/test2.py (130ms)
[BG] analyzing: /home/martin/test2.py (473ms)
[Error - 15:55:11] Error performing analysis: TypeError: Cannot read property 'category' of undefined
at $t (/home/martin/.vscode/extensions/ms-python.vscode-pylance-2020.7.1/server/pyright.bundle.js:1:307871)
at qt (/home/martin/.vscode/extensions/ms-python.vscode-pylance-2020.7.1/server/pyright.bundle.js:1:305811)
at /home/martin/.vscode/extensions/ms-python.vscode-pylance-2020.7.1/server/pyright.bundle.js:1:304752
at Wt (/home/martin/.vscode/extensions/ms-python.vscode-pylance-2020.7.1/server/pyright.bundle.js:1:305039)
at $t (/home/martin/.vscode/extensions/ms-python.vscode-pylance-2020.7.1/server/pyright.bundle.js:1:310097)
at Gt (/home/martin/.vscode/extensions/ms-python.vscode-pylance-2020.7.1/server/pyright.bundle.js:1:307557)
at $t (/home/martin/.vscode/extensions/ms-python.vscode-pylance-2020.7.1/server/pyright.bundle.js:1:307959)
at Xt (/home/martin/.vscode/extensions/ms-python.vscode-pylance-2020.7.1/server/pyright.bundle.js:1:315783)
at Jt (/home/martin/.vscode/extensions/ms-python.vscode-pylance-2020.7.1/server/pyright.bundle.js:1:315366)
at Ce (/home/martin/.vscode/extensions/ms-python.vscode-pylance-2020.7.1/server/pyright.bundle.js:1:218159)
Trying to hover over the instance or property gives the following extra readout with the same error:
[Error - 15:55:59] Request textDocument/hover failed.
Message: Request textDocument/hover failed with message: Cannot read property 'category' of undefined
Code: -32603
The errors are very easy to produce under normal conditions if Astropy is installed:
from astropy.time import Time
time = Time('2020-01-01 00:00:00')
print(time.unix)
Delving into Astropy I eventually settled on this basic example that creates the errors above:
import abc
class MyClass(metaclass=abc.ABCMeta):
def __init__(self, value=None):
self._cache = {'value': value}
@property
def cache(self):
return self._cache
@cache.deleter
def cache(self):
self._cache = {key: None for key in self._cache}
def __getattr__(self, attr):
cache = self.cache
if attr in cache:
return cache[attr]
else:
return self.__getattribute__(attr)
myclass = MyClass('test')
print(myclass.value)
del myclass.cache
print(myclass.value)
I have no idea why the combination of the property deleter and the ABCMeta class produces the above errors, but hopefully that snipped is a start for someone to have a look into this.
@bschnurr, this is a crash in the heart of the type checker, so I'll take it.
Thanks for the reporting the bug. Your simplified example was very helpful. This will be fixed in an upcoming version of Pylance.
This didn't make it into 2020.7.2 (fixed just as we were releasing), but will likely be in the next one.
This issue has been fixed in version 2020.7.3, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/master/CHANGELOG.md#202073-21-july-2020
Most helpful comment
This didn't make it into 2020.7.2 (fixed just as we were releasing), but will likely be in the next one.