mirror of
https://github.com/davidhalter/jedi.git
synced 2026-02-20 16:18:27 +08:00
Start to rework dynamic params. However goto is now needed first.
This commit is contained in:
@@ -177,7 +177,7 @@ class Evaluator(object):
|
|||||||
for trailer in element.children[1:]:
|
for trailer in element.children[1:]:
|
||||||
if trailer == '**': # has a power operation.
|
if trailer == '**': # has a power operation.
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
types = self._eval_trailer(types, trailer)
|
types = self.eval_trailer(types, trailer)
|
||||||
|
|
||||||
return types
|
return types
|
||||||
elif pr.is_node(element, 'testlist_star_expr', 'testlist'):
|
elif pr.is_node(element, 'testlist_star_expr', 'testlist'):
|
||||||
@@ -223,13 +223,13 @@ class Evaluator(object):
|
|||||||
return [iterable.Comprehension.from_atom(self, atom)]
|
return [iterable.Comprehension.from_atom(self, atom)]
|
||||||
return [iterable.Array(self, atom)]
|
return [iterable.Array(self, atom)]
|
||||||
|
|
||||||
def _eval_trailer(self, types, trailer):
|
def eval_trailer(self, types, trailer):
|
||||||
trailer_op, node = trailer.children[:2]
|
trailer_op, node = trailer.children[:2]
|
||||||
if node == ')': # `arglist` is optional.
|
if node == ')': # `arglist` is optional.
|
||||||
node = ()
|
node = ()
|
||||||
new_types = []
|
new_types = []
|
||||||
for typ in types:
|
for typ in types:
|
||||||
debug.dbg('_eval_trailer: %s in scope %s', trailer, typ)
|
debug.dbg('eval_trailer: %s in scope %s', trailer, typ)
|
||||||
if trailer_op == '.':
|
if trailer_op == '.':
|
||||||
new_types += self.find_types(typ, node)
|
new_types += self.find_types(typ, node)
|
||||||
elif trailer_op == '(':
|
elif trailer_op == '(':
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ def search_params(evaluator, param):
|
|||||||
"""
|
"""
|
||||||
if not settings.dynamic_params:
|
if not settings.dynamic_params:
|
||||||
return []
|
return []
|
||||||
|
from jedi.evaluate import representation as er
|
||||||
|
|
||||||
def get_params_for_module(module):
|
def get_params_for_module(module):
|
||||||
"""
|
"""
|
||||||
@@ -64,13 +65,30 @@ def search_params(evaluator, param):
|
|||||||
@memoize_default([], evaluator_is_first_arg=True)
|
@memoize_default([], evaluator_is_first_arg=True)
|
||||||
def get_posibilities(evaluator, module, func_name):
|
def get_posibilities(evaluator, module, func_name):
|
||||||
try:
|
try:
|
||||||
possible_stmts = module.used_names[func_name]
|
names = module.used_names[func_name]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
for stmt in possible_stmts:
|
for name in names:
|
||||||
if isinstance(stmt, pr.Import):
|
stmt = name.get_definition()
|
||||||
|
if not isinstance(stmt, pr.ExprStmt):
|
||||||
continue
|
continue
|
||||||
|
print(stmt, stmt.start_pos, name.parent)
|
||||||
|
try:
|
||||||
|
trailer = name.parent.children[1]
|
||||||
|
except IndexError:
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
types = evaluator.goto(name)
|
||||||
|
|
||||||
|
if compare in types:
|
||||||
|
# Only if we have the correct function we execute
|
||||||
|
# it, otherwise just ignore it.
|
||||||
|
evaluator.eval_trailer(types, trailer)
|
||||||
|
|
||||||
|
continue
|
||||||
|
|
||||||
|
|
||||||
calls = helpers.scan_statement_for_calls(stmt, func_name)
|
calls = helpers.scan_statement_for_calls(stmt, func_name)
|
||||||
for c in calls:
|
for c in calls:
|
||||||
# no execution means that params cannot be set
|
# no execution means that params cannot be set
|
||||||
@@ -120,7 +138,7 @@ def search_params(evaluator, param):
|
|||||||
result = []
|
result = []
|
||||||
for params in get_posibilities(evaluator, module, func_name):
|
for params in get_posibilities(evaluator, module, func_name):
|
||||||
for p in params:
|
for p in params:
|
||||||
if str(p) == param_name:
|
if str(p) == param.name:
|
||||||
result += evaluator.eval_statement(p.get_definition())
|
result += evaluator.eval_statement(p.get_definition())
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@@ -132,15 +150,6 @@ def search_params(evaluator, param):
|
|||||||
func_name = unicode(func.parent.name)
|
func_name = unicode(func.parent.name)
|
||||||
compare = func.parent
|
compare = func.parent
|
||||||
|
|
||||||
# get the param name
|
|
||||||
if param.assignment_details:
|
|
||||||
# first assignment details, others would be a syntax error
|
|
||||||
expression_list, op = param.assignment_details[0]
|
|
||||||
else:
|
|
||||||
expression_list = param.expression_list()
|
|
||||||
offset = 1 if expression_list[0] in ['*', '**'] else 0
|
|
||||||
param_name = str(expression_list[offset].name)
|
|
||||||
|
|
||||||
# add the listener
|
# add the listener
|
||||||
listener = ParamListener()
|
listener = ParamListener()
|
||||||
func.listeners.add(listener)
|
func.listeners.add(listener)
|
||||||
|
|||||||
Reference in New Issue
Block a user