Start replacing get_definitions.

This commit is contained in:
Dave Halter
2017-09-02 17:48:01 +02:00
parent 9cac7462d6
commit 7e19e49200
2 changed files with 16 additions and 14 deletions

View File

@@ -6,10 +6,12 @@ the interesting information about completion and goto operations.
import warnings import warnings
import re import re
from parso.cache import parser_cache
from parso.python.tree import search_ancestor
from jedi._compatibility import u from jedi._compatibility import u
from jedi import settings from jedi import settings
from jedi import common from jedi import common
from parso.cache import parser_cache
from jedi.cache import memoize_method from jedi.cache import memoize_method
from jedi.evaluate import representation as er from jedi.evaluate import representation as er
from jedi.evaluate import instance from jedi.evaluate import instance
@@ -138,9 +140,9 @@ class BaseDefinition(object):
resolve = False resolve = False
if tree_name is not None: if tree_name is not None:
# TODO move this to their respective names. # TODO move this to their respective names.
definition = tree_name.get_definition() definition = tree_name._get_definition()
if definition.type == 'import_from' and \ if definition is not None and definition.type == 'import_from' and \
tree_name in definition.get_defined_names(): tree_name.is_definition():
resolve = True resolve = True
if isinstance(self._name, imports.SubModuleName) or resolve: if isinstance(self._name, imports.SubModuleName) or resolve:
@@ -538,14 +540,14 @@ class Definition(BaseDefinition):
typ = 'def' typ = 'def'
return typ + ' ' + u(self._name.string_name) return typ + ' ' + u(self._name.string_name)
elif typ == 'param': elif typ == 'param':
code = tree_name.get_definition().get_code( code = search_ancestor(tree_name, 'param').get_code(
include_prefix=False, include_prefix=False,
include_comma=False include_comma=False
) )
return typ + ' ' + code return typ + ' ' + code
definition = tree_name.get_definition() definition = tree_name._get_definition() or tree_name
# Remove the prefix, because that's not what we want for get_code # Remove the prefix, because that's not what we want for get_code
# here. # here.
txt = definition.get_code(include_prefix=False) txt = definition.get_code(include_prefix=False)
@@ -630,7 +632,7 @@ class CallSignature(Definition):
if self.params: if self.params:
param_name = self.params[-1]._name param_name = self.params[-1]._name
if param_name.tree_name is not None: if param_name.tree_name is not None:
if param_name.tree_name.get_definition().star_count == 2: if param_name.tree_name._get_definition().star_count == 2:
return i return i
return None return None
@@ -639,7 +641,7 @@ class CallSignature(Definition):
tree_name = param._name.tree_name tree_name = param._name.tree_name
if tree_name is not None: if tree_name is not None:
# *args case # *args case
if tree_name.get_definition().star_count == 1: if tree_name._get_definition().star_count == 1:
return i return i
return None return None
return self._index return self._index

View File

@@ -1,11 +1,11 @@
import pytest import pytest
import jedi import jedi
from jedi._compatibility import py_version from jedi._compatibility import py_version, unicode
def _eval_literal(value): def _eval_literal(code):
def_, = jedi.Script(value).goto_definitions() def_, = jedi.Script(code).goto_definitions()
return def_._name._context.obj return def_._name._context.obj
@@ -25,9 +25,9 @@ def test_rb_strings():
assert _eval_literal('br"asdf"') == b'asdf' assert _eval_literal('br"asdf"') == b'asdf'
obj = _eval_literal('rb"asdf"') obj = _eval_literal('rb"asdf"')
if py_version < 33: if py_version < 33:
# Before Python 3.3 there was a more strict definition in which order # rb is not valid in Python 2. Due to error recovery we just get a
# you could define literals. # string.
assert obj == '' assert obj == 'asdf'
else: else:
assert obj == b'asdf' assert obj == b'asdf'