forked from VimPlug/jedi
some code - just written for @dbrgn
This commit is contained in:
@@ -125,15 +125,21 @@ class Evaluator(object):
|
||||
result = self.eval_expression_list(expression_list)
|
||||
|
||||
ass_details = stmt.assignment_details
|
||||
if ass_details and ass_details[0][1] != '=' and not isinstance(stmt,
|
||||
er.InstanceElement): # TODO don't check for this.
|
||||
#print('LEFT', ass_details, stmt, stmt.parent)
|
||||
if ass_details and ass_details[0][1] != '=' and not isinstance(stmt, er.InstanceElement): # TODO don't check for this.
|
||||
expr_list, operator = ass_details[0]
|
||||
# `=` is always the last character in aug assignments -> -1
|
||||
operator = operator[:-1]
|
||||
name = str(expr_list[0].name)
|
||||
start_pos = stmt.start_pos[0] - 1, stmt.start_pos[1] + 30000
|
||||
left_result = self.find_types(stmt.parent, name, start_pos)
|
||||
# `=` is always the last character in aug assignments
|
||||
result = precedence.calculate(left_result, operator[:-1], result)
|
||||
left = self.find_types(stmt.parent, name, stmt.start_pos)
|
||||
if isinstance(stmt.parent, pr.ForFlow):
|
||||
# iterate through result and add the values, that's possible
|
||||
# only in for loops without clutter, because they are
|
||||
# predictable.
|
||||
for r in result:
|
||||
left = precedence.calculate(left, operator, [r])
|
||||
result = left
|
||||
else:
|
||||
result = precedence.calculate(left, operator, result)
|
||||
elif len(stmt.get_set_vars()) > 1 and seek_name and ass_details:
|
||||
# Assignment checking is only important if the statement defines
|
||||
# multiple variables.
|
||||
|
||||
@@ -94,7 +94,7 @@ class Array(use_metaclass(CachedMetaClass, pr.Base)):
|
||||
|
||||
result = list(self._follow_values(self._array.values))
|
||||
result += check_array_additions(self._evaluator, self)
|
||||
return set(result)
|
||||
return result
|
||||
|
||||
def get_exact_index_types(self, mixed_index):
|
||||
""" Here the index is an int/str. Raises IndexError/KeyError """
|
||||
|
||||
@@ -335,7 +335,7 @@ class Function(use_metaclass(CachedMetaClass, pr.IsScope)):
|
||||
if not self.is_decorated:
|
||||
for dec in reversed(self.base_func.decorators):
|
||||
debug.dbg('decorator: %s %s', dec, f)
|
||||
dec_results = set(self._evaluator.eval_statement(dec))
|
||||
dec_results = self._evaluator.eval_statement(dec)
|
||||
if not len(dec_results):
|
||||
debug.warning('decorator not found: %s on %s', dec, self.base_func)
|
||||
return None
|
||||
|
||||
@@ -34,24 +34,10 @@ def calculate(number):
|
||||
# strings
|
||||
# -----------------
|
||||
|
||||
class FooBar(object):
|
||||
muahaha = 3.0
|
||||
raboof = 'fourtytwo'
|
||||
x = 'upp' + 'e'
|
||||
|
||||
x = 'mua' + 'ha'
|
||||
|
||||
#? float()
|
||||
getattr(FooBar, x + 'ha')
|
||||
|
||||
|
||||
# github #24
|
||||
target = u''
|
||||
for char in reversed(['f', 'o', 'o', 'b', 'a', 'r']):
|
||||
target += char
|
||||
|
||||
answer = getattr(FooBar, target)
|
||||
##? str()
|
||||
answer
|
||||
#? str.upper
|
||||
getattr(str, x + 'r')
|
||||
|
||||
# -----------------
|
||||
# assignments
|
||||
@@ -71,3 +57,26 @@ i -= 3
|
||||
i += 1
|
||||
#? int()
|
||||
x[i]
|
||||
|
||||
# -----------------
|
||||
# for flow assignments
|
||||
# -----------------
|
||||
|
||||
class FooBar(object):
|
||||
fuu = 0.1
|
||||
raboof = 'fourtytwo'
|
||||
|
||||
# targets should be working
|
||||
target = u''
|
||||
for char in ['f', 'u', 'u']:
|
||||
target += char
|
||||
#? float()
|
||||
getattr(FooBar, target)
|
||||
|
||||
# github #24
|
||||
target = u''
|
||||
for char in reversed(['f', 'o', 'o', 'b', 'a', 'r']):
|
||||
target += char
|
||||
|
||||
#? str()
|
||||
getattr(FooBar, target)
|
||||
|
||||
Reference in New Issue
Block a user