File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
python_packages/jupyter_lsp/jupyter_lsp Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -93,6 +93,9 @@ class PythonModuleSpec(SpecBase):
93
93
def __call__ (self , mgr : LanguageServerManagerAPI ) -> KeyedLanguageServerSpecs :
94
94
spec = __import__ ("importlib" ).util .find_spec (self .python_module )
95
95
96
+ if not spec :
97
+ return {}
98
+
96
99
if not spec .origin : # pragma: no cover
97
100
return {}
98
101
Original file line number Diff line number Diff line change 1
1
import shutil
2
2
3
3
from jupyter_lsp .specs .r_languageserver import RLanguageServer
4
+ from jupyter_lsp .specs .utils import PythonModuleSpec
4
5
5
6
6
7
def test_no_detect (manager ):
@@ -28,3 +29,23 @@ class NonInstalledRServer(RLanguageServer):
28
29
29
30
non_installed_server = NonInstalledRServer ()
30
31
assert non_installed_server .is_installed (cmd = existing_runner ) is False
32
+
33
+
34
+ def test_missing_python_module_spec ():
35
+ """Prevent failure in module detection raising error:
36
+
37
+ Failed to fetch commands from language server spec finder`python-language-server`:
38
+ 'NoneType' object has no attribute 'origin'
39
+ Traceback (most recent call last):
40
+ File "../lib/python3.8/site-packages/jupyter_lsp/manager.py", line 209, in _autodetect_language_servers
41
+ specs = spec_finder(self)
42
+ File "../lib/python3.8/site-packages/jupyter_lsp/specs/utils.py", line 96, in __call__
43
+ if not spec.origin: # pragma: no cover
44
+ AttributeError: 'NoneType' object has no attribute 'origin'
45
+ """
46
+
47
+ class NonInstalledPythonServer (PythonModuleSpec ):
48
+ python_module = "not_installed_python_module"
49
+
50
+ not_installed_server = NonInstalledPythonServer ()
51
+ assert not_installed_server (mgr = None ) == {}
You can’t perform that action at this time.
0 commit comments