deprecated api_classes.Completion.word in favor of name

This commit is contained in:
David Halter
2013-05-03 20:38:37 +04:30
parent beae920177
commit 49e51f5a1a
5 changed files with 33 additions and 22 deletions

View File

@@ -27,7 +27,7 @@ example for the autocompletion feature:
[<Completion: date>, <Completion: datetime>, ...]
>>> print(completions[0].complete)
te
>>> print(completions[0].word)
>>> print(completions[0].name)
date
As you see Jedi is pretty simple and allows you to concentrate on writing a

View File

@@ -154,7 +154,7 @@ class Script(object):
self._parser.user_stmt, n):
new = api_classes.Completion(c, needs_dot,
len(like), s)
k = (new.word, new.complete) # key
k = (new.name, new.complete) # key
if k in comp_dct and settings.no_completion_duplicates:
comp_dct[k]._same_name_completions.append(new)
else:
@@ -163,9 +163,9 @@ class Script(object):
debug.speed('completions end')
return sorted(comps, key=lambda x: (x.word.startswith('__'),
x.word.startswith('_'),
x.word.lower()))
return sorted(comps, key=lambda x: (x.name.startswith('__'),
x.name.startswith('_'),
x.name.lower()))
def _prepare_goto(self, goto_path, is_like_search=False):
""" Base for completions, goto and definition. Basically it returns

View File

@@ -310,7 +310,7 @@ class Completion(BaseDefinition):
def __init__(self, name, needs_dot, like_name_length, base):
super(Completion, self).__init__(name.parent, name.start_pos)
self.name = name
self._name = name
self.needs_dot = needs_dot
self.like_name_length = like_name_length
self.base = base
@@ -342,10 +342,10 @@ class Completion(BaseDefinition):
append += '.'
if isinstance(self.base, pr.Param):
append += '='
return dot + self.name.names[-1][self.like_name_length:] + append
return dot + self._name.names[-1][self.like_name_length:] + append
@property
def word(self):
def name(self):
"""
Similar to :meth:`Completion.complete`, but return the whole word, for
example::
@@ -354,7 +354,18 @@ class Completion(BaseDefinition):
would return 'isinstance'.
"""
return unicode(self.name.names[-1])
return unicode(self._name.names[-1])
@property
def word(self):
"""
.. deprecated:: 0.6.0
Use :attr:`.name` instead.
.. todo:: Remove!
"""
warnings.warn("Use name instead.", DeprecationWarning)
return self.name
@property
def description(self):
@@ -363,7 +374,7 @@ class Completion(BaseDefinition):
.. todo:: return value is just __repr__ of some objects, improve!
"""
parent = self.name.parent
parent = self._name.parent
if parent is None:
return ''
t = self.type
@@ -399,7 +410,7 @@ class Completion(BaseDefinition):
return self._followed_definitions
def __repr__(self):
return '<%s: %s>' % (type(self).__name__, self.name)
return '<%s: %s>' % (type(self).__name__, self._name)
class Definition(BaseDefinition):

View File

@@ -151,7 +151,7 @@ class IntegrationTestCase(object):
completions = self.script().completions()
#import cProfile; cProfile.run('script.completions()')
comp_str = set([c.word for c in completions])
comp_str = set([c.name for c in completions])
return compare_cb(self, comp_str, set(literal_eval(self.correct)))
def run_definition(self, compare_cb):

View File

@@ -123,7 +123,7 @@ class TestRegression(TestBase):
def test_complete_at_zero(self):
s = self.completions("str", (1, 3))
assert len(s) == 1
assert list(s)[0].word == 'str'
assert list(s)[0].name == 'str'
s = self.completions("", (1, 0))
assert len(s) > 0
@@ -143,7 +143,7 @@ class TestRegression(TestBase):
assert len(self.completions("import import", path='')) > 0
# 111
assert self.completions("from datetime import")[0].word == 'import'
assert self.completions("from datetime import")[0].name == 'import'
assert self.completions("from datetime import ")
def assert_call_def(self, call_def, name, index):
@@ -306,16 +306,16 @@ class TestRegression(TestBase):
s1 = utf8('#-*- coding: utf-8 -*-\nclass Person():\n'
' name = "e"\n\nPerson().name.')
completions1 = self.completions(s1)
assert 'strip' in [c.word for c in completions1]
assert 'strip' in [c.name for c in completions1]
s2 = utf8('#-*- coding: utf-8 -*-\nclass Person():\n'
' name = "é"\n\nPerson().name.')
completions2 = self.completions(s2)
assert 'strip' in [c.word for c in completions2]
assert 'strip' in [c.name for c in completions2]
def test_os_nowait(self):
""" github issue #45 """
s = self.completions("import os; os.P_")
assert 'P_NOWAIT' in [i.word for i in s]
assert 'P_NOWAIT' in [i.name for i in s]
def test_follow_definition(self):
""" github issue #45 """
@@ -345,7 +345,7 @@ class TestRegression(TestBase):
caused problems, sometimes.
"""
c = self.completions("if IndentationErr")
assert c[0].word == 'IndentationError'
assert c[0].name == 'IndentationError'
self.assertEqual(c[0].complete, 'or')
def test_docstrings_type_str(self):
@@ -356,8 +356,8 @@ class TestRegression(TestBase):
'''
arg."""
words = [c.word for c in self.completions(s)]
assert 'join' in words
names = [c.name for c in self.completions(s)]
assert 'join' in names
def test_docstrings_type_dotted_import(self):
s = """
@@ -366,8 +366,8 @@ class TestRegression(TestBase):
:type arg: threading.Thread
'''
arg."""
words = [c.word for c in self.completions(s)]
assert 'start' in words
names = [c.name for c in self.completions(s)]
assert 'start' in names
def test_no_statement_parent(self):
source = textwrap.dedent("""