mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 14:04:26 +08:00
removed old code & pep8
This commit is contained in:
105
evaluate.py
105
evaluate.py
@@ -3,33 +3,6 @@ import __builtin__
|
|||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
|
|
||||||
class Arr(object):
|
|
||||||
"""
|
|
||||||
- caching one function
|
|
||||||
- iterating over arrays objects
|
|
||||||
- test
|
|
||||||
"""
|
|
||||||
cache = []
|
|
||||||
|
|
||||||
def __init__(self, scope, ):
|
|
||||||
self.counter = 0
|
|
||||||
self.types = [] # each an array, like: [[list], [A,B]]
|
|
||||||
|
|
||||||
def __iter__(self):
|
|
||||||
return self
|
|
||||||
|
|
||||||
def next(self):
|
|
||||||
if self.counter < len(Arr.cache):
|
|
||||||
return Arr.cache[self.counter]
|
|
||||||
else:
|
|
||||||
if blub:
|
|
||||||
Arr.cache.append(1)
|
|
||||||
self.counter += 1
|
|
||||||
return Arr.cache[self.counter]
|
|
||||||
else:
|
|
||||||
raise StopIteration
|
|
||||||
|
|
||||||
|
|
||||||
class Instance(object):
|
class Instance(object):
|
||||||
""" This class is used to evaluate instances. """
|
""" This class is used to evaluate instances. """
|
||||||
def __init__(self, cl):
|
def __init__(self, cl):
|
||||||
@@ -84,6 +57,7 @@ def get_names_for_scope(scope):
|
|||||||
scope = scope.parent
|
scope = scope.parent
|
||||||
return compl
|
return compl
|
||||||
|
|
||||||
|
|
||||||
def get_scopes_for_name(scope, name, search_global=False):
|
def get_scopes_for_name(scope, name, search_global=False):
|
||||||
"""
|
"""
|
||||||
:return: List of Names. Their parents are the scopes, they are defined in.
|
:return: List of Names. Their parents are the scopes, they are defined in.
|
||||||
@@ -167,7 +141,7 @@ def follow_path(path, input):
|
|||||||
# this must be an execution, either () or []
|
# this must be an execution, either () or []
|
||||||
if current.arr_type == parsing.Array.LIST:
|
if current.arr_type == parsing.Array.LIST:
|
||||||
print 'dini mami'
|
print 'dini mami'
|
||||||
result = [] # TODO eval lists
|
result = [] # TODO eval lists
|
||||||
else:
|
else:
|
||||||
# input must be a class or func -> make an instance or execution
|
# input must be a class or func -> make an instance or execution
|
||||||
if isinstance(input, parsing.Class):
|
if isinstance(input, parsing.Class):
|
||||||
@@ -190,81 +164,6 @@ def follow_path(path, input):
|
|||||||
return follow_paths(path, result)
|
return follow_paths(path, result)
|
||||||
|
|
||||||
|
|
||||||
def follow_array(scope, array):
|
|
||||||
yield 1
|
|
||||||
|
|
||||||
|
|
||||||
def follow_path_old(scope, path):
|
|
||||||
"""
|
|
||||||
Follow a path of python names.
|
|
||||||
recursive!
|
|
||||||
:returns: list(Scope)
|
|
||||||
"""
|
|
||||||
compl = get_names_for_scope(scope)
|
|
||||||
print path, compl
|
|
||||||
|
|
||||||
path = list(path)
|
|
||||||
name = path.pop(0)
|
|
||||||
scopes = []
|
|
||||||
|
|
||||||
# make the full comparison, because the names have to match exactly
|
|
||||||
compl = [c for c in compl if [name] == list(c.names)]
|
|
||||||
# TODO differentiate between the different comp input (some are overridden)
|
|
||||||
for c in compl:
|
|
||||||
p_class = c.parent.__class__
|
|
||||||
if p_class == parsing.Class or p_class == parsing.Scope:
|
|
||||||
scopes.append(c.parent)
|
|
||||||
#elif p_class == parsing.Function:
|
|
||||||
elif p_class == parsing.Statement:
|
|
||||||
print 'state', c.parent.token_list, c.parent.get_assignment_calls()
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
print 'error follow_path:', p_class, repr(c.parent)
|
|
||||||
|
|
||||||
if path:
|
|
||||||
new_scopes = []
|
|
||||||
for s in tuple(scopes):
|
|
||||||
new_scopes += follow_path(s, tuple(path))
|
|
||||||
scopes = new_scopes
|
|
||||||
return set(scopes)
|
|
||||||
|
|
||||||
def _parseassignment(self):
|
|
||||||
""" TODO remove or replace, at the moment not used """
|
|
||||||
assign = ''
|
|
||||||
token_type, tok, indent = self.next()
|
|
||||||
if token_type == tokenize.STRING or tok == 'str':
|
|
||||||
return '""'
|
|
||||||
elif tok == '(' or tok == 'tuple':
|
|
||||||
return '()'
|
|
||||||
elif tok == '[' or tok == 'list':
|
|
||||||
return '[]'
|
|
||||||
elif tok == '{' or tok == 'dict':
|
|
||||||
return '{}'
|
|
||||||
elif token_type == tokenize.NUMBER:
|
|
||||||
return '0'
|
|
||||||
elif tok == 'open' or tok == 'file':
|
|
||||||
return 'file'
|
|
||||||
elif tok == 'None':
|
|
||||||
return '_PyCmplNoType()'
|
|
||||||
elif tok == 'type':
|
|
||||||
return 'type(_PyCmplNoType)' # only for method resolution
|
|
||||||
else:
|
|
||||||
assign += tok
|
|
||||||
level = 0
|
|
||||||
while True:
|
|
||||||
token_type, tok, indent = self.next()
|
|
||||||
if tok in ('(', '{', '['):
|
|
||||||
level += 1
|
|
||||||
elif tok in (']', '}', ')'):
|
|
||||||
level -= 1
|
|
||||||
if level == 0:
|
|
||||||
break
|
|
||||||
elif level == 0:
|
|
||||||
if tok in (';', '\n'):
|
|
||||||
break
|
|
||||||
assign += tok
|
|
||||||
return "%s" % assign
|
|
||||||
|
|
||||||
def dbg(*args):
|
def dbg(*args):
|
||||||
if debug_function:
|
if debug_function:
|
||||||
debug_function(*args)
|
debug_function(*args)
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
import parsing
|
import parsing
|
||||||
import evaluate
|
import evaluate
|
||||||
import re
|
import re
|
||||||
|
|||||||
@@ -511,7 +511,7 @@ class Statement(Simple):
|
|||||||
call = Call(tok, result)
|
call = Call(tok, result)
|
||||||
result = result.set_next_chain_call(call)
|
result = result.set_next_chain_call(call)
|
||||||
is_chain = False
|
is_chain = False
|
||||||
close_brackets = False
|
close_brackets = False
|
||||||
else:
|
else:
|
||||||
if close_brackets:
|
if close_brackets:
|
||||||
result = result.parent
|
result = result.parent
|
||||||
|
|||||||
Reference in New Issue
Block a user