mirror of
https://github.com/davidhalter/jedi.git
synced 2026-05-19 14:59:41 +08:00
Typing does not need to be installed for Jedi to work, vendored typeshed is enough
This commit is contained in:
@@ -161,7 +161,12 @@ class Evaluator(object):
|
|||||||
@evaluator_function_cache()
|
@evaluator_function_cache()
|
||||||
def typing_module(self):
|
def typing_module(self):
|
||||||
typing_module, = self.import_module((u'typing',))
|
typing_module, = self.import_module((u'typing',))
|
||||||
return typing_module.stub_context
|
try:
|
||||||
|
return typing_module.stub_context
|
||||||
|
except AttributeError:
|
||||||
|
# Python 2 and 3.4: In some cases there is no non-stub module,
|
||||||
|
# because the module was not installed with `pip install typing`.
|
||||||
|
return typing_module
|
||||||
|
|
||||||
def reset_recursion_limitations(self):
|
def reset_recursion_limitations(self):
|
||||||
self.recursion_detector = recursion.RecursionDetector()
|
self.recursion_detector = recursion.RecursionDetector()
|
||||||
|
|||||||
@@ -17,8 +17,9 @@ from jedi.evaluate.context.klass import ClassMixin
|
|||||||
from jedi.evaluate.context.module import ModuleMixin
|
from jedi.evaluate.context.module import ModuleMixin
|
||||||
from jedi.evaluate.context.typing import TypingModuleFilterWrapper, \
|
from jedi.evaluate.context.typing import TypingModuleFilterWrapper, \
|
||||||
TypingModuleName
|
TypingModuleName
|
||||||
from jedi.evaluate.compiled.context import CompiledObject, CompiledName
|
from jedi.evaluate.compiled.context import CompiledName
|
||||||
from jedi.evaluate.utils import to_list, safe_property
|
from jedi.evaluate.utils import to_list, safe_property
|
||||||
|
from jedi.evaluate.imports import JediImportError
|
||||||
|
|
||||||
_jedi_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
_jedi_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
_TYPESHED_PATH = os.path.join(_jedi_path, 'third_party', 'typeshed')
|
_TYPESHED_PATH = os.path.join(_jedi_path, 'third_party', 'typeshed')
|
||||||
@@ -130,12 +131,19 @@ class TypeshedPlugin(BasePlugin):
|
|||||||
parent_module_context, = evaluator.import_module(('os',))
|
parent_module_context, = evaluator.import_module(('os',))
|
||||||
return parent_module_context.py__getattribute__('path')
|
return parent_module_context.py__getattribute__('path')
|
||||||
|
|
||||||
context_set = callback(
|
try:
|
||||||
evaluator,
|
context_set = callback(
|
||||||
import_names,
|
evaluator,
|
||||||
parent_module_context,
|
import_names,
|
||||||
sys_path
|
parent_module_context,
|
||||||
)
|
sys_path
|
||||||
|
)
|
||||||
|
except JediImportError:
|
||||||
|
if import_names == ('typing',):
|
||||||
|
# TODO this is also quite ugly, please refactor.
|
||||||
|
context_set = NO_CONTEXTS
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
|
||||||
import_name = import_names[-1]
|
import_name = import_names[-1]
|
||||||
map_ = None
|
map_ = None
|
||||||
|
|||||||
Reference in New Issue
Block a user