davidhalter / jedi Goto Github PK
View Code? Open in Web Editor NEWAwesome autocompletion, static analysis and refactoring library for python
Home Page: http://jedi.readthedocs.io
License: Other
Awesome autocompletion, static analysis and refactoring library for python
Home Page: http://jedi.readthedocs.io
License: Other
Currently jedi includes l.__iterable
as completion of the code below. I think jedi should not return private variables such as this by default. And if it is to return such variables, name mangling rule [1] should be applied.
l = list('abc')
l.__
[1] http://docs.python.org/2/tutorial/classes.html#private-variables-and-class-local-references
class FooBar(object):
raboof = 'fourtytwo'
target = u''
for char in reversed(['f', 'o', 'o', 'b', 'a', 'r']):
target += char
answer = getattr(FooBar, target)
answer.<tab>
...doesn't work. Jedi sucks so much.
When completing here
from pkg.mod import <tab>
make it possible to only display names present in the module's __all__
list.
Realize this as a mapping, maybe only present when the popupmenu is open (toggle).
I think I will license Jedi with the GNU LGPL, what do you think?
Is anyone fond of GPL or BSD?
exception occurs on
jedi\parsing.py line 301
when os is windows and os.path.sep = ''
changing line 300 in the same file to
sep = (re.escape(os.path.sep),) * 2
can fix this issue.
import django
class Foo(object):
global django
asdf = django
def asdfy():
return Foo
xorz = getattr(asdfy()(), 'asdf')
print xorz.<tab>
...doesn't work. Jedi sucks so much.
Is it possible to get full symbol name from api.Completion
object? For example, when I am completing json.l
, I can get "load" from Completion.word
and "oad" from Completion.complete
. But how can I get "json.load"?
BTW, I started Emacs binding: https://github.com/tkf/emacs-jedi
I get this in
In [18]:
source = """\
def function(alpha, beta):
pass
function(alpha='one', beta='two')
"""
script = jedi.Script(source, 3, 0, '')
definitions = script.get_definition()
definitions
Truncated Traceback (Use C-c C-x to view full TB):
/home/takafumi/repos/watch/jedi/jedi/parsing.py in name(self)
300 sep = (os.path.sep,) * 2
301 r = re.search(r'([^%s]+?)(%s__init__)?(\.py)?$' % sep, self.path)
--> 302 string = r.group(1)
303 names = [(string, (0, 0))]
304 self._name = Name(names, self.start_pos, self.end_pos, self)
AttributeError: 'NoneType' object has no attribute 'group'
This expression causes an error:
[[int(v) for v in line.strip().split() if v] for line in ["123", "123", "123"] if line]
When called like this:
jedi.Script("[[int(v) for v in line.strip().split() if v] for line in [\"123\", \"123\", \"123\"] if line]", 0, 10, "test.py")
Error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "jedi\api.py", line 173, in __init__
position=self.pos)
File "jedi\modules.py", line 64, in __init__
self._parser = parsing.PyFuzzyParser(source, path, position)
File "jedi\parsing.py", line 1138, in __init__
self.parse()
File "jedi\parsing.py", line 1764, in parse
stmt, tok = self._parse_statement(self.current)
File "jedi\parsing.py", line 1468, in _parse_statement
tok = tok[1]
TypeError: 'ListComprehension' object does not support indexing
Create a file test.py
containing the following:
from django.core.exceptions import ObjectDoesNotExist
Move your cursor over ObjectDoesNotExist
Invoke jedi#goto
Error message:
Some different eror, this shouldn't happen.
Traceback (most recent call last):
File "<string>", line 50, in _goto
File "/usr/lib/python2.7/site-packages/jedi/api.py", line 316, in goto
definitions = evaluate.goto(scopes, search_name_new)
File "/usr/lib/python2.7/site-packages/jedi/evaluate.py", line 1517, in goto
s = statement_path[0]
IndexError: list index out of range
Press ENTER or type command to continue
get_definition seems to work though.
...so that imports relative to the project root work.
You can detect a Django root folder by looking for the manage.py
module.
Jedi does not work properly in Python 3.1.3, because local package
imports like
import parsing
don't work anymore. Changing these lines to
from . import parsing
, as 2to3 suggests, gets us in trouble with circular dependencies
between various modules.
As a workaround it's possible to add the jedi installation path to
sys.path at runtime.
-ap
REStructuredText makes more sense because the README could be turned into a full Sphinx based documentation later on.
I'll probably do this tonight or tomorrow.
import os
class Test(object):
def __init__(self):
self.foo = 'bar'
def test(self):
for root, dirs, files in os.walk(self.
self.<tab>
is not completed inside the os.walk(
function call. Apparently it has to do with the for
loop.
=jedi#do_popup_on_dot() ? "" : ""
E117: Unknown function: pysmell#Complete
Oh, you thought reverse iterators were too easy?
class _TrackingMetaclass(type):
def __init__(cls, name, bases, attrs):
if hasattr(cls, '_bazinga'):
IncredibleClass._registry.append(cls)
class IncredibleClass(object):
__metaclass__ = _TrackingMetaclass
_registry = []
class Eggs(IncredibleClass):
_bazinga = True
class Bacon(IncredibleClass):
pass
class Spam(IncredibleClass):
_bazinga = None
number = '01189998819991197253'
yoda = Bacon()
setattr(yoda, '_omgwtf', Eggs._registry)
yoda._omgwtf[1].number.<tab>
...doesn't work. There you go, Jedi sucks so much!
โ๏ธ Cheers! โ๏ธ
Is this not implemented yet or does it have to be an issue with my setup? values returned by functions.complete() always have empty help attributes.
It looks like jedi does not care what is in sys.path when completing code.
Let's say I have a virtualenv ~/.virtualenvs/tmp which has numpy installed and numpy is not installed in system site-packages. If I start jedi using ~/.virtualenvs/tmp/bin/python jedi can complete numpy, but it cannot do it when I start jedi using /usr/bin/python and add numpy to sys.path.
This is how to reproduce. Save the following code in test.py:
import os
import sys
import jedi
def add_virtualenv_path():
"""Add virtualenv's site-packages to `sys.path`."""
venv = os.path.abspath(os.getenv('VIRTUAL_ENV'))
if not venv:
return
path = os.path.join(
venv, 'lib', 'python%d.%d' % sys.version_info[:2], 'site-packages')
sys.path.insert(0, path)
add_virtualenv_path()
import numpy # this does not fail
source = """\
import numpy
numpy."""
script = jedi.Script(source, 2, len('numpy.'), '')
print script.complete()
Run test.py using /usr/bin/python
, like this:
source ~/.virtualenvs/tmp/bin/activate
echo $VIRTUAL_ENV
/usr/bin/python test.py
This will output:
/home/takafumi/.virtualenvs/tmp
[]
If I run this script by python test.py
, I get a long list of completions.
I have been using get_definitions() to implement what is now the goto() function. This worked great until now. I tried using goto(), but there are these two issues.
When goto() is invoked on a name in an import statement that absolutely imports from within the current package, nothing is found. In my case it looks like this:
from myproject.mod import SomeClass
with the cursor on SomeClass. This used to work with get_definitions() and accessing scope.parent.
myproject is in sys.path.
Second, I would like to jump to the definition directly, without stopover at the import statement.
Are you planning to enhance goto() like this or do I need to implement this myself?
Anyway, great work!
Completing
import threading
threading.
fails with AttributeError("'Flow' object has no attribute 'name'",)
.
Completing
import threading
threading.T
works fine.
Hi.
To me, the most important thing when selecting whether to use autocomplete, and which one to use, is knowing what if anything is evaluated and what is done statically.
If possible, it would be extremely helpful to have specific documentation on what execution of code is being done when autocompleting. I haven't had a chance to dig through the source yet, but from just a quick peek it does seem like at least some is being done, so having clear lines for how far that goes would be lovely.
Thanks for your work!
Currently,
source = """\
import datetime
if isinstance(obj, datetime.datetime):
obj."""
script = jedi.Script(source, 3, 8, '')
script.complete()
works, but
source = """\
import datetime
if isinstance(obj, datetime.datetime):
pass
obj."""
script = jedi.Script(source, 4, 4, '')
script.complete()
does not work.
I think having false-positive candidates in auto-completion is OK (better than nothing).
import requests
r = requests.post('http://google.com', {'foo': 'bar'})
r.st<tab>
This should return r.status_code
.
Currently completion object for json.JSONEncoder
has "Import" as scope, not "Class".
In [7]:
comp
Out [7]:
<Completion: JSONEncoder>
In [8]:
parent = comp.name.parent()
parent
Out [8]:
<Import: from .encoder import JSONEncoder @109>
It would be nice if jedi "follows" imports so that I can get docstring for imported objects such as JSONEncoder.
source = """\
class Spam:
if True:
def egg():
pass
Spam.e
"""
lines = source.splitlines()
lineno = len(lines)
column = len(lines[lineno - 1])
script = jedi.Script(source, lineno, column, '')
completions = script.complete()
In [3]:
source = """\
import re
any_re = re.compile('.*')"""
lines = source.splitlines()
script = jedi.Script(source, len(lines), 1, None)
definition = script.get_definition()
[(d, d.full_name) for d in definition]
Out [3]:
[(<Definition class str>, '__builtin__.str'),
(<Definition class SRE_Pattern>, '_sre.SRE_Pattern')]
Jedi says any_re
can be __builtin__.str
. How come?
I will write a patch for mapping _sre.SRE_Pattern
later (but don't wait for me if you want to do it).
149 response = HttpResponse(mimetype='application/pdf')
150 response['Content-Disposition'] = 'attachment; filename=%s.pdf' % id
151 response.write(pdf)
152
153 return response
Renaming response on line 153 leads to:
149 foobear = HttpResponse(mimetype='application/pdf')
150 response['Content-Disposition'] = 'attachment; filename=%s.pdf' % id
151 foobear.write(pdf)
152
153 return foobear
When I install the plugin and open a file in python + - 400 lines, when it gets slow when I start typing. And when I type the point, it takes about 2 seconds to appear oa listing.
Remembering that this was a project in Django.
also in: davidhalter/jedi-vim#20
from @gilsondev (in another issue)
import <tab>
Show all importable modules.
See also: http://stackoverflow.com/questions/11225235/finding-out-importable-modules-in-python
I just started a port of Jedi for Sublime Text (https://github.com/svaiter/SublimeJEDI).
I never wrote a plugin for Sublime, so I might be slow to have a reliable plugin, but if anyone is interested to contribute, please join the effort :)
(Thanks for this awesome piece of code David)
Sometimes Jedi returns very long description. It would be nice if it returns shorter one by default. I know it is on your TODO list as the source says so, but let me file this issue so that people can follow the status.
Note: This is how I am using it in Emacs Jedi:
https://github.com/tkf/emacs-jedi/blob/9ed6990f4f69f51a03c78218c9ec3d4b0654d9f1/jediepcserver.py#L64
Example:
Originally posted at tkf/emacs-jedi#4 by @syohex
Hi,
How can I change the mapping from to something else? I can't figure out where to do that in your code.
Thanks!
As written in the README, these features might be supported in the future:
__mul__
, __add__
, etc.Which features are important for you? Vote for the ones you're interested in.
Are there any other features, you like to have in Jedi?
If you don't like Jedi, I also want to know why!
Cheers!
David
Sphinx info filed (http://sphinx.pocoo.org/domains.html#info-field-lists) has well defined syntax and it is used in many modules. It would be nice if Jedi can pull information out from it. Jedi user can quickly improve completions in their functions by improving their documentation.
I don't really have much more to say, here is a recipe:
>>> Script('import numpy\na = numpy.array([1,2])\na.', 3, 2, "").complete()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/api.py", line 225, in complete
scopes = list(self._prepare_goto(path, True))
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/api.py", line 296, in _prepare_goto
scopes = evaluate.follow_statement(stmt)
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/helpers.py", line 26, in __call__
result = self.func(stmt, *args, **kwargs)
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 108, in wrapper
rv = function(*args, **kwargs)
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 1345, in follow_statement
result = follow_call_list(call_list)
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 1424, in follow_call_list
result += follow_call(call)
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 1439, in follow_call
return follow_call_path(path, scope, position)
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 1462, in follow_call_path
search_global=True)
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 1214, in get_scopes_for_name
return descriptor_check(remove_statements(filter_name(scope_generator)))
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 1023, in remove_statements
scopes = follow_statement(r, seek_name=name_str)
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/helpers.py", line 26, in __call__
result = self.func(stmt, *args, **kwargs)
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 108, in wrapper
rv = function(*args, **kwargs)
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 1345, in follow_statement
result = follow_call_list(call_list)
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 1424, in follow_call_list
result += follow_call(call)
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 1439, in follow_call
return follow_call_path(path, scope, position)
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 1469, in follow_call_path
return follow_paths(path, result, position=position)
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 1484, in follow_paths
fp = follow_path(iter_paths[i], r, position=position)
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 1531, in follow_path
return follow_paths(path, set(result), position=position)
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 1484, in follow_paths
fp = follow_path(iter_paths[i], r, position=position)
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 1517, in follow_path
result = Execution(scope, current).get_return_types()
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 108, in wrapper
rv = function(*args, **kwargs)
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/helpers.py", line 103, in __call__
result = self.func(execution, evaluate_generator)
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 522, in get_return_types
stmts = self._get_function_returns(evaluate_generator)
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 539, in _get_function_returns
stmts += follow_statement(r)
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/helpers.py", line 26, in __call__
result = self.func(stmt, *args, **kwargs)
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 108, in wrapper
rv = function(*args, **kwargs)
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 1345, in follow_statement
result = follow_call_list(call_list)
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 1424, in follow_call_list
result += follow_call(call)
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 1439, in follow_call
return follow_call_path(path, scope, position)
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 1469, in follow_call_path
return follow_paths(path, result, position=position)
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 1484, in follow_paths
fp = follow_path(iter_paths[i], r, position=position)
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 1517, in follow_path
result = Execution(scope, current).get_return_types()
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 108, in wrapper
rv = function(*args, **kwargs)
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/helpers.py", line 103, in __call__
result = self.func(execution, evaluate_generator)
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 522, in get_return_types
stmts = self._get_function_returns(evaluate_generator)
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 539, in _get_function_returns
stmts += follow_statement(r)
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/helpers.py", line 26, in __call__
result = self.func(stmt, *args, **kwargs)
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 108, in wrapper
rv = function(*args, **kwargs)
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 1349, in follow_statement
raise MultiLevelAttributeError(sys.exc_info())
jedi.evaluate.MultiLevelAttributeError: Original:
Traceback (most recent call last):
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 1345, in follow_statement
result = follow_call_list(call_list)
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 1424, in follow_call_list
result += follow_call(call)
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 1439, in follow_call
return follow_call_path(path, scope, position)
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 1462, in follow_call_path
search_global=True)
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 1214, in get_scopes_for_name
return descriptor_check(remove_statements(filter_name(scope_generator)))
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 1130, in filter_name
for nscope, name_list in scope_generator:
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 946, in get_names_for_scope
position, in_func_scope)
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 907, in get_defined_names_for_position
names = scope.get_defined_names()
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 696, in get_defined_names
return self.get_params() + parsing.Scope.get_set_vars(self)
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 108, in wrapper
rv = function(*args, **kwargs)
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 604, in get_params
key, value = next(var_arg_iterator, (None, None))
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/parsing.py", line 70, in next
return self.__next__()
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/parsing.py", line 76, in __next__
return next(self.iterator)
File "/home/politza/.local/lib/python2.6/site-packages/jedi-0.5b3-py2.6.egg/jedi/evaluate.py", line 676, in iterate
name = key[0].name
AttributeError: 'str' object has no attribute 'name'
-ap
Running Jedi on PyPy is no problem. (Almost) all tests pass.
But PyPy has a bug in current releases (itertools.tee):
https://bugs.pypy.org/issue1249
It got fixed a few hours ago.
If this fix of PyPy is in the major packaging systems, I will start supporting it (probably PyPy 2.0).
raise <tab>
This should show builtin exception classes.
See this file: http://tmp.dbrgn.ch/builder.py.txt
Go to line 124 in vim, move the cursor to the last character and press "a". A 10-15 seconds delay occurs.
At first it even gave me segfaults, after a recompilation of vim that doesn't happen anymore, but the long delay still persists.
It would be nice if I can get "full name" or "absolute path" of the function or class. For example, if I have
import json
l = json.load
l# <- cursor
then corresponding Definition.fullname
should return "json.load". This is mainly for document lookup. For example, you can directly search this "full name" using online Sphinx document. In Emacs, you can directly go to the document using pydoc-info [1] or pylookup [2] if you have the "full name". Also, I think you can use objects.inv
(intersphinx) [3] to get the direct link to online documents generated by sphinx (not only stdlib!). I guess even having objects.inv
handing as a jedi feature makes sense.
The problem is that many functions and classes have real location different from what is written in the document. For example, os.path.join
in Linux is actually posixpath.join
and io.Bytes
is _io.Bytes
. Can jedi workaround this problem?
[1] https://bitbucket.org/jonwaltman/pydoc-info
[2] https://github.com/tsgates/pylookup
[3] http://sphinx-doc.org/ext/intersphinx.html
Executing this code
source = """\
import gobject
gobject.idle_add"""
script = jedi.Script(source, 2, len('gobject.idle_'), '')
definitions = script.get_definition()
definitions
yields this:
Traceback (most recent call last):
File "/.../jedi/evaluate.py", line 1349, in follow_statement
result = follow_call_list(call_list)
File "/.../jedi/evaluate.py", line 1428, in follow_call_list
result += follow_call(call)
File "/.../jedi/evaluate.py", line 1443, in follow_call
return follow_call_path(path, scope, position)
File "/.../jedi/evaluate.py", line 1467, in follow_call_path
result = imports.strip_imports(scopes)
File "/.../jedi/imports.py", line 258, in strip_imports
result += ImportPath(s).follow()
File "/.../jedi/imports.py", line 154, in follow
remove_star_imports(s) for s in scopes)
File "/.../jedi/imports.py", line 154, in <genexpr>
remove_star_imports(s) for s in scopes)
File "/.../jedi/imports.py", line 271, in remove_star_imports
modules = strip_imports(i for i in scope.get_imports() if i.star)
File "/.../jedi/imports.py", line 258, in strip_imports
result += ImportPath(s).follow()
File "/.../jedi/imports.py", line 146, in follow
scope, rest = self._follow_file_system()
File "/.../jedi/imports.py", line 247, in _follow_file_system
return f.parser.module, rest
File "/.../jedi/builtin.py", line 42, in parser
self._load_module()
File "/.../jedi/builtin.py", line 49, in _load_module
source = self._get_source()
File "/.../jedi/builtin.py", line 134, in _get_source
return self._generate_code(self.module, self._load_mixins())
File "/.../jedi/builtin.py", line 129, in module
load_module(name, path)
File "/.../jedi/builtin.py", line 104, in load_module
exec_function('import %s as module' % name, content)
File "blub", line 2, in exec_function
File "<string>", line 1, in <module>
AttributeError: 'module' object has no attribute '_gobject'
If you don't know about Jedi internals it feels like returning a Definition object is the right thing to do. Why you are returning list? Which element I should use if I just want to show the docstring or goto the line of def function(...)
?
It would be nice to have more docstrings and Sphinx documentation. For example, I need a couple of experiments to see the difference between Completion.word
and Completion.complete
.
In [2]:
source = """\
from pygments.formatters import TerminalFormatter
TerminalFormatter"""
lines = source.splitlines()
script = jedi.Script(source, len(lines), len(lines[-1]), None)
definition = script.get_definition()
definition
Out [2]:
[]
It's the same for the other classes in this module.
The beginning of pygments/formatters/__init__.py
is something like this:
from pygments.formatters._mapping import FORMATTERS
ns = globals()
for fcls in FORMATTERS:
ns[fcls.__name__] = fcls
del fcls
__all__ = ['get_formatter_by_name', 'get_formatter_for_filename',
'get_all_formatters'] + [cls.__name__ for cls in FORMATTERS]
Probably it's too evil for Jedi to handle?
As the title(subject) said.
...I find it a quite nice convention :)
Can source_path
be optional for small source? How about source_path=None
meaning "do not cache". For example it will be useful when using with IPython Notebook (https://github.com/tkf/emacs-ipython-notebook), as there is no actual Python file when writing code in the notebook.
original discussion:
tkf/emacs-jedi@bd39dd2#commitcomment-2019538
I am using the latest Jedi (1940fbe).
source = """\
import json
json.load(s)"""
script = jedi.Script(source, 1, len("import js"), None)
completions = script.complete()
completions
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-2-4f2725382bcf> in <module>()
3 json.load(s)"""
4 script = jedi.Script(source, 1, len("import js"), None)
----> 5 completions = script.complete()
6 completions
/home/takafumi/repos/watch/jedi/jedi/api.pyc in complete(self)
117 if not l.endswith('import import'):
118 continue
--> 119 names = s.get_defined_names(on_import_stmt=True)
120 else:
121 names = s.get_defined_names()
/home/takafumi/repos/watch/jedi/jedi/imports.pyc in get_defined_names(self, on_import_stmt)
95 if scope is ImportPath.GlobalNamespace:
96 if self.import_stmt.relative_count == 0:
---> 97 names += self.get_module_names()
98
99 path = os.path.abspath(self.file_path)
/home/takafumi/repos/watch/jedi/jedi/imports.pyc in get_module_names(self, search_path)
126 """
127 if not search_path:
--> 128 search_path = self.sys_path_with_modifications()
129 names = []
130 for module_loader, name, is_pkg in pkgutil.iter_modules(search_path):
/home/takafumi/repos/watch/jedi/jedi/imports.pyc in sys_path_with_modifications(self)
136 def sys_path_with_modifications(self):
137 module = self.import_stmt.get_parent_until()
--> 138 return modules.sys_path_with_modifications(module)
139
140 def follow(self, is_goto=False):
/home/takafumi/repos/watch/jedi/jedi/evaluate.pyc in wrapper(*args, **kwargs)
107 else:
108 memo[key] = default
--> 109 rv = function(*args, **kwargs)
110 memo[key] = rv
111 return rv
/home/takafumi/repos/watch/jedi/jedi/modules.pyc in sys_path_with_modifications(module)
274 curdir = os.path.abspath(os.curdir)
275 try:
--> 276 os.chdir(os.path.dirname(module.path))
277 except OSError:
278 pass
/home/takafumi/.virtualenvs/mypy/lib/python2.7/posixpath.pyc in dirname(p)
118 def dirname(p):
119 """Returns the directory component of a pathname"""
--> 120 i = p.rfind('/') + 1
121 head = p[:i]
122 if head and head != '/'*len(head):
AttributeError: 'NoneType' object has no attribute 'rfind'
In [70]:
source = """\
import json
json.l"""
script = jedi.Script(source, 2, len('json.l'), '')
completions = script.complete()
completions
Out [70]:
[<Completion: load>, <Completion: loads>]
In [71]:
source = u"""\
import json
json.l"""
script = jedi.Script(source, 2, len('json.l'), '')
completions = script.complete()
completions
Out [71]:
[]
When in code like function(alpha='one', beta='two')
, it seems that index=0
when the cursor is at alpha
but index=1
when at 'one'
. I think it should be index=0
for both cases.
In [2]:
import jedi
In [3]:
source = """\
def function(alpha, beta):
pass
function(alpha='one', beta='two')"""
script = jedi.Script(source, 3, len("function(a"), '')
script.get_in_function_call().index
Out [3]:
0
In [4]:
source = """\
def function(alpha, beta):
pass
function(alpha='one', beta='two')"""
script = jedi.Script(source, 3, len("function(alpha='on"), '')
script.get_in_function_call().index
Out [4]:
1
Completion does not work in these examples:
import psycopg2
conn = psycopg2.connect('dbname=test')
conn.<TAB>
import psycopg2
conn = psycopg2.connect('dbname=test')
cur = conn.cursor()
cur.<TAB>
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.