From e07625017dad445e5705b194820d9b0dde8008c2 Mon Sep 17 00:00:00 2001 From: David Halter Date: Sun, 11 Aug 2013 23:00:27 +0430 Subject: [PATCH] remove all the deprecation warnings in jedi itself --- jedi/api.py | 6 +++--- jedi/api_classes.py | 12 ++++++------ jedi/refactoring.py | 10 +++++----- test/run.py | 3 +-- test/test_api.py | 7 +++---- test/test_integration_import.py | 2 +- test/test_interpreter.py | 4 ++-- 7 files changed, 21 insertions(+), 23 deletions(-) diff --git a/jedi/api.py b/jedi/api.py index a6d67d57..64231d02 100644 --- a/jedi/api.py +++ b/jedi/api.py @@ -514,7 +514,7 @@ class Script(object): def _sorted_defs(d): # Note: `or ''` below is required because `module_path` could be # None and you can't compare None and str in Python 3. - return sorted(d, key=lambda x: (x.module_path or '', x.start_pos)) + return sorted(d, key=lambda x: (x.module_path or '', x.line, x.column)) class Interpreter(Script): @@ -530,7 +530,7 @@ class Interpreter(Script): >>> from os.path import join >>> namespace = locals() >>> script = Interpreter('join().up', [namespace]) - >>> print(script.complete()[0].word) + >>> print(script.completions()[0].name) upper """ @@ -584,7 +584,7 @@ def preload_module(*modules): """ for m in modules: s = "import %s as x; x." % m - Script(s, 1, len(s), None).complete() + Script(s, 1, len(s), None).completions() def set_debug_function(func_cb=debug.print_to_stdout, warnings=True, diff --git a/jedi/api_classes.py b/jedi/api_classes.py index 9472c4d3..789f7082 100644 --- a/jedi/api_classes.py +++ b/jedi/api_classes.py @@ -98,7 +98,7 @@ class BaseDefinition(object): Here is an example of the value of this attribute. Let's consider the following source. As what is in ``variable`` is unambiguous - to Jedi, :meth:`api.Script.definition` should return a list of + to Jedi, :meth:`api.Script.goto_definitions` should return a list of definition for ``sys``, ``f``, ``C`` and ``x``. >>> from jedi import Script @@ -118,7 +118,7 @@ class BaseDefinition(object): ... ... variable = keyword or f or C or x''' >>> script = Script(source, len(source.splitlines()), 3, 'example.py') - >>> defs = script.definition() + >>> defs = script.goto_definitions() Before showing what is in ``defs``, let's sort it by :attr:`line` so that it is easy to relate the result to the source code. @@ -178,7 +178,7 @@ class BaseDefinition(object): >>> from jedi import Script >>> source = 'import datetime' >>> script = Script(source, 1, len(source), 'example.py') - >>> d = script.definition()[0] + >>> d = script.goto_definitions()[0] >>> print(d.module_name) # doctest: +ELLIPSIS datetime """ @@ -226,7 +226,7 @@ class BaseDefinition(object): ... "Document for function f." ... ''' >>> script = Script(source, 1, len('def f'), 'example.py') - >>> d = script.definition()[0] + >>> d = script.goto_definitions()[0] >>> print(d.doc) f(a, b = 1) @@ -274,7 +274,7 @@ class BaseDefinition(object): ... ... variable = f or C''' >>> script = Script(source, len(source.splitlines()), 3, 'example.py') - >>> defs = script.definition() # doctest: +SKIP + >>> defs = script.goto_definitions() # doctest: +SKIP >>> defs = sorted(defs, key=lambda d: d.line) # doctest: +SKIP >>> defs # doctest: +SKIP [, ] @@ -302,7 +302,7 @@ class BaseDefinition(object): ... import os ... os.path.join''' >>> script = Script(source, 3, len('os.path.join'), 'example.py') - >>> print(script.definition()[0].full_name) + >>> print(script.goto_definitions()[0].full_name) os.path.join Notice that it correctly returns ``'os.path.join'`` instead of diff --git a/jedi/refactoring.py b/jedi/refactoring.py index 9f6249e0..b22b8293 100644 --- a/jedi/refactoring.py +++ b/jedi/refactoring.py @@ -64,7 +64,7 @@ def rename(script, new_name): def _rename(names, replace_str): """ For both rename and inline. """ - order = sorted(names, key=lambda x: (x.module_path, x.start_pos), + order = sorted(names, key=lambda x: (x.module_path, x.line, x.column), reverse=True) def process(path, old_lines, new_lines): @@ -89,7 +89,7 @@ def _rename(names, replace_str): new_lines = modules.source_to_unicode(source).splitlines() old_lines = new_lines[:] - nr, indent = name.start_pos + nr, indent = name.line, name.column line = new_lines[nr - 1] new_lines[nr - 1] = line[:indent] + replace_str + \ line[indent + len(name.text):] @@ -167,14 +167,14 @@ def inline(script): dct = {} - definitions = script.goto() + definitions = script.goto_assignments() with common.ignored(AssertionError): assert len(definitions) == 1 stmt = definitions[0]._definition usages = script.usages() inlines = [r for r in usages - if not stmt.start_pos <= r.start_pos <= stmt.end_pos] - inlines = sorted(inlines, key=lambda x: (x.module_path, x.start_pos), + if not stmt.start_pos <= (r.line, r.column) <= stmt.end_pos] + inlines = sorted(inlines, key=lambda x: (x.module_path, x.line, x.column), reverse=True) commands = stmt.get_commands() # don't allow multiline refactorings for now. diff --git a/test/run.py b/test/run.py index d6296ea8..fc444929 100755 --- a/test/run.py +++ b/test/run.py @@ -191,8 +191,7 @@ class IntegrationTestCase(object): def run_usages(self, compare_cb): result = self.script().usages() self.correct = self.correct.strip() - compare = sorted((r.module_name, r.start_pos[0], r.start_pos[1]) - for r in result) + compare = sorted((r.module_name, r.line, r.column) for r in result) wanted = [] if not self.correct: positions = [] diff --git a/test/test_api.py b/test/test_api.py index 4fd34e9e..1ee95afd 100644 --- a/test/test_api.py +++ b/test/test_api.py @@ -2,8 +2,7 @@ Test all things related to the ``jedi.api`` module. """ -import jedi -from jedi import common +from jedi import common, api def test_preload_modules(): @@ -19,9 +18,9 @@ def test_preload_modules(): with common.ignored(KeyError): # performance of tests -> no reload new['__builtin__'] = temp_cache['__builtin__'] - jedi.preload_module('datetime') + api.preload_module('datetime') check_loaded('datetime') - jedi.preload_module('json', 'token') + api.preload_module('json', 'token') check_loaded('datetime', 'json', 'token') cache.parser_cache = temp_cache diff --git a/test/test_integration_import.py b/test/test_integration_import.py index 9ea43e69..0c85a707 100644 --- a/test/test_integration_import.py +++ b/test/test_integration_import.py @@ -39,7 +39,7 @@ def test_goto_following_on_imports(): s = "import multiprocessing.dummy; multiprocessing.dummy" g = Script(s).goto_assignments() assert len(g) == 1 - assert g[0].start_pos != (0, 0) + assert (g[0].line, g[0].column) != (0, 0) def test_follow_definition(): diff --git a/test/test_interpreter.py b/test/test_interpreter.py index ffeba666..ea871b06 100644 --- a/test/test_interpreter.py +++ b/test/test_interpreter.py @@ -11,8 +11,8 @@ class TestInterpreterAPI(TestCase): def check_interpreter_complete(self, source, namespace, completions, **kwds): script = jedi.Interpreter(source, [namespace], **kwds) - cs = script.complete() - actual = [c.word for c in cs] + cs = script.completions() + actual = [c.name for c in cs] self.assertEqual(sorted(actual), sorted(completions)) def test_complete_raw_function(self):