1
0
forked from VimPlug/jedi

remove all the deprecation warnings in jedi itself

This commit is contained in:
David Halter
2013-08-11 23:00:27 +04:30
parent 0ab4119447
commit e07625017d
7 changed files with 21 additions and 23 deletions
+3 -3
View File
@@ -514,7 +514,7 @@ class Script(object):
def _sorted_defs(d): def _sorted_defs(d):
# Note: `or ''` below is required because `module_path` could be # Note: `or ''` below is required because `module_path` could be
# None and you can't compare None and str in Python 3. # 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): class Interpreter(Script):
@@ -530,7 +530,7 @@ class Interpreter(Script):
>>> from os.path import join >>> from os.path import join
>>> namespace = locals() >>> namespace = locals()
>>> script = Interpreter('join().up', [namespace]) >>> script = Interpreter('join().up', [namespace])
>>> print(script.complete()[0].word) >>> print(script.completions()[0].name)
upper upper
""" """
@@ -584,7 +584,7 @@ def preload_module(*modules):
""" """
for m in modules: for m in modules:
s = "import %s as x; x." % m 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, def set_debug_function(func_cb=debug.print_to_stdout, warnings=True,
+6 -6
View File
@@ -98,7 +98,7 @@ class BaseDefinition(object):
Here is an example of the value of this attribute. Let's consider Here is an example of the value of this attribute. Let's consider
the following source. As what is in ``variable`` is unambiguous 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``. definition for ``sys``, ``f``, ``C`` and ``x``.
>>> from jedi import Script >>> from jedi import Script
@@ -118,7 +118,7 @@ class BaseDefinition(object):
... ...
... variable = keyword or f or C or x''' ... variable = keyword or f or C or x'''
>>> script = Script(source, len(source.splitlines()), 3, 'example.py') >>> 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` 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. so that it is easy to relate the result to the source code.
@@ -178,7 +178,7 @@ class BaseDefinition(object):
>>> from jedi import Script >>> from jedi import Script
>>> source = 'import datetime' >>> source = 'import datetime'
>>> script = Script(source, 1, len(source), 'example.py') >>> script = Script(source, 1, len(source), 'example.py')
>>> d = script.definition()[0] >>> d = script.goto_definitions()[0]
>>> print(d.module_name) # doctest: +ELLIPSIS >>> print(d.module_name) # doctest: +ELLIPSIS
datetime datetime
""" """
@@ -226,7 +226,7 @@ class BaseDefinition(object):
... "Document for function f." ... "Document for function f."
... ''' ... '''
>>> script = Script(source, 1, len('def f'), 'example.py') >>> script = Script(source, 1, len('def f'), 'example.py')
>>> d = script.definition()[0] >>> d = script.goto_definitions()[0]
>>> print(d.doc) >>> print(d.doc)
f(a, b = 1) f(a, b = 1)
<BLANKLINE> <BLANKLINE>
@@ -274,7 +274,7 @@ class BaseDefinition(object):
... ...
... variable = f or C''' ... variable = f or C'''
>>> script = Script(source, len(source.splitlines()), 3, 'example.py') >>> 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 = sorted(defs, key=lambda d: d.line) # doctest: +SKIP
>>> defs # doctest: +SKIP >>> defs # doctest: +SKIP
[<Definition def f>, <Definition class C>] [<Definition def f>, <Definition class C>]
@@ -302,7 +302,7 @@ class BaseDefinition(object):
... import os ... import os
... os.path.join''' ... os.path.join'''
>>> script = Script(source, 3, len('os.path.join'), 'example.py') >>> 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 os.path.join
Notice that it correctly returns ``'os.path.join'`` instead of Notice that it correctly returns ``'os.path.join'`` instead of
+5 -5
View File
@@ -64,7 +64,7 @@ def rename(script, new_name):
def _rename(names, replace_str): def _rename(names, replace_str):
""" For both rename and inline. """ """ 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) reverse=True)
def process(path, old_lines, new_lines): def process(path, old_lines, new_lines):
@@ -89,7 +89,7 @@ def _rename(names, replace_str):
new_lines = modules.source_to_unicode(source).splitlines() new_lines = modules.source_to_unicode(source).splitlines()
old_lines = new_lines[:] old_lines = new_lines[:]
nr, indent = name.start_pos nr, indent = name.line, name.column
line = new_lines[nr - 1] line = new_lines[nr - 1]
new_lines[nr - 1] = line[:indent] + replace_str + \ new_lines[nr - 1] = line[:indent] + replace_str + \
line[indent + len(name.text):] line[indent + len(name.text):]
@@ -167,14 +167,14 @@ def inline(script):
dct = {} dct = {}
definitions = script.goto() definitions = script.goto_assignments()
with common.ignored(AssertionError): with common.ignored(AssertionError):
assert len(definitions) == 1 assert len(definitions) == 1
stmt = definitions[0]._definition stmt = definitions[0]._definition
usages = script.usages() usages = script.usages()
inlines = [r for r in usages inlines = [r for r in usages
if not stmt.start_pos <= r.start_pos <= stmt.end_pos] if not stmt.start_pos <= (r.line, r.column) <= stmt.end_pos]
inlines = sorted(inlines, key=lambda x: (x.module_path, x.start_pos), inlines = sorted(inlines, key=lambda x: (x.module_path, x.line, x.column),
reverse=True) reverse=True)
commands = stmt.get_commands() commands = stmt.get_commands()
# don't allow multiline refactorings for now. # don't allow multiline refactorings for now.
+1 -2
View File
@@ -191,8 +191,7 @@ class IntegrationTestCase(object):
def run_usages(self, compare_cb): def run_usages(self, compare_cb):
result = self.script().usages() result = self.script().usages()
self.correct = self.correct.strip() self.correct = self.correct.strip()
compare = sorted((r.module_name, r.start_pos[0], r.start_pos[1]) compare = sorted((r.module_name, r.line, r.column) for r in result)
for r in result)
wanted = [] wanted = []
if not self.correct: if not self.correct:
positions = [] positions = []
+3 -4
View File
@@ -2,8 +2,7 @@
Test all things related to the ``jedi.api`` module. Test all things related to the ``jedi.api`` module.
""" """
import jedi from jedi import common, api
from jedi import common
def test_preload_modules(): def test_preload_modules():
@@ -19,9 +18,9 @@ def test_preload_modules():
with common.ignored(KeyError): # performance of tests -> no reload with common.ignored(KeyError): # performance of tests -> no reload
new['__builtin__'] = temp_cache['__builtin__'] new['__builtin__'] = temp_cache['__builtin__']
jedi.preload_module('datetime') api.preload_module('datetime')
check_loaded('datetime') check_loaded('datetime')
jedi.preload_module('json', 'token') api.preload_module('json', 'token')
check_loaded('datetime', 'json', 'token') check_loaded('datetime', 'json', 'token')
cache.parser_cache = temp_cache cache.parser_cache = temp_cache
+1 -1
View File
@@ -39,7 +39,7 @@ def test_goto_following_on_imports():
s = "import multiprocessing.dummy; multiprocessing.dummy" s = "import multiprocessing.dummy; multiprocessing.dummy"
g = Script(s).goto_assignments() g = Script(s).goto_assignments()
assert len(g) == 1 assert len(g) == 1
assert g[0].start_pos != (0, 0) assert (g[0].line, g[0].column) != (0, 0)
def test_follow_definition(): def test_follow_definition():
+2 -2
View File
@@ -11,8 +11,8 @@ class TestInterpreterAPI(TestCase):
def check_interpreter_complete(self, source, namespace, completions, def check_interpreter_complete(self, source, namespace, completions,
**kwds): **kwds):
script = jedi.Interpreter(source, [namespace], **kwds) script = jedi.Interpreter(source, [namespace], **kwds)
cs = script.complete() cs = script.completions()
actual = [c.word for c in cs] actual = [c.name for c in cs]
self.assertEqual(sorted(actual), sorted(completions)) self.assertEqual(sorted(actual), sorted(completions))
def test_complete_raw_function(self): def test_complete_raw_function(self):