forked from VimPlug/jedi
support for dynamic params in classes
This commit is contained in:
12
dynamic.py
12
dynamic.py
@@ -55,12 +55,10 @@ def search_params(param):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
func = param.get_parent_until(parsing.Function)
|
func = param.get_parent_until(parsing.Function)
|
||||||
|
current_module = param.get_parent_until()
|
||||||
# add the listener
|
|
||||||
listener = ParamListener()
|
|
||||||
func.listeners.add(listener)
|
|
||||||
|
|
||||||
func_name = str(func.name)
|
func_name = str(func.name)
|
||||||
|
if func_name == '__init__' and isinstance(func.parent, parsing.Class):
|
||||||
|
func_name = str(func.parent.name)
|
||||||
|
|
||||||
# get the param name
|
# get the param name
|
||||||
if param.assignment_details:
|
if param.assignment_details:
|
||||||
@@ -70,7 +68,9 @@ def search_params(param):
|
|||||||
offset = 1 if arr[0][0] in ['*', '**'] else 0
|
offset = 1 if arr[0][0] in ['*', '**'] else 0
|
||||||
param_name = str(arr[0][offset].name)
|
param_name = str(arr[0][offset].name)
|
||||||
|
|
||||||
current_module = param.get_parent_until()
|
# add the listener
|
||||||
|
listener = ParamListener()
|
||||||
|
func.listeners.add(listener)
|
||||||
|
|
||||||
result = get_params_for_module(current_module)
|
result = get_params_for_module(current_module)
|
||||||
|
|
||||||
|
|||||||
18
evaluate.py
18
evaluate.py
@@ -137,14 +137,22 @@ class Executable(object):
|
|||||||
|
|
||||||
class Instance(Executable):
|
class Instance(Executable):
|
||||||
""" This class is used to evaluate instances. """
|
""" This class is used to evaluate instances. """
|
||||||
|
def __init__(self, base, var_args=parsing.Array(None, None)):
|
||||||
|
super(Instance, self).__init__(base, var_args)
|
||||||
|
|
||||||
|
# need to execute the __init__ function, because the dynamic param
|
||||||
|
# searching needs it.
|
||||||
|
try:
|
||||||
|
init_func = self.get_subscope_by_name('__init__')
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
self.get_init_execution(init_func).get_return_types()
|
||||||
|
|
||||||
@memoize_default()
|
@memoize_default()
|
||||||
def get_init_execution(self, func):
|
def get_init_execution(self, func):
|
||||||
if isinstance(func, parsing.Function):
|
instance_el = InstanceElement(self, Function(func))
|
||||||
instance_el = InstanceElement(self, Function(func))
|
return Execution(instance_el, self.var_args)
|
||||||
return Execution(instance_el, self.var_args)
|
|
||||||
else:
|
|
||||||
return func
|
|
||||||
|
|
||||||
def get_func_self_name(self, func):
|
def get_func_self_name(self, func):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -58,3 +58,24 @@ def func(c=1):
|
|||||||
return c
|
return c
|
||||||
|
|
||||||
func(1.0)
|
func(1.0)
|
||||||
|
|
||||||
|
# -----------------
|
||||||
|
# classes
|
||||||
|
# -----------------
|
||||||
|
|
||||||
|
class A():
|
||||||
|
def __init__(self, a):
|
||||||
|
#? str()
|
||||||
|
a
|
||||||
|
|
||||||
|
A("s")
|
||||||
|
|
||||||
|
class A():
|
||||||
|
def __init__(self, a):
|
||||||
|
#? int()
|
||||||
|
a
|
||||||
|
def test(self, a):
|
||||||
|
#? float()
|
||||||
|
a
|
||||||
|
|
||||||
|
A(3).test(2.0)
|
||||||
|
|||||||
Reference in New Issue
Block a user