forked from VimPlug/jedi
Fix some issues with usages and imports.
This commit is contained in:
@@ -9,15 +9,14 @@ def usages(evaluator, definition_names, mods):
|
||||
"""
|
||||
:param definitions: list of Name
|
||||
"""
|
||||
def compare_array(definitions):
|
||||
def compare_array(definition_names):
|
||||
""" `definitions` are being compared by module/start_pos, because
|
||||
sometimes the id's of the objects change (e.g. executions).
|
||||
"""
|
||||
result = []
|
||||
for d in definitions:
|
||||
module = d.get_root_context()
|
||||
result.append((module, d.start_pos))
|
||||
return result
|
||||
return [
|
||||
(d.get_root_context(), d.start_pos)
|
||||
for d in definition_names
|
||||
]
|
||||
|
||||
search_name = list(definition_names)[0].string_name
|
||||
compare_definitions = compare_array(definition_names)
|
||||
@@ -35,6 +34,7 @@ def usages(evaluator, definition_names, mods):
|
||||
# (because goto might return that import name).
|
||||
compare_definitions += compare_array([name])
|
||||
else:
|
||||
# compiled objects
|
||||
definition_names.add(m.name)
|
||||
|
||||
return [classes.Definition(evaluator, n) for n in definition_names]
|
||||
|
||||
@@ -15,7 +15,6 @@ import imp
|
||||
import os
|
||||
import pkgutil
|
||||
import sys
|
||||
from itertools import chain
|
||||
|
||||
from jedi._compatibility import find_module, unicode
|
||||
from jedi import debug
|
||||
@@ -171,30 +170,40 @@ class ImportName(AbstractNameDefinition):
|
||||
start_pos = (1, 0)
|
||||
|
||||
def __init__(self, parent_module, string_name):
|
||||
self.parent_context = parent_module
|
||||
self.parent_module = parent_module
|
||||
self.string_name = string_name
|
||||
|
||||
def infer(self):
|
||||
return Importer(
|
||||
self.parent_context.evaluator,
|
||||
self.parent_module.evaluator,
|
||||
[self.string_name],
|
||||
self.parent_context,
|
||||
self.parent_module,
|
||||
).follow()
|
||||
|
||||
def get_root_context(self):
|
||||
# Not sure if this is correct.
|
||||
return self.parent_context.get_root_context()
|
||||
|
||||
@property
|
||||
def parent_context(self):
|
||||
return self.parent_module
|
||||
|
||||
|
||||
class SubModuleName(ImportName):
|
||||
def infer(self):
|
||||
return Importer(
|
||||
self.parent_context.evaluator,
|
||||
self.parent_module.evaluator,
|
||||
[self.string_name],
|
||||
self.parent_context,
|
||||
self.parent_module,
|
||||
level=1
|
||||
).follow()
|
||||
|
||||
@property
|
||||
def parent_context(self):
|
||||
# This is a bit of a special case. But it seems like it's working well.
|
||||
# Since a SubModuleName is basically a lazy name to a module
|
||||
return next(iter(self.infer()))
|
||||
|
||||
|
||||
class Importer(object):
|
||||
def __init__(self, evaluator, import_path, module_context, level=0):
|
||||
|
||||
@@ -486,7 +486,7 @@ class DictLiteralContext(SequenceLiteralContext):
|
||||
@register_builtin_method('values')
|
||||
def _imitate_values(self):
|
||||
lazy_context = context.LazyKnownContexts(self.dict_values())
|
||||
return FakeSequence(self.evaluator, 'list', [lazy_context])
|
||||
return set([FakeSequence(self.evaluator, 'list', [lazy_context])])
|
||||
|
||||
@register_builtin_method('items')
|
||||
def _imitate_items(self):
|
||||
@@ -532,7 +532,7 @@ class FakeSequence(_FakeArray):
|
||||
return self._context_list
|
||||
|
||||
def py__getitem__(self, index):
|
||||
return self._lazy_context_list[index].infer()
|
||||
return set(self._lazy_context_list[index].infer())
|
||||
|
||||
def py__iter__(self):
|
||||
return self._lazy_context_list
|
||||
|
||||
Reference in New Issue
Block a user