File tree 1 file changed +15
-12
lines changed
packages/python/plotly/_plotly_utils
1 file changed +15
-12
lines changed Original file line number Diff line number Diff line change 2
2
Stand-alone module to provide information about whether optional deps exist.
3
3
4
4
"""
5
+
5
6
from importlib import import_module
6
7
import logging
7
8
import sys
@@ -19,16 +20,18 @@ def get_module(name, should_load=True):
19
20
:return: (module|None) If import succeeds, the module will be returned.
20
21
21
22
"""
22
- if name in sys .modules :
23
- return sys .modules [name ]
24
23
if not should_load :
25
- return None
26
- if name not in _not_importable :
27
- try :
28
- return import_module (name )
29
- except ImportError :
30
- _not_importable .add (name )
31
- except Exception :
32
- _not_importable .add (name )
33
- msg = f"Error importing optional module { name } "
34
- logger .exception (msg )
24
+ return sys .modules .get (name , None )
25
+
26
+ else :
27
+ if name not in _not_importable :
28
+ try :
29
+ return import_module (name )
30
+ except ImportError :
31
+ _not_importable .add (name )
32
+ except Exception :
33
+ _not_importable .add (name )
34
+ msg = f"Error importing optional module { name } "
35
+ logger .exception (msg )
36
+ else :
37
+ return None
You can’t perform that action at this time.
0 commit comments