Some more _get_definition fixes

This commit is contained in:
Dave Halter
2017-09-02 21:37:23 +02:00
parent ee6d68c3a8
commit 6419534417
3 changed files with 17 additions and 11 deletions

View File

@@ -64,7 +64,7 @@ def resolve_potential_imports(evaluator, definitions):
new = set() new = set()
for d in definitions: for d in definitions:
if isinstance(d, TreeNameDefinition): if isinstance(d, TreeNameDefinition):
imp_or_stmt = d.tree_name.get_definition() imp_or_stmt = d.tree_name._get_definition()
if isinstance(imp_or_stmt, tree.Import): if isinstance(imp_or_stmt, tree.Import):
new |= resolve_potential_imports( new |= resolve_potential_imports(
evaluator, evaluator,

View File

@@ -74,6 +74,14 @@ class ContextName(ContextNameMixin, AbstractTreeName):
class TreeNameDefinition(AbstractTreeName): class TreeNameDefinition(AbstractTreeName):
_API_TYPES = dict(
import_name='module',
import_from='module',
funcdef='function',
param='param',
classdef='class',
)
def infer(self): def infer(self):
# Refactor this, should probably be here. # Refactor this, should probably be here.
from jedi.evaluate.finder import _name_to_types from jedi.evaluate.finder import _name_to_types
@@ -81,14 +89,12 @@ class TreeNameDefinition(AbstractTreeName):
@property @property
def api_type(self): def api_type(self):
definition = self.tree_name.get_definition() definition = self.tree_name._get_definition()
return dict( if definition is None:
import_name='module', definition = self.tree_name.parent
import_from='module', if definition.type == 'dotted_as_name':
funcdef='function', definition = definition.parent
param='param', return self._API_TYPES.get(definition.type, 'statement')
classdef='class',
).get(definition.type, 'statement')
class ParamName(AbstractTreeName): class ParamName(AbstractTreeName):

View File

@@ -358,7 +358,7 @@ class TestGotoAssignments(TestCase):
nms = names('import json as foo', references=True) nms = names('import json as foo', references=True)
assert nms[0].name == 'json' assert nms[0].name == 'json'
assert nms[0].type == 'module' assert nms[0].type == 'module'
assert nms[0]._name.tree_name.get_definition().type == 'import_name' assert nms[0]._name.tree_name.parent.type == 'dotted_as_name'
n = nms[0].goto_assignments()[0] n = nms[0].goto_assignments()[0]
assert n.name == 'json' assert n.name == 'json'
assert n.type == 'module' assert n.type == 'module'
@@ -366,7 +366,7 @@ class TestGotoAssignments(TestCase):
assert nms[1].name == 'foo' assert nms[1].name == 'foo'
assert nms[1].type == 'module' assert nms[1].type == 'module'
assert nms[1]._name.tree_name.get_definition().type == 'import_name' assert nms[1]._name.tree_name.parent.type == 'dotted_as_name'
ass = nms[1].goto_assignments() ass = nms[1].goto_assignments()
assert len(ass) == 1 assert len(ass) == 1
assert ass[0].name == 'json' assert ass[0].name == 'json'