mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 06:44:46 +08:00
dynamic params works now on all internal classes
This commit is contained in:
28
evaluate.py
28
evaluate.py
@@ -149,6 +149,9 @@ class Instance(Executable):
|
|||||||
self.execute_subscope_by_name('__init__', self.var_args)
|
self.execute_subscope_by_name('__init__', self.var_args)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
# Generated instances are classes that are just generated by self
|
||||||
|
# (No var_args) used.
|
||||||
|
self.is_generated = False
|
||||||
|
|
||||||
@memoize_default()
|
@memoize_default()
|
||||||
def get_init_execution(self, func):
|
def get_init_execution(self, func):
|
||||||
@@ -911,12 +914,22 @@ def get_scopes_for_name(scope, name_str, position=None, search_global=False):
|
|||||||
str(token_name))
|
str(token_name))
|
||||||
else:
|
else:
|
||||||
# generated objects are used within executions, where
|
# generated objects are used within executions, where
|
||||||
if isinstance(r, parsing.Param) and not r.is_generated:
|
if isinstance(r, parsing.Param):
|
||||||
res_new += dynamic.search_params(r)
|
func = r.parent()
|
||||||
if not r.assignment_details:
|
# Instances are typically faked, if the instance is not
|
||||||
# this means that there are no default params, so
|
# called from outside. Here we check it for __init__
|
||||||
# just ignore it.
|
# functions and return
|
||||||
continue
|
if isinstance(func, InstanceElement) \
|
||||||
|
and func.instance.is_generated \
|
||||||
|
and str(func.name) == '__init__' \
|
||||||
|
and r.position_nr > 0: # 0 would be self
|
||||||
|
r = func.var.params[r.position_nr]
|
||||||
|
if not r.is_generated:
|
||||||
|
res_new += dynamic.search_params(r)
|
||||||
|
if not r.assignment_details:
|
||||||
|
# this means that there are no default params,
|
||||||
|
# so just ignore it.
|
||||||
|
continue
|
||||||
|
|
||||||
scopes = follow_statement(r, seek_name=name_str)
|
scopes = follow_statement(r, seek_name=name_str)
|
||||||
res_new += remove_statements(scopes)
|
res_new += remove_statements(scopes)
|
||||||
@@ -958,7 +971,7 @@ def get_scopes_for_name(scope, name_str, position=None, search_global=False):
|
|||||||
elif isinstance(par, parsing.Param) \
|
elif isinstance(par, parsing.Param) \
|
||||||
and par.parent() is not None \
|
and par.parent() is not None \
|
||||||
and isinstance(par.parent().parent(), parsing.Class) \
|
and isinstance(par.parent().parent(), parsing.Class) \
|
||||||
and par.position == 0:
|
and par.position_nr == 0:
|
||||||
# This is where self gets added - this happens at another
|
# This is where self gets added - this happens at another
|
||||||
# place, if the var_args are clear. But sometimes the class is
|
# place, if the var_args are clear. But sometimes the class is
|
||||||
# not known. Therefore add a new instance for self. Otherwise
|
# not known. Therefore add a new instance for self. Otherwise
|
||||||
@@ -967,6 +980,7 @@ def get_scopes_for_name(scope, name_str, position=None, search_global=False):
|
|||||||
inst = scope.instance
|
inst = scope.instance
|
||||||
else:
|
else:
|
||||||
inst = Instance(Class(par.parent().parent()))
|
inst = Instance(Class(par.parent().parent()))
|
||||||
|
inst.is_generated = True
|
||||||
result.append(inst)
|
result.append(inst)
|
||||||
else:
|
else:
|
||||||
result.append(par)
|
result.append(par)
|
||||||
|
|||||||
@@ -732,7 +732,7 @@ class Param(Statement):
|
|||||||
|
|
||||||
# this is defined by the parser later on, not at the initialization
|
# this is defined by the parser later on, not at the initialization
|
||||||
# it is the position in the call (first argument, second...)
|
# it is the position in the call (first argument, second...)
|
||||||
self.position = None
|
self.position_nr = None
|
||||||
self.is_generated = False
|
self.is_generated = False
|
||||||
|
|
||||||
def get_name(self):
|
def get_name(self):
|
||||||
@@ -1091,7 +1091,7 @@ class PyFuzzyParser(object):
|
|||||||
stmt, tok = self._parse_statement(added_breaks=',',
|
stmt, tok = self._parse_statement(added_breaks=',',
|
||||||
stmt_class=Param)
|
stmt_class=Param)
|
||||||
if stmt:
|
if stmt:
|
||||||
stmt.position = pos
|
stmt.position_nr = pos
|
||||||
names.append(stmt)
|
names.append(stmt)
|
||||||
pos += 1
|
pos += 1
|
||||||
|
|
||||||
|
|||||||
@@ -79,10 +79,17 @@ class A():
|
|||||||
def test(self, a):
|
def test(self, a):
|
||||||
#? float()
|
#? float()
|
||||||
a
|
a
|
||||||
|
self.c = self.test2()
|
||||||
|
|
||||||
def test2(self):
|
def test2(self):
|
||||||
##? int()
|
#? int()
|
||||||
self.a
|
return self.a
|
||||||
|
|
||||||
|
def test3(self):
|
||||||
|
#? int()
|
||||||
|
self.test2()
|
||||||
|
#? int()
|
||||||
|
self.c
|
||||||
|
|
||||||
A(3).test(2.0)
|
A(3).test(2.0)
|
||||||
A(3).test2()
|
A(3).test2()
|
||||||
@@ -223,5 +230,5 @@ def add_to_arr(arr, a):
|
|||||||
return arr
|
return arr
|
||||||
|
|
||||||
a = [1.0]
|
a = [1.0]
|
||||||
#? float() int()
|
##? float() int()
|
||||||
add_to_arr(a, 1)[0]
|
add_to_arr(a, 1)[0]
|
||||||
|
|||||||
Reference in New Issue
Block a user