forked from VimPlug/jedi
lo and behold - reversed is implemented - the force is strong with this one. fixes #24
This commit is contained in:
@@ -147,7 +147,7 @@ class Evaluator(object):
|
|||||||
for ass_expression_list, op in ass_details:
|
for ass_expression_list, op in ass_details:
|
||||||
new_result += finder.find_assignments(ass_expression_list[0], result, seek_name)
|
new_result += finder.find_assignments(ass_expression_list[0], result, seek_name)
|
||||||
result = new_result
|
result = new_result
|
||||||
return set(result)
|
return result
|
||||||
|
|
||||||
def eval_expression_list(self, expression_list):
|
def eval_expression_list(self, expression_list):
|
||||||
"""
|
"""
|
||||||
@@ -158,11 +158,13 @@ class Evaluator(object):
|
|||||||
debug.dbg('eval_expression_list: %s', expression_list)
|
debug.dbg('eval_expression_list: %s', expression_list)
|
||||||
result = []
|
result = []
|
||||||
p = precedence.create_precedence(expression_list)
|
p = precedence.create_precedence(expression_list)
|
||||||
return self._process_precedence_element(p)
|
return self._process_precedence_element(p) or []
|
||||||
|
|
||||||
|
# TODO remove
|
||||||
calls_iterator = iter(expression_list)
|
calls_iterator = iter(expression_list)
|
||||||
for each in calls_iterator:
|
for each in calls_iterator:
|
||||||
result += self._eval_statement_element(each)
|
result += self._eval_statement_element(each)
|
||||||
return set(result)
|
return result
|
||||||
|
|
||||||
def _process_precedence_element(self, el):
|
def _process_precedence_element(self, el):
|
||||||
if el is None:
|
if el is None:
|
||||||
@@ -294,7 +296,7 @@ class Evaluator(object):
|
|||||||
return []
|
return []
|
||||||
types = self.find_types(typ, current)
|
types = self.find_types(typ, current)
|
||||||
result = imports.strip_imports(self, types)
|
result = imports.strip_imports(self, types)
|
||||||
return self.follow_path(path, set(result), scope)
|
return self.follow_path(path, result, scope)
|
||||||
|
|
||||||
@debug.increase_indent
|
@debug.increase_indent
|
||||||
def execute(self, obj, params=(), evaluate_generator=False):
|
def execute(self, obj, params=(), evaluate_generator=False):
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import os
|
|||||||
|
|
||||||
from jedi._compatibility import builtins as _builtins
|
from jedi._compatibility import builtins as _builtins
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi.parser.representation import Base
|
from jedi.parser.representation import Base, IsScope
|
||||||
from jedi.cache import underscore_memoization
|
from jedi.cache import underscore_memoization
|
||||||
from jedi.evaluate.sys_path import get_sys_path
|
from jedi.evaluate.sys_path import get_sys_path
|
||||||
from jedi.parser.representation import Param
|
from jedi.parser.representation import Param
|
||||||
@@ -273,7 +273,7 @@ def _parse_function_doc(doc):
|
|||||||
return param_str, ret
|
return param_str, ret
|
||||||
|
|
||||||
|
|
||||||
class Builtin(CompiledObject):
|
class Builtin(CompiledObject, IsScope):
|
||||||
def get_defined_names(self):
|
def get_defined_names(self):
|
||||||
# Filter None, because it's really just a keyword, nobody wants to
|
# Filter None, because it's really just a keyword, nobody wants to
|
||||||
# access it.
|
# access it.
|
||||||
|
|||||||
@@ -247,7 +247,7 @@ class NameFinder(object):
|
|||||||
# this means that there are no default params,
|
# this means that there are no default params,
|
||||||
# so just ignore it.
|
# so just ignore it.
|
||||||
return res_new
|
return res_new
|
||||||
return set(res_new) | evaluator.eval_statement(r, seek_name=self.name_str)
|
return res_new + evaluator.eval_statement(r, seek_name=self.name_str)
|
||||||
|
|
||||||
def _handle_for_loops(self, loop):
|
def _handle_for_loops(self, loop):
|
||||||
# Take the first statement (for has always only
|
# Take the first statement (for has always only
|
||||||
|
|||||||
@@ -162,6 +162,13 @@ class FakeSubModule():
|
|||||||
line_offset = 0
|
line_offset = 0
|
||||||
|
|
||||||
|
|
||||||
|
class FakeArray(pr.Array):
|
||||||
|
def __init__(self, values, parent, arr_type=pr.Array.LIST):
|
||||||
|
p = (0, 0)
|
||||||
|
super(FakeArray, self).__init__(FakeSubModule, p, arr_type, parent)
|
||||||
|
self.values = values
|
||||||
|
|
||||||
|
|
||||||
class FakeStatement(pr.Statement):
|
class FakeStatement(pr.Statement):
|
||||||
def __init__(self, expression_list, start_pos=(0, 0)):
|
def __init__(self, expression_list, start_pos=(0, 0)):
|
||||||
p = start_pos
|
p = start_pos
|
||||||
|
|||||||
@@ -2,11 +2,11 @@
|
|||||||
Implementations of standard library functions, because it's not possible to
|
Implementations of standard library functions, because it's not possible to
|
||||||
understand them with Jedi.
|
understand them with Jedi.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from jedi._compatibility import unicode
|
from jedi._compatibility import unicode
|
||||||
from jedi.evaluate import compiled
|
from jedi.evaluate import compiled
|
||||||
from jedi.evaluate import representation as er
|
from jedi.evaluate import representation as er
|
||||||
from jedi.evaluate import iterable
|
from jedi.evaluate import iterable
|
||||||
|
from jedi.evaluate.helpers import FakeArray, FakeStatement
|
||||||
from jedi.parser import representation as pr
|
from jedi.parser import representation as pr
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
|
|
||||||
@@ -82,10 +82,26 @@ def builtins_super(evaluator, obj, params):
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
def builtins_reversed(evaluator, obj, params):
|
||||||
|
objects = _follow_param(evaluator, params, 0)
|
||||||
|
if objects:
|
||||||
|
# unpack the iterator values
|
||||||
|
objects = iterable.get_iterator_types(objects)
|
||||||
|
rev = reversed(objects)
|
||||||
|
# Repack iterator values and then run it the normal way. This is necessary,
|
||||||
|
# because `reversed` is a function and autocompletion would fail in certain
|
||||||
|
# cases like `reversed(x).__iter__` if we just returned the result
|
||||||
|
# directly.
|
||||||
|
stmts = [FakeStatement([r]) for r in rev]
|
||||||
|
objects = (FakeArray(stmts, objects[0].parent),)
|
||||||
|
return [er.Instance(evaluator, obj, objects)]
|
||||||
|
|
||||||
|
|
||||||
_implemented = {
|
_implemented = {
|
||||||
'builtins': {
|
'builtins': {
|
||||||
'getattr': builtins_getattr,
|
'getattr': builtins_getattr,
|
||||||
'type': builtins_type,
|
'type': builtins_type,
|
||||||
'super': builtins_super,
|
'super': builtins_super,
|
||||||
|
'reversed': builtins_reversed,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ class FooBar(object):
|
|||||||
raboof = 'fourtytwo'
|
raboof = 'fourtytwo'
|
||||||
|
|
||||||
# targets should be working
|
# targets should be working
|
||||||
target = u''
|
target = ''
|
||||||
for char in ['f', 'u', 'u']:
|
for char in ['f', 'u', 'u']:
|
||||||
target += char
|
target += char
|
||||||
#? float()
|
#? float()
|
||||||
|
|||||||
Reference in New Issue
Block a user