mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-10 15:51:51 +08:00
ternary operators work now, list comprehensions preparation
This commit is contained in:
18
evaluate.py
18
evaluate.py
@@ -6,7 +6,7 @@ follow_statement -> follow_call -> follow_paths -> follow_path
|
|||||||
|
|
||||||
TODO doc
|
TODO doc
|
||||||
TODO list comprehensions, priority? +1
|
TODO list comprehensions, priority? +1
|
||||||
TODO `a = b if b else None` expressions
|
TODO magic methods: __mul__, __add__, etc.
|
||||||
TODO evaluate asserts (type safety)
|
TODO evaluate asserts (type safety)
|
||||||
|
|
||||||
python 3 stuff:
|
python 3 stuff:
|
||||||
@@ -66,7 +66,6 @@ class MultiLevelAttributeError(BaseException):
|
|||||||
return 'Original:\n\n' + ''.join(tb)
|
return 'Original:\n\n' + ''.join(tb)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def clear_caches():
|
def clear_caches():
|
||||||
for m in memoize_caches:
|
for m in memoize_caches:
|
||||||
m.clear()
|
m.clear()
|
||||||
@@ -1039,15 +1038,26 @@ def follow_call_list(scope, call_list):
|
|||||||
else:
|
else:
|
||||||
result = []
|
result = []
|
||||||
for calls in call_list:
|
for calls in call_list:
|
||||||
for call in calls:
|
calls_iterator = iter(calls)
|
||||||
|
for call in calls_iterator:
|
||||||
if parsing.Array.is_type(call, parsing.Array.NOARRAY):
|
if parsing.Array.is_type(call, parsing.Array.NOARRAY):
|
||||||
result += follow_call_list(scope, call)
|
result += follow_call_list(scope, call)
|
||||||
else:
|
else:
|
||||||
# with things like params, these can also be functions, etc
|
# with things like params, these can also be functions, etc
|
||||||
if isinstance(call, (Function, parsing.Class)):
|
if isinstance(call, (Function, parsing.Class)):
|
||||||
result.append(call)
|
result.append(call)
|
||||||
|
# The string tokens are just operations (+, -, etc.)
|
||||||
elif not isinstance(call, str):
|
elif not isinstance(call, str):
|
||||||
# The string tokens are just operations (+, -, etc.)
|
# ternary operators
|
||||||
|
if str(call.name) == 'if':
|
||||||
|
while True:
|
||||||
|
call = next(calls_iterator)
|
||||||
|
try:
|
||||||
|
if str(call.name) == 'else':
|
||||||
|
break
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
continue
|
||||||
result += follow_call(scope, call)
|
result += follow_call(scope, call)
|
||||||
return set(result)
|
return set(result)
|
||||||
|
|
||||||
|
|||||||
@@ -633,6 +633,9 @@ class Statement(Simple):
|
|||||||
if close_brackets:
|
if close_brackets:
|
||||||
result = result.parent
|
result = result.parent
|
||||||
close_brackets = False
|
close_brackets = False
|
||||||
|
if result.__class__ == Call:
|
||||||
|
result = result.parent
|
||||||
|
close_brackets = False
|
||||||
call = Call(tok, c_type, self, result)
|
call = Call(tok, c_type, self, result)
|
||||||
result.add_to_current_field(call)
|
result.add_to_current_field(call)
|
||||||
result = call
|
result = call
|
||||||
|
|||||||
@@ -38,6 +38,33 @@ for a4, (b4, c4) in (1,("", list)), (1,("", list)):
|
|||||||
#? []
|
#? []
|
||||||
c4.upper
|
c4.upper
|
||||||
|
|
||||||
|
# -----------------
|
||||||
|
# list comprehensions
|
||||||
|
# -----------------
|
||||||
|
|
||||||
|
a = ['' for abc in [1]]
|
||||||
|
|
||||||
|
#? str()
|
||||||
|
a[0]
|
||||||
|
|
||||||
|
|
||||||
|
# -----------------
|
||||||
|
# ternary operator
|
||||||
|
# -----------------
|
||||||
|
|
||||||
|
a = 3
|
||||||
|
b = '' if a else set()
|
||||||
|
#? str() set()
|
||||||
|
b
|
||||||
|
|
||||||
|
def ret(a):
|
||||||
|
return ['' if a else set()]
|
||||||
|
|
||||||
|
#? str() set()
|
||||||
|
ret(1)[0]
|
||||||
|
#? str() set()
|
||||||
|
ret()[0]
|
||||||
|
|
||||||
# -----------------
|
# -----------------
|
||||||
# with statements
|
# with statements
|
||||||
# -----------------
|
# -----------------
|
||||||
@@ -58,8 +85,8 @@ with open('') as f1, open('') as f2:
|
|||||||
# -----------------
|
# -----------------
|
||||||
|
|
||||||
def global_define():
|
def global_define():
|
||||||
global glob
|
global global_var_in_func
|
||||||
glob = 3
|
global_var_in_func = 3
|
||||||
|
|
||||||
#? ['real']
|
#? int()
|
||||||
glob.real
|
global_var_in_func
|
||||||
|
|||||||
Reference in New Issue
Block a user