From 49e51f5a1acd7a2d5cf795ff69a94dd529c6a72b Mon Sep 17 00:00:00 2001 From: David Halter Date: Fri, 3 May 2013 20:38:37 +0430 Subject: [PATCH] deprecated api_classes.Completion.word in favor of name --- jedi/__init__.py | 2 +- jedi/api.py | 8 ++++---- jedi/api_classes.py | 23 +++++++++++++++++------ test/run.py | 2 +- test/test_regression.py | 20 ++++++++++---------- 5 files changed, 33 insertions(+), 22 deletions(-) diff --git a/jedi/__init__.py b/jedi/__init__.py index ee18c817..7d74b8c4 100644 --- a/jedi/__init__.py +++ b/jedi/__init__.py @@ -27,7 +27,7 @@ example for the autocompletion feature: [, , ...] >>> 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 diff --git a/jedi/api.py b/jedi/api.py index db8af43b..ec04b26c 100644 --- a/jedi/api.py +++ b/jedi/api.py @@ -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 diff --git a/jedi/api_classes.py b/jedi/api_classes.py index 4e166f66..90cd9391 100644 --- a/jedi/api_classes.py +++ b/jedi/api_classes.py @@ -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): diff --git a/test/run.py b/test/run.py index 5d107cb7..cdda0e6a 100755 --- a/test/run.py +++ b/test/run.py @@ -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): diff --git a/test/test_regression.py b/test/test_regression.py index 4faefd16..f2af7ae5 100755 --- a/test/test_regression.py +++ b/test/test_regression.py @@ -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("""