Code Monkey home page Code Monkey logo

jedi's People

Contributors

alga avatar asford avatar asmeurer avatar astrac avatar bcolsen avatar blueyed avatar boerde avatar carreau avatar colinduquesnoy avatar davidhalter avatar dbrgn avatar hattya avatar hugovk avatar immerrr avatar jkb0o avatar jmfrank63 avatar lvh avatar m-novikov avatar marciomazza avatar mfussenegger avatar micbou avatar moser avatar muffinmad avatar pappasam avatar peterjclaw avatar reinhrst avatar sadovnychyi avatar tkf avatar tobiasrzepka avatar yuan-xy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jedi's Issues

Follow imports?

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.

docstrings in vim completion

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.

Jedi does not care what is in sys.path

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.

pydoc failure on windows

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.

goto() import following

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!

slow in large files

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)

Clarify how Jedi autocompletes

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!

imports + getattr completion

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.

psycopg2

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>

Complete requests

import requests

r = requests.post('http://google.com', {'foo': 'bar'})
r.st<tab>

This should return r.status_code.

iterators + strings + getattr completion

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.

'NoneType' object has no attribute 'rfind'

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'

Shifted CallDef.index for keyword argument

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

Request: docstrings and Sphinx documentation?

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.

Jedi with PyPy

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).

Convert README to .rst

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.

meta classes + if + array indexing + setattr completion

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! โ˜€๏ธ

Licensing

I think I will license Jedi with the GNU LGPL, what do you think?

Is anyone fond of GPL or BSD?

error completing on numpy.array

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

Request: Definition.fullname

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

Features

As written in the README, these features might be supported in the future:

  • function annotations (py3k feature)
  • class decorators (py3k feature)
  • getattr() / getattr / getattribute
  • sys.path modifications
  • manipulations of instances outside the instance variables, without using functions
  • mro
  • relative imports
  • operation support -> __mul__, __add__, etc.
  • assert / isinstance

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

python3 import failure

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

No definition found for `from pygments.formatters import TerminalFormatter`

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?

Why re.compile() is interpreted as str?

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).

Complete `self` in `for` loop

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.

script.get_definition error in dev head (6a98aaf)

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'

Renaming bug

 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

No completion returned when source is passed as an unicode object

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]:
[]

Use CLASS information after `if isinstance(object, CLASS)` block

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).

Script.get_definition for gobject function fails

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'

Nested list comprehensions cause parsing error

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

IndexError in jedi#goto

  • 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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.