forked from VimPlug/jedi
remove all the deprecation warnings in jedi itself
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
<BLANKLINE>
|
||||
@@ -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
|
||||
[<Definition def f>, <Definition class C>]
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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 = []
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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():
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user