mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 14:04:26 +08:00
globals
This commit is contained in:
17
evaluate.py
17
evaluate.py
@@ -5,6 +5,7 @@ follow_statement -> follow_call -> follow_paths -> follow_path
|
||||
`get_names_for_scope` and `get_scopes_for_name` are search functions
|
||||
|
||||
TODO include super classes
|
||||
TOOD nonlocal statement
|
||||
"""
|
||||
from _compatibility import next
|
||||
|
||||
@@ -123,7 +124,6 @@ class Execution(Exec):
|
||||
|
||||
debug.dbg('exec stmts=', stmts, self.base, repr(self))
|
||||
|
||||
#print stmts
|
||||
return stmts
|
||||
|
||||
@memoize(default=[])
|
||||
@@ -249,8 +249,15 @@ def get_scopes_for_name(scope, name, search_global=False):
|
||||
res_new = []
|
||||
for r in result:
|
||||
if isinstance(r, parsing.Statement):
|
||||
scopes = follow_statement(r, seek_name=name)
|
||||
res_new += remove_statements(scopes)
|
||||
if r.is_global():
|
||||
res_new += []
|
||||
for token_name in r.token_list[1:]:
|
||||
if isinstance(token_name, parsing.Name):
|
||||
res_new += get_scopes_for_name(r.parent,
|
||||
str(token_name))
|
||||
else:
|
||||
scopes = follow_statement(r, seek_name=name)
|
||||
res_new += remove_statements(scopes)
|
||||
else:
|
||||
res_new.append(r)
|
||||
debug.dbg('sfn remove, new: %s, old: %s' % (res_new, result))
|
||||
@@ -266,13 +273,12 @@ def get_scopes_for_name(scope, name, search_global=False):
|
||||
else:
|
||||
par = scope.parent
|
||||
if isinstance(par, parsing.Flow):
|
||||
# TODO get Flow data, which is defined by the loop
|
||||
# (or with)
|
||||
if par.command == 'for':
|
||||
# take the first statement (for has always only
|
||||
# one, remember `in`). And follow it. After that,
|
||||
# get the types which are in the array
|
||||
arrays = follow_statement(par.inits[0])
|
||||
# TODO for loops can have tuples as set_vars
|
||||
for array in arrays:
|
||||
result += array.get_index_types()
|
||||
else:
|
||||
@@ -465,7 +471,6 @@ def follow_path(path, scope):
|
||||
debug.warning('strange function call with {}', current, scope)
|
||||
else:
|
||||
if isinstance(scope, parsing.Function):
|
||||
# TODO this is never reached, just remove it?
|
||||
# TODO check default function methods and return them
|
||||
result = []
|
||||
else:
|
||||
|
||||
4
ftest.py
4
ftest.py
@@ -2,7 +2,7 @@
|
||||
|
||||
import functions
|
||||
|
||||
#functions.debug.debug_function = functions.debug.print_to_stdout
|
||||
functions.debug.debug_function = functions.debug.print_to_stdout
|
||||
functions.debug.ignored_modules = ['parsing', 'builtin']
|
||||
#functions.debug.ignored_modules = ['parsing', 'builtin', 'evaluate', 'modules']
|
||||
functions.modules.module_find_path.insert(0, '.')
|
||||
@@ -14,7 +14,7 @@ path = os.path.join(os.getcwd(), f_name)
|
||||
f = open(path)
|
||||
code = f.read()
|
||||
for i in range(1):
|
||||
completions = functions.complete(code, 150, 200, path)
|
||||
completions = functions.complete(code, 160, 200, path)
|
||||
|
||||
print '\n', ', '.join(sorted(str(c) for c in completions))
|
||||
#print [n.name for n in completions]
|
||||
|
||||
12
parsetest.py
12
parsetest.py
@@ -124,7 +124,6 @@ def flow_test(a):
|
||||
|
||||
if True or a:
|
||||
print a
|
||||
|
||||
# completion
|
||||
import time
|
||||
class c1():
|
||||
@@ -148,3 +147,14 @@ c = b().c3(); abc = datetime; return [abc][0]. ;pylab.; add(1+2,2).; for fi in [
|
||||
abc = [1,2+3]; abc[0].
|
||||
import pylab; def add(a1,b1): nana = 1; return a1+b1
|
||||
flow_test.; a12, (b12, c12) = (1,(list, "")); b12.
|
||||
|
||||
|
||||
|
||||
def globalfunc():
|
||||
global globalvar, globalvar2
|
||||
globalvar = 3
|
||||
|
||||
|
||||
|
||||
|
||||
globalvar.
|
||||
|
||||
@@ -543,6 +543,10 @@ class Statement(Simple):
|
||||
# array
|
||||
return self._assignment_details or []
|
||||
|
||||
def is_global(self):
|
||||
# first keyword of the first token is global -> must be a global
|
||||
return str(self.token_list[0]) == "global"
|
||||
|
||||
def get_assignment_calls(self):
|
||||
"""
|
||||
This is not done in the main parser, because it might be slow and
|
||||
|
||||
@@ -1,7 +1,31 @@
|
||||
# -----------------
|
||||
# for loops
|
||||
# -----------------
|
||||
|
||||
for a in [1,2]:
|
||||
#? ['real']
|
||||
a.real
|
||||
|
||||
for a1 in 1,"":
|
||||
#? ['real']
|
||||
a1.real
|
||||
#? ['upper']
|
||||
a1.upper
|
||||
|
||||
for a3, b3 in (1,""), (1,""):
|
||||
#? ['real']
|
||||
a3.real
|
||||
#? []
|
||||
a3.upper
|
||||
#? []
|
||||
b3.real
|
||||
#? ['upper']
|
||||
b3.upper
|
||||
|
||||
# -----------------
|
||||
# with statements
|
||||
# -----------------
|
||||
|
||||
with open('') as f:
|
||||
#? ['closed']
|
||||
f.closed
|
||||
@@ -13,6 +37,10 @@ with open('') as f1, open('') as f2:
|
||||
f2.closed
|
||||
|
||||
|
||||
# -----------------
|
||||
# global vars
|
||||
# -----------------
|
||||
|
||||
def global_define():
|
||||
global glob
|
||||
glob = 3
|
||||
|
||||
Reference in New Issue
Block a user