1
0
forked from VimPlug/jedi

make source parameter in Script optional

This commit is contained in:
David Halter
2013-08-31 14:41:32 +04:30
parent b8a909d352
commit 1ebf68999a
2 changed files with 9 additions and 6 deletions

View File

@@ -41,6 +41,9 @@ class Script(object):
A Script is the base for completions, goto or whatever you want to do with A Script is the base for completions, goto or whatever you want to do with
|jedi|. |jedi|.
You can either use the ``source`` parameter or ``path`` to read a file.
Usually you're going to want to use both of them (in an editor).
:param source: The source code of the current file, separated by newlines. :param source: The source code of the current file, separated by newlines.
:type source: str :type source: str
:param line: The line to perform actions on (starting with 1). :param line: The line to perform actions on (starting with 1).
@@ -54,12 +57,16 @@ class Script(object):
``unicode`` object (default ``'utf-8'``). ``unicode`` object (default ``'utf-8'``).
:type source_encoding: str :type source_encoding: str
""" """
def __init__(self, source, line=None, column=None, path=None, def __init__(self, source=None, line=None, column=None, path=None,
source_encoding='utf-8', source_path=None): source_encoding='utf-8', source_path=None):
if source_path is not None: if source_path is not None:
warnings.warn("Use path instead of source_path.", DeprecationWarning) warnings.warn("Use path instead of source_path.", DeprecationWarning)
path = source_path path = source_path
if source is None:
with open(path) as f:
source = f.read()
lines = source.splitlines() or [''] lines = source.splitlines() or ['']
if source and source[-1] == '\n': if source and source[-1] == '\n':
lines.append('') lines.append('')

View File

@@ -35,9 +35,5 @@ def test_dont_break_imports_without_namespaces():
@helpers.cwd_at("test/absolute_import") @helpers.cwd_at("test/absolute_import")
def test_can_complete_when_shadowing(): def test_can_complete_when_shadowing():
filename = "unittest.py" script = jedi.Script(path="unittest.py")
with open(filename) as f:
lines = f.readlines()
src = "".join(lines)
script = jedi.Script(src, path=filename)
assert script.completions() assert script.completions()