forked from VimPlug/jedi
used_names -> get_used_names().
This commit is contained in:
@@ -41,7 +41,7 @@ def usages(evaluator, definition_names, mods):
|
|||||||
definition_names = set(resolve_names(definition_names))
|
definition_names = set(resolve_names(definition_names))
|
||||||
for m in imports.get_modules_containing_name(evaluator, mods, search_name):
|
for m in imports.get_modules_containing_name(evaluator, mods, search_name):
|
||||||
if isinstance(m, ModuleContext):
|
if isinstance(m, ModuleContext):
|
||||||
for name_node in m.tree_node.used_names.get(search_name, []):
|
for name_node in m.tree_node.get_used_names().get(search_name, []):
|
||||||
context = evaluator.create_context(m, name_node)
|
context = evaluator.create_context(m, name_node)
|
||||||
result = evaluator.goto(context, name_node)
|
result = evaluator.goto(context, name_node)
|
||||||
if any(compare_contexts(c1, c2)
|
if any(compare_contexts(c1, c2)
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ def _check_for_setattr(instance):
|
|||||||
|
|
||||||
node = module.tree_node
|
node = module.tree_node
|
||||||
try:
|
try:
|
||||||
stmts = node.used_names['setattr']
|
stmts = node.get_used_names()['setattr']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class CheckAttribute(object):
|
|||||||
|
|
||||||
class CompiledObject(Context):
|
class CompiledObject(Context):
|
||||||
path = None # modules have this attribute - set it to None.
|
path = None # modules have this attribute - set it to None.
|
||||||
used_names = {} # To be consistent with modules.
|
used_names = lambda self: {} # To be consistent with modules.
|
||||||
|
|
||||||
def __init__(self, evaluator, obj, parent_context=None, faked_class=None):
|
def __init__(self, evaluator, obj, parent_context=None, faked_class=None):
|
||||||
super(CompiledObject, self).__init__(evaluator, parent_context)
|
super(CompiledObject, self).__init__(evaluator, parent_context)
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ def get_faked(evaluator, module, obj, name=None, parent_context=None):
|
|||||||
|
|
||||||
faked, fake_module = _get_faked(module and module.obj, obj, name)
|
faked, fake_module = _get_faked(module and module.obj, obj, name)
|
||||||
if module is not None:
|
if module is not None:
|
||||||
module.used_names = fake_module.used_names
|
module.get_used_names = fake_module.get_used_names
|
||||||
return faked
|
return faked
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ def find_syntax_node_name(evaluator, python_object):
|
|||||||
|
|
||||||
# Doesn't always work (e.g. os.stat_result)
|
# Doesn't always work (e.g. os.stat_result)
|
||||||
try:
|
try:
|
||||||
names = module.used_names[name_str]
|
names = module.get_used_names()[name_str]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return None, None
|
return None, None
|
||||||
names = [n for n in names if n.is_definition()]
|
names = [n for n in names if n.is_definition()]
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ def _search_function_executions(evaluator, module_context, funcdef):
|
|||||||
|
|
||||||
def _get_possible_nodes(module_context, func_string_name):
|
def _get_possible_nodes(module_context, func_string_name):
|
||||||
try:
|
try:
|
||||||
names = module_context.tree_node.used_names[func_string_name]
|
names = module_context.tree_node.get_used_names()[func_string_name]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ class AbstractUsedNamesFilter(AbstractFilter):
|
|||||||
|
|
||||||
def __init__(self, context, parser_scope):
|
def __init__(self, context, parser_scope):
|
||||||
self._parser_scope = parser_scope
|
self._parser_scope = parser_scope
|
||||||
self._used_names = self._parser_scope.get_root_node().used_names
|
self._used_names = self._parser_scope.get_root_node().get_used_names()
|
||||||
self.context = context
|
self.context = context
|
||||||
|
|
||||||
def get(self, name):
|
def get(self, name):
|
||||||
|
|||||||
@@ -301,7 +301,7 @@ def _check_flow_information(context, flow, search_name, pos):
|
|||||||
# Check for asserts.
|
# Check for asserts.
|
||||||
module_node = flow.get_root_node()
|
module_node = flow.get_root_node()
|
||||||
try:
|
try:
|
||||||
names = module_node.used_names[search_name.value]
|
names = module_node.get_used_names()[search_name.value]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return None
|
return None
|
||||||
names = reversed([
|
names = reversed([
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ def get_module_names(module, all_scopes):
|
|||||||
Returns a dictionary with name parts as keys and their call paths as
|
Returns a dictionary with name parts as keys and their call paths as
|
||||||
values.
|
values.
|
||||||
"""
|
"""
|
||||||
names = chain.from_iterable(module.used_names.values())
|
names = chain.from_iterable(module.get_used_names().values())
|
||||||
if not all_scopes:
|
if not all_scopes:
|
||||||
# We have to filter all the names that don't have the module as a
|
# We have to filter all the names that don't have the module as a
|
||||||
# parent_scope. There's None as a parent, because nodes in the module
|
# parent_scope. There's None as a parent, because nodes in the module
|
||||||
|
|||||||
@@ -738,7 +738,7 @@ def _check_array_additions(context, sequence):
|
|||||||
added_types = set()
|
added_types = set()
|
||||||
for add_name in search_names:
|
for add_name in search_names:
|
||||||
try:
|
try:
|
||||||
possible_names = module_context.tree_node.used_names[add_name]
|
possible_names = module_context.tree_node.get_used_names()[add_name]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -167,10 +167,8 @@ def _check_module(module_context):
|
|||||||
return sys_path
|
return sys_path
|
||||||
|
|
||||||
try:
|
try:
|
||||||
possible_names = module_context.tree_node.used_names['path']
|
possible_names = module_context.tree_node.get_used_names()['path']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
# module.used_names is MergedNamesDict whose getitem never throws
|
|
||||||
# keyerror, this is superfluous.
|
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
for name, power in get_sys_path_powers(possible_names):
|
for name, power in get_sys_path_powers(possible_names):
|
||||||
|
|||||||
@@ -417,8 +417,7 @@ class Module(Scope):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@property
|
def get_used_names(self):
|
||||||
def used_names(self):
|
|
||||||
if self._used_names is None:
|
if self._used_names is None:
|
||||||
# Don't directly use self._used_names to eliminate a lookup.
|
# Don't directly use self._used_names to eliminate a lookup.
|
||||||
dct = {}
|
dct = {}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ def test_carriage_return_splitting():
|
|||||||
'''))
|
'''))
|
||||||
source = source.replace('\n', '\r\n')
|
source = source.replace('\n', '\r\n')
|
||||||
module = parse(source)
|
module = parse(source)
|
||||||
assert [n.value for lst in module.used_names.values() for n in lst] == ['Foo']
|
assert [n.value for lst in module.get_used_names().values() for n in lst] == ['Foo']
|
||||||
|
|
||||||
|
|
||||||
def test_class_in_docstr():
|
def test_class_in_docstr():
|
||||||
|
|||||||
Reference in New Issue
Block a user