forked from VimPlug/jedi
Make ImplicitNamespaceContext a bit cleaner
This commit is contained in:
@@ -1,8 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
|
|
||||||
from jedi._compatibility import use_metaclass
|
from jedi.evaluate.cache import evaluator_method_cache
|
||||||
from jedi.evaluate.cache import evaluator_method_cache, CachedMetaClass
|
|
||||||
from jedi.evaluate import imports
|
from jedi.evaluate import imports
|
||||||
from jedi.evaluate.filters import DictFilter, AbstractNameDefinition
|
from jedi.evaluate.filters import DictFilter, AbstractNameDefinition
|
||||||
from jedi.evaluate.base_context import NO_CONTEXTS, TreeContext
|
from jedi.evaluate.base_context import NO_CONTEXTS, TreeContext
|
||||||
@@ -24,17 +23,18 @@ class ImplicitNSName(AbstractNameDefinition):
|
|||||||
return self.implicit_ns_context
|
return self.implicit_ns_context
|
||||||
|
|
||||||
|
|
||||||
class ImplicitNamespaceContext(use_metaclass(CachedMetaClass, TreeContext)):
|
class ImplicitNamespaceContext(TreeContext):
|
||||||
"""
|
"""
|
||||||
Provides support for implicit namespace packages
|
Provides support for implicit namespace packages
|
||||||
"""
|
"""
|
||||||
api_type = 'module'
|
api_type = 'module'
|
||||||
parent_context = None
|
parent_context = None
|
||||||
|
|
||||||
def __init__(self, evaluator, fullname):
|
def __init__(self, evaluator, fullname, paths):
|
||||||
super(ImplicitNamespaceContext, self).__init__(evaluator, parent_context=None)
|
super(ImplicitNamespaceContext, self).__init__(evaluator, parent_context=None)
|
||||||
self.evaluator = evaluator
|
self.evaluator = evaluator
|
||||||
self.fullname = fullname
|
self._fullname = fullname
|
||||||
|
self.paths = paths
|
||||||
|
|
||||||
def get_filters(self, search_global, until_position=None, origin_scope=None):
|
def get_filters(self, search_global, until_position=None, origin_scope=None):
|
||||||
yield DictFilter(self._sub_modules_dict())
|
yield DictFilter(self._sub_modules_dict())
|
||||||
@@ -51,7 +51,7 @@ class ImplicitNamespaceContext(use_metaclass(CachedMetaClass, TreeContext)):
|
|||||||
def py__package__(self):
|
def py__package__(self):
|
||||||
"""Return the fullname
|
"""Return the fullname
|
||||||
"""
|
"""
|
||||||
return self.fullname
|
return self._fullname
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def py__path__(self):
|
def py__path__(self):
|
||||||
@@ -61,8 +61,7 @@ class ImplicitNamespaceContext(use_metaclass(CachedMetaClass, TreeContext)):
|
|||||||
def _sub_modules_dict(self):
|
def _sub_modules_dict(self):
|
||||||
names = {}
|
names = {}
|
||||||
|
|
||||||
paths = self.paths
|
file_names = chain.from_iterable(os.listdir(path) for path in self.paths)
|
||||||
file_names = chain.from_iterable(os.listdir(path) for path in paths)
|
|
||||||
mods = [
|
mods = [
|
||||||
file_name.rpartition('.')[0] if '.' in file_name else file_name
|
file_name.rpartition('.')[0] if '.' in file_name else file_name
|
||||||
for file_name in file_names
|
for file_name in file_names
|
||||||
|
|||||||
@@ -380,9 +380,11 @@ class Importer(object):
|
|||||||
|
|
||||||
if isinstance(module_path, ImplicitNSInfo):
|
if isinstance(module_path, ImplicitNSInfo):
|
||||||
from jedi.evaluate.context.namespace import ImplicitNamespaceContext
|
from jedi.evaluate.context.namespace import ImplicitNamespaceContext
|
||||||
fullname, paths = module_path.name, module_path.paths
|
module = ImplicitNamespaceContext(
|
||||||
module = ImplicitNamespaceContext(self._evaluator, fullname=fullname)
|
self._evaluator,
|
||||||
module.paths = paths
|
fullname=module_path.name,
|
||||||
|
paths=module_path.paths,
|
||||||
|
)
|
||||||
elif module_file is not None or module_path.endswith(('.py', '.zip', '.egg')):
|
elif module_file is not None or module_path.endswith(('.py', '.zip', '.egg')):
|
||||||
module = _load_module(self._evaluator, module_path, code, sys_path, parent_module)
|
module = _load_module(self._evaluator, module_path, code, sys_path, parent_module)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user