mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-09 07:14:48 +08:00
made dynamic *args/**args work
This commit is contained in:
18
dynamic.py
18
dynamic.py
@@ -21,7 +21,22 @@ class ParamListener(object):
|
|||||||
|
|
||||||
|
|
||||||
def search_params(param):
|
def search_params(param):
|
||||||
|
"""
|
||||||
|
This is a dynamic search for params. If you try to complete a type:
|
||||||
|
>>> def func(foo):
|
||||||
|
>>> # here is the completion
|
||||||
|
>>> foo
|
||||||
|
>>> func(1)
|
||||||
|
>>> func("")
|
||||||
|
|
||||||
|
It is not known what the type is, because it cannot be guessed with
|
||||||
|
recursive madness. Therefore one has to analyse the statements that are
|
||||||
|
calling the function, as well as analyzing the incoming params.
|
||||||
|
"""
|
||||||
def get_params_for_module(module):
|
def get_params_for_module(module):
|
||||||
|
"""
|
||||||
|
Returns the values of a param, or an empty array.
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
possible_stmts = current_module.used_names[func_name]
|
possible_stmts = current_module.used_names[func_name]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
@@ -52,7 +67,8 @@ def search_params(param):
|
|||||||
arr = param.assignment_details[0][1]
|
arr = param.assignment_details[0][1]
|
||||||
else:
|
else:
|
||||||
arr = param.get_assignment_calls()
|
arr = param.get_assignment_calls()
|
||||||
param_name = str(arr[0][0].name)
|
offset = 1 if arr[0][0] in ['*', '**'] else 0
|
||||||
|
param_name = str(arr[0][offset].name)
|
||||||
|
|
||||||
current_module = param.get_parent_until()
|
current_module = param.get_parent_until()
|
||||||
|
|
||||||
|
|||||||
@@ -447,6 +447,7 @@ class Execution(Executable):
|
|||||||
|
|
||||||
def _get_function_returns(self, evaluate_generator):
|
def _get_function_returns(self, evaluate_generator):
|
||||||
""" A normal Function execution """
|
""" A normal Function execution """
|
||||||
|
# Feed the listeners, with the params.
|
||||||
for listener in self.base.listeners:
|
for listener in self.base.listeners:
|
||||||
listener.execute(self.get_params())
|
listener.execute(self.get_params())
|
||||||
func = self.base.get_decorated_func()
|
func = self.base.get_decorated_func()
|
||||||
|
|||||||
@@ -30,9 +30,9 @@ def func(a):
|
|||||||
# *args, **args
|
# *args, **args
|
||||||
# -----------------
|
# -----------------
|
||||||
def arg(*args):
|
def arg(*args):
|
||||||
##? tuple()
|
#? tuple()
|
||||||
args
|
args
|
||||||
##? int()
|
#? int()
|
||||||
args[0]
|
args[0]
|
||||||
|
|
||||||
arg(1,"")
|
arg(1,"")
|
||||||
|
|||||||
Reference in New Issue
Block a user