mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 14:34:31 +08:00
deprecated api_classes.Completion.word in favor of name
This commit is contained in:
@@ -27,7 +27,7 @@ example for the autocompletion feature:
|
|||||||
[<Completion: date>, <Completion: datetime>, ...]
|
[<Completion: date>, <Completion: datetime>, ...]
|
||||||
>>> print(completions[0].complete)
|
>>> print(completions[0].complete)
|
||||||
te
|
te
|
||||||
>>> print(completions[0].word)
|
>>> print(completions[0].name)
|
||||||
date
|
date
|
||||||
|
|
||||||
As you see Jedi is pretty simple and allows you to concentrate on writing a
|
As you see Jedi is pretty simple and allows you to concentrate on writing a
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ class Script(object):
|
|||||||
self._parser.user_stmt, n):
|
self._parser.user_stmt, n):
|
||||||
new = api_classes.Completion(c, needs_dot,
|
new = api_classes.Completion(c, needs_dot,
|
||||||
len(like), s)
|
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:
|
if k in comp_dct and settings.no_completion_duplicates:
|
||||||
comp_dct[k]._same_name_completions.append(new)
|
comp_dct[k]._same_name_completions.append(new)
|
||||||
else:
|
else:
|
||||||
@@ -163,9 +163,9 @@ class Script(object):
|
|||||||
|
|
||||||
debug.speed('completions end')
|
debug.speed('completions end')
|
||||||
|
|
||||||
return sorted(comps, key=lambda x: (x.word.startswith('__'),
|
return sorted(comps, key=lambda x: (x.name.startswith('__'),
|
||||||
x.word.startswith('_'),
|
x.name.startswith('_'),
|
||||||
x.word.lower()))
|
x.name.lower()))
|
||||||
|
|
||||||
def _prepare_goto(self, goto_path, is_like_search=False):
|
def _prepare_goto(self, goto_path, is_like_search=False):
|
||||||
""" Base for completions, goto and definition. Basically it returns
|
""" Base for completions, goto and definition. Basically it returns
|
||||||
|
|||||||
@@ -310,7 +310,7 @@ class Completion(BaseDefinition):
|
|||||||
def __init__(self, name, needs_dot, like_name_length, base):
|
def __init__(self, name, needs_dot, like_name_length, base):
|
||||||
super(Completion, self).__init__(name.parent, name.start_pos)
|
super(Completion, self).__init__(name.parent, name.start_pos)
|
||||||
|
|
||||||
self.name = name
|
self._name = name
|
||||||
self.needs_dot = needs_dot
|
self.needs_dot = needs_dot
|
||||||
self.like_name_length = like_name_length
|
self.like_name_length = like_name_length
|
||||||
self.base = base
|
self.base = base
|
||||||
@@ -342,10 +342,10 @@ class Completion(BaseDefinition):
|
|||||||
append += '.'
|
append += '.'
|
||||||
if isinstance(self.base, pr.Param):
|
if isinstance(self.base, pr.Param):
|
||||||
append += '='
|
append += '='
|
||||||
return dot + self.name.names[-1][self.like_name_length:] + append
|
return dot + self._name.names[-1][self.like_name_length:] + append
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def word(self):
|
def name(self):
|
||||||
"""
|
"""
|
||||||
Similar to :meth:`Completion.complete`, but return the whole word, for
|
Similar to :meth:`Completion.complete`, but return the whole word, for
|
||||||
example::
|
example::
|
||||||
@@ -354,7 +354,18 @@ class Completion(BaseDefinition):
|
|||||||
|
|
||||||
would return 'isinstance'.
|
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
|
@property
|
||||||
def description(self):
|
def description(self):
|
||||||
@@ -363,7 +374,7 @@ class Completion(BaseDefinition):
|
|||||||
|
|
||||||
.. todo:: return value is just __repr__ of some objects, improve!
|
.. todo:: return value is just __repr__ of some objects, improve!
|
||||||
"""
|
"""
|
||||||
parent = self.name.parent
|
parent = self._name.parent
|
||||||
if parent is None:
|
if parent is None:
|
||||||
return ''
|
return ''
|
||||||
t = self.type
|
t = self.type
|
||||||
@@ -399,7 +410,7 @@ class Completion(BaseDefinition):
|
|||||||
return self._followed_definitions
|
return self._followed_definitions
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<%s: %s>' % (type(self).__name__, self.name)
|
return '<%s: %s>' % (type(self).__name__, self._name)
|
||||||
|
|
||||||
|
|
||||||
class Definition(BaseDefinition):
|
class Definition(BaseDefinition):
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ class IntegrationTestCase(object):
|
|||||||
completions = self.script().completions()
|
completions = self.script().completions()
|
||||||
#import cProfile; cProfile.run('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)))
|
return compare_cb(self, comp_str, set(literal_eval(self.correct)))
|
||||||
|
|
||||||
def run_definition(self, compare_cb):
|
def run_definition(self, compare_cb):
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ class TestRegression(TestBase):
|
|||||||
def test_complete_at_zero(self):
|
def test_complete_at_zero(self):
|
||||||
s = self.completions("str", (1, 3))
|
s = self.completions("str", (1, 3))
|
||||||
assert len(s) == 1
|
assert len(s) == 1
|
||||||
assert list(s)[0].word == 'str'
|
assert list(s)[0].name == 'str'
|
||||||
|
|
||||||
s = self.completions("", (1, 0))
|
s = self.completions("", (1, 0))
|
||||||
assert len(s) > 0
|
assert len(s) > 0
|
||||||
@@ -143,7 +143,7 @@ class TestRegression(TestBase):
|
|||||||
assert len(self.completions("import import", path='')) > 0
|
assert len(self.completions("import import", path='')) > 0
|
||||||
|
|
||||||
# 111
|
# 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 ")
|
assert self.completions("from datetime import ")
|
||||||
|
|
||||||
def assert_call_def(self, call_def, name, index):
|
def assert_call_def(self, call_def, name, index):
|
||||||
@@ -306,16 +306,16 @@ class TestRegression(TestBase):
|
|||||||
s1 = utf8('#-*- coding: utf-8 -*-\nclass Person():\n'
|
s1 = utf8('#-*- coding: utf-8 -*-\nclass Person():\n'
|
||||||
' name = "e"\n\nPerson().name.')
|
' name = "e"\n\nPerson().name.')
|
||||||
completions1 = self.completions(s1)
|
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'
|
s2 = utf8('#-*- coding: utf-8 -*-\nclass Person():\n'
|
||||||
' name = "é"\n\nPerson().name.')
|
' name = "é"\n\nPerson().name.')
|
||||||
completions2 = self.completions(s2)
|
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):
|
def test_os_nowait(self):
|
||||||
""" github issue #45 """
|
""" github issue #45 """
|
||||||
s = self.completions("import os; os.P_")
|
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):
|
def test_follow_definition(self):
|
||||||
""" github issue #45 """
|
""" github issue #45 """
|
||||||
@@ -345,7 +345,7 @@ class TestRegression(TestBase):
|
|||||||
caused problems, sometimes.
|
caused problems, sometimes.
|
||||||
"""
|
"""
|
||||||
c = self.completions("if IndentationErr")
|
c = self.completions("if IndentationErr")
|
||||||
assert c[0].word == 'IndentationError'
|
assert c[0].name == 'IndentationError'
|
||||||
self.assertEqual(c[0].complete, 'or')
|
self.assertEqual(c[0].complete, 'or')
|
||||||
|
|
||||||
def test_docstrings_type_str(self):
|
def test_docstrings_type_str(self):
|
||||||
@@ -356,8 +356,8 @@ class TestRegression(TestBase):
|
|||||||
'''
|
'''
|
||||||
arg."""
|
arg."""
|
||||||
|
|
||||||
words = [c.word for c in self.completions(s)]
|
names = [c.name for c in self.completions(s)]
|
||||||
assert 'join' in words
|
assert 'join' in names
|
||||||
|
|
||||||
def test_docstrings_type_dotted_import(self):
|
def test_docstrings_type_dotted_import(self):
|
||||||
s = """
|
s = """
|
||||||
@@ -366,8 +366,8 @@ class TestRegression(TestBase):
|
|||||||
:type arg: threading.Thread
|
:type arg: threading.Thread
|
||||||
'''
|
'''
|
||||||
arg."""
|
arg."""
|
||||||
words = [c.word for c in self.completions(s)]
|
names = [c.name for c in self.completions(s)]
|
||||||
assert 'start' in words
|
assert 'start' in names
|
||||||
|
|
||||||
def test_no_statement_parent(self):
|
def test_no_statement_parent(self):
|
||||||
source = textwrap.dedent("""
|
source = textwrap.dedent("""
|
||||||
|
|||||||
Reference in New Issue
Block a user