forked from VimPlug/jedi
Fix all imports inference tests.
This commit is contained in:
@@ -68,7 +68,7 @@ class BaseDefinition(object):
|
|||||||
self._definition = None
|
self._definition = None
|
||||||
|
|
||||||
# generate a path to the definition
|
# generate a path to the definition
|
||||||
self._module = name.parent_context.get_root_context()
|
self._module = name.get_root_context()
|
||||||
if self.in_builtin_module():
|
if self.in_builtin_module():
|
||||||
self.module_path = None
|
self.module_path = None
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import copy
|
import copy
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
|
|
||||||
from jedi.evaluate.filters import AbstractNameDefinition
|
|
||||||
from jedi.parser import tree
|
from jedi.parser import tree
|
||||||
|
|
||||||
|
|
||||||
@@ -158,13 +157,3 @@ class FakeName(tree.Name):
|
|||||||
return super(FakeName, self).is_definition()
|
return super(FakeName, self).is_definition()
|
||||||
else:
|
else:
|
||||||
return self._is_definition
|
return self._is_definition
|
||||||
|
|
||||||
|
|
||||||
class LazyName(AbstractNameDefinition):
|
|
||||||
def __init__(self, name, parent_callback, is_definition=None):
|
|
||||||
# TODO remove is_definition
|
|
||||||
self.string_name = name
|
|
||||||
self._parent_callback = parent_callback
|
|
||||||
|
|
||||||
def infer(self):
|
|
||||||
return self._parent_callback()
|
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ import os
|
|||||||
import pkgutil
|
import pkgutil
|
||||||
import imp
|
import imp
|
||||||
import re
|
import re
|
||||||
from itertools import chain
|
|
||||||
|
|
||||||
from jedi._compatibility import use_metaclass, unicode, Python3Method, is_py3
|
from jedi._compatibility import use_metaclass, unicode, Python3Method, is_py3
|
||||||
from jedi.parser import tree
|
from jedi.parser import tree
|
||||||
@@ -51,7 +50,6 @@ from jedi.evaluate import recursion
|
|||||||
from jedi.evaluate import iterable
|
from jedi.evaluate import iterable
|
||||||
from jedi.evaluate import docstrings
|
from jedi.evaluate import docstrings
|
||||||
from jedi.evaluate import pep0484
|
from jedi.evaluate import pep0484
|
||||||
from jedi.evaluate import helpers
|
|
||||||
from jedi.evaluate import param
|
from jedi.evaluate import param
|
||||||
from jedi.evaluate import flow_analysis
|
from jedi.evaluate import flow_analysis
|
||||||
from jedi.evaluate import imports
|
from jedi.evaluate import imports
|
||||||
@@ -738,7 +736,7 @@ class AnonymousFunctionExecution(FunctionExecutionContext):
|
|||||||
return search_params(self.evaluator, self.parent_context, self.funcdef)
|
return search_params(self.evaluator, self.parent_context, self.funcdef)
|
||||||
|
|
||||||
|
|
||||||
class GlobalName(helpers.FakeName):
|
class GlobalName(object):
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
"""
|
"""
|
||||||
We need to mark global names somehow. Otherwise they are just normal
|
We need to mark global names somehow. Otherwise they are just normal
|
||||||
@@ -748,7 +746,24 @@ class GlobalName(helpers.FakeName):
|
|||||||
super(GlobalName, self).__init__(name.value, name.parent,
|
super(GlobalName, self).__init__(name.value, name.parent,
|
||||||
name.start_pos, is_definition=True)
|
name.start_pos, is_definition=True)
|
||||||
|
|
||||||
|
|
||||||
|
class ModuleAttributeName(AbstractNameDefinition):
|
||||||
|
"""
|
||||||
|
For module attributes like __file__, __str__ and so on.
|
||||||
|
"""
|
||||||
|
def __init__(self, parent_module, string_name):
|
||||||
|
self.parent_context = parent_module
|
||||||
|
self.string_name = string_name
|
||||||
|
|
||||||
|
def infer(self):
|
||||||
|
return compiled.create(self.parent_context.evaluator, str).execute(
|
||||||
|
param.ValuesArguments([])
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class SubModuleName(AbstractNameDefinition):
|
class SubModuleName(AbstractNameDefinition):
|
||||||
|
"""
|
||||||
|
"""
|
||||||
def __init__(self, parent_module, string_name):
|
def __init__(self, parent_module, string_name):
|
||||||
self.parent_context = parent_module
|
self.parent_context = parent_module
|
||||||
self.string_name = string_name
|
self.string_name = string_name
|
||||||
@@ -791,11 +806,8 @@ class ModuleContext(use_metaclass(CachedMetaClass, context.TreeContext, Wrapper)
|
|||||||
yield GlobalNameFilter(self, self.module_node)
|
yield GlobalNameFilter(self, self.module_node)
|
||||||
yield DictFilter(self._sub_modules_dict())
|
yield DictFilter(self._sub_modules_dict())
|
||||||
yield DictFilter(self._module_attributes_dict())
|
yield DictFilter(self._module_attributes_dict())
|
||||||
# TODO
|
|
||||||
'''
|
|
||||||
for star_module in self.star_imports():
|
for star_module in self.star_imports():
|
||||||
yield star_module.names_dict
|
yield next(star_module.get_filters(search_global))
|
||||||
'''
|
|
||||||
|
|
||||||
# I'm not sure if the star import cache is really that effective anymore
|
# I'm not sure if the star import cache is really that effective anymore
|
||||||
# with all the other really fast import caches. Recheck. Also we would need
|
# with all the other really fast import caches. Recheck. Also we would need
|
||||||
@@ -816,14 +828,9 @@ class ModuleContext(use_metaclass(CachedMetaClass, context.TreeContext, Wrapper)
|
|||||||
|
|
||||||
@memoize_default()
|
@memoize_default()
|
||||||
def _module_attributes_dict(self):
|
def _module_attributes_dict(self):
|
||||||
def parent_callback():
|
|
||||||
# Create a string type object (without a defined string in it):
|
|
||||||
return list(self.evaluator.execute(compiled.create(self.evaluator, str)))[0]
|
|
||||||
|
|
||||||
names = ['__file__', '__package__', '__doc__', '__name__']
|
names = ['__file__', '__package__', '__doc__', '__name__']
|
||||||
# All the additional module attributes are strings.
|
# All the additional module attributes are strings.
|
||||||
return dict((n, helpers.LazyName(n, parent_callback, is_definition=True))
|
return dict((n, ModuleAttributeName(self, n)) for n in names)
|
||||||
for n in names)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@memoize_default()
|
@memoize_default()
|
||||||
@@ -923,8 +930,8 @@ class ModuleContext(use_metaclass(CachedMetaClass, context.TreeContext, Wrapper)
|
|||||||
# import hacks.
|
# import hacks.
|
||||||
# ``os.path`` is a hardcoded exception, because it's a
|
# ``os.path`` is a hardcoded exception, because it's a
|
||||||
# ``sys.modules`` modification.
|
# ``sys.modules`` modification.
|
||||||
#if str(self.name) == 'os':
|
# if str(self.name) == 'os':
|
||||||
# names.append(helpers.FakeName('path', parent=self))
|
# names.append(Name('path', parent_context=self))
|
||||||
|
|
||||||
return names
|
return names
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user