forked from VimPlug/jedi
Undo most of the namespace changes and use module again
Is a module like every other module, because if you import an empty folder foobar it will be available as an object: <module 'foobar' (namespace)>. See #1033.
This commit is contained in:
@@ -153,13 +153,13 @@ class BaseDefinition(object):
|
|||||||
"""The path to a module/class/function definition."""
|
"""The path to a module/class/function definition."""
|
||||||
def to_reverse():
|
def to_reverse():
|
||||||
name = self._name
|
name = self._name
|
||||||
if name.api_type in ('module', 'namespace'):
|
if name.api_type == 'module':
|
||||||
try:
|
try:
|
||||||
name = list(name.infer())[0].name
|
name = list(name.infer())[0].name
|
||||||
except IndexError:
|
except IndexError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if name.api_type in ('module', 'namespace'):
|
if name.api_type in 'module':
|
||||||
module_contexts = name.infer()
|
module_contexts = name.infer()
|
||||||
if module_contexts:
|
if module_contexts:
|
||||||
module_context, = module_contexts
|
module_context, = module_contexts
|
||||||
@@ -521,7 +521,7 @@ class Definition(BaseDefinition):
|
|||||||
"""
|
"""
|
||||||
typ = self.type
|
typ = self.type
|
||||||
tree_name = self._name.tree_name
|
tree_name = self._name.tree_name
|
||||||
if typ in ('function', 'class', 'module', 'instance', 'namespace') or tree_name is None:
|
if typ in ('function', 'class', 'module', 'instance') or tree_name is None:
|
||||||
if typ == 'function':
|
if typ == 'function':
|
||||||
# For the description we want a short and a pythonic way.
|
# For the description we want a short and a pythonic way.
|
||||||
typ = 'def'
|
typ = 'def'
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ from itertools import chain
|
|||||||
from jedi.evaluate.cache import evaluator_method_cache
|
from jedi.evaluate.cache import evaluator_method_cache
|
||||||
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 TreeContext, ContextSet
|
||||||
|
|
||||||
|
|
||||||
class ImplicitNSName(AbstractNameDefinition):
|
class ImplicitNSName(AbstractNameDefinition):
|
||||||
@@ -17,7 +17,7 @@ class ImplicitNSName(AbstractNameDefinition):
|
|||||||
self.string_name = string_name
|
self.string_name = string_name
|
||||||
|
|
||||||
def infer(self):
|
def infer(self):
|
||||||
return NO_CONTEXTS
|
return ContextSet(self.parent_context)
|
||||||
|
|
||||||
def get_root_context(self):
|
def get_root_context(self):
|
||||||
return self.parent_context
|
return self.parent_context
|
||||||
@@ -27,7 +27,10 @@ class ImplicitNamespaceContext(TreeContext):
|
|||||||
"""
|
"""
|
||||||
Provides support for implicit namespace packages
|
Provides support for implicit namespace packages
|
||||||
"""
|
"""
|
||||||
api_type = u'namespace'
|
# Is a module like every other module, because if you import an empty
|
||||||
|
# folder foobar it will be available as an object:
|
||||||
|
# <module 'foobar' (namespace)>.
|
||||||
|
api_type = u'module'
|
||||||
parent_context = None
|
parent_context = None
|
||||||
|
|
||||||
def __init__(self, evaluator, fullname, paths):
|
def __init__(self, evaluator, fullname, paths):
|
||||||
|
|||||||
@@ -419,7 +419,7 @@ class Importer(object):
|
|||||||
|
|
||||||
for context in self.follow():
|
for context in self.follow():
|
||||||
# Non-modules are not completable.
|
# Non-modules are not completable.
|
||||||
if context.api_type not in ('namespace', 'module'): # not a module
|
if context.api_type != 'module': # not a module
|
||||||
continue
|
continue
|
||||||
# namespace packages
|
# namespace packages
|
||||||
if isinstance(context, ModuleContext) and context.py__file__().endswith('__init__.py'):
|
if isinstance(context, ModuleContext) and context.py__file__().endswith('__init__.py'):
|
||||||
|
|||||||
Reference in New Issue
Block a user