mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 14:04:26 +08:00
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."""
|
||||
def to_reverse():
|
||||
name = self._name
|
||||
if name.api_type in ('module', 'namespace'):
|
||||
if name.api_type == 'module':
|
||||
try:
|
||||
name = list(name.infer())[0].name
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
if name.api_type in ('module', 'namespace'):
|
||||
if name.api_type in 'module':
|
||||
module_contexts = name.infer()
|
||||
if module_contexts:
|
||||
module_context, = module_contexts
|
||||
@@ -521,7 +521,7 @@ class Definition(BaseDefinition):
|
||||
"""
|
||||
typ = self.type
|
||||
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':
|
||||
# For the description we want a short and a pythonic way.
|
||||
typ = 'def'
|
||||
|
||||
@@ -4,7 +4,7 @@ from itertools import chain
|
||||
from jedi.evaluate.cache import evaluator_method_cache
|
||||
from jedi.evaluate import imports
|
||||
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):
|
||||
@@ -17,7 +17,7 @@ class ImplicitNSName(AbstractNameDefinition):
|
||||
self.string_name = string_name
|
||||
|
||||
def infer(self):
|
||||
return NO_CONTEXTS
|
||||
return ContextSet(self.parent_context)
|
||||
|
||||
def get_root_context(self):
|
||||
return self.parent_context
|
||||
@@ -27,7 +27,10 @@ class ImplicitNamespaceContext(TreeContext):
|
||||
"""
|
||||
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
|
||||
|
||||
def __init__(self, evaluator, fullname, paths):
|
||||
|
||||
@@ -419,7 +419,7 @@ class Importer(object):
|
||||
|
||||
for context in self.follow():
|
||||
# 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
|
||||
# namespace packages
|
||||
if isinstance(context, ModuleContext) and context.py__file__().endswith('__init__.py'):
|
||||
|
||||
Reference in New Issue
Block a user