1
0
forked from VimPlug/jedi

some code - just written for @dbrgn

This commit is contained in:
Dave Halter
2014-03-10 23:06:39 +01:00
parent f8336d7176
commit 6c5e91da69
4 changed files with 41 additions and 26 deletions

View File

@@ -125,15 +125,21 @@ class Evaluator(object):
result = self.eval_expression_list(expression_list) result = self.eval_expression_list(expression_list)
ass_details = stmt.assignment_details ass_details = stmt.assignment_details
if ass_details and ass_details[0][1] != '=' and not isinstance(stmt, if ass_details and ass_details[0][1] != '=' and not isinstance(stmt, er.InstanceElement): # TODO don't check for this.
er.InstanceElement): # TODO don't check for this.
#print('LEFT', ass_details, stmt, stmt.parent)
expr_list, operator = ass_details[0] expr_list, operator = ass_details[0]
# `=` is always the last character in aug assignments -> -1
operator = operator[:-1]
name = str(expr_list[0].name) name = str(expr_list[0].name)
start_pos = stmt.start_pos[0] - 1, stmt.start_pos[1] + 30000 left = self.find_types(stmt.parent, name, stmt.start_pos)
left_result = self.find_types(stmt.parent, name, start_pos) if isinstance(stmt.parent, pr.ForFlow):
# `=` is always the last character in aug assignments # iterate through result and add the values, that's possible
result = precedence.calculate(left_result, operator[:-1], result) # 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: elif len(stmt.get_set_vars()) > 1 and seek_name and ass_details:
# Assignment checking is only important if the statement defines # Assignment checking is only important if the statement defines
# multiple variables. # multiple variables.

View File

@@ -94,7 +94,7 @@ class Array(use_metaclass(CachedMetaClass, pr.Base)):
result = list(self._follow_values(self._array.values)) result = list(self._follow_values(self._array.values))
result += check_array_additions(self._evaluator, self) result += check_array_additions(self._evaluator, self)
return set(result) return result
def get_exact_index_types(self, mixed_index): def get_exact_index_types(self, mixed_index):
""" Here the index is an int/str. Raises IndexError/KeyError """ """ Here the index is an int/str. Raises IndexError/KeyError """

View File

@@ -335,7 +335,7 @@ class Function(use_metaclass(CachedMetaClass, pr.IsScope)):
if not self.is_decorated: if not self.is_decorated:
for dec in reversed(self.base_func.decorators): for dec in reversed(self.base_func.decorators):
debug.dbg('decorator: %s %s', dec, f) 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): if not len(dec_results):
debug.warning('decorator not found: %s on %s', dec, self.base_func) debug.warning('decorator not found: %s on %s', dec, self.base_func)
return None return None

View File

@@ -34,24 +34,10 @@ def calculate(number):
# strings # strings
# ----------------- # -----------------
class FooBar(object): x = 'upp' + 'e'
muahaha = 3.0
raboof = 'fourtytwo'
x = 'mua' + 'ha' #? str.upper
getattr(str, x + 'r')
#? 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
# ----------------- # -----------------
# assignments # assignments
@@ -71,3 +57,26 @@ i -= 3
i += 1 i += 1
#? int() #? int()
x[i] 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)