mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 14:54:47 +08:00
self redirection solved
This commit is contained in:
38
evaluate.py
38
evaluate.py
@@ -126,6 +126,7 @@ class Instance(Executable):
|
|||||||
if n.names[0] == self_name and len(n.names) == 2:
|
if n.names[0] == self_name and len(n.names) == 2:
|
||||||
add_self_name(n)
|
add_self_name(n)
|
||||||
|
|
||||||
|
#print names, [n.parent for n in names], [n.parent.parent for n in names]
|
||||||
for var in self.base.get_defined_names(as_instance=True):
|
for var in self.base.get_defined_names(as_instance=True):
|
||||||
# functions are also instance elements
|
# functions are also instance elements
|
||||||
if isinstance(var.parent, (parsing.Function)):
|
if isinstance(var.parent, (parsing.Function)):
|
||||||
@@ -161,6 +162,10 @@ class InstanceElement(object):
|
|||||||
def parent(self):
|
def parent(self):
|
||||||
return InstanceElement(self.instance, self.var.parent)
|
return InstanceElement(self.instance, self.var.parent)
|
||||||
|
|
||||||
|
def get_parent_until(self, *classes):
|
||||||
|
scope = self.var.get_parent_until(*classes)
|
||||||
|
return InstanceElement(self.instance, scope)
|
||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
return getattr(self.var, name)
|
return getattr(self.var, name)
|
||||||
|
|
||||||
@@ -504,6 +509,8 @@ class Execution(Executable):
|
|||||||
return objects
|
return objects
|
||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
|
if name not in ['indent', 'line_nr', 'imports']:
|
||||||
|
raise AttributeError('Tried to access %s. Why?' % name)
|
||||||
return getattr(self.base, name)
|
return getattr(self.base, name)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -628,6 +635,18 @@ class Array(object):
|
|||||||
def get_contents(self):
|
def get_contents(self):
|
||||||
return self._array
|
return self._array
|
||||||
|
|
||||||
|
@property
|
||||||
|
def parent(self):
|
||||||
|
"""
|
||||||
|
Return the builtin scope as parent, because the arrays are builtins
|
||||||
|
"""
|
||||||
|
return builtin.Builtin.scope
|
||||||
|
|
||||||
|
def __getattr__(self, name):
|
||||||
|
if name not in ['type']:
|
||||||
|
raise AttributeError('Strange access: %s.' % name)
|
||||||
|
return getattr(self._array, name)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<e%s of %s>" % (self.__class__.__name__, self._array)
|
return "<e%s of %s>" % (self.__class__.__name__, self._array)
|
||||||
|
|
||||||
@@ -639,10 +658,9 @@ class ArrayElement(object):
|
|||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
# set access rights:
|
# set access rights:
|
||||||
if name in ['parent', 'names', 'line_nr', 'indent']:
|
if name not in ['parent', 'names', 'line_nr', 'indent']:
|
||||||
return getattr(self.name, name)
|
raise AttributeError('Strange access: %s.' % name)
|
||||||
else:
|
return getattr(self.name, name)
|
||||||
raise NotImplementedError("Strange access, shouldn't happen!")
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<%s of %s>" % (self.__class__.__name__, self.name)
|
return "<%s of %s>" % (self.__class__.__name__, self.name)
|
||||||
@@ -747,9 +765,13 @@ def get_scopes_for_name(scope, name_str, position=None, search_global=False):
|
|||||||
and par.position == 0:
|
and par.position == 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 some times the class is
|
# place, if the var_args are clear. But some times the class is
|
||||||
# not known. Therefore set self.
|
# not known. Therefore add a new instance for self. Otherwise
|
||||||
result.append(Instance(Class(par.parent.parent)))
|
# take the existing.
|
||||||
result.append(par)
|
if isinstance(scope, InstanceElement):
|
||||||
|
inst = scope.instance
|
||||||
|
else:
|
||||||
|
inst = Instance(Class(par.parent.parent))
|
||||||
|
result.append(inst)
|
||||||
else:
|
else:
|
||||||
result.append(par)
|
result.append(par)
|
||||||
return result
|
return result
|
||||||
@@ -858,7 +880,7 @@ def follow_statement(stmt, scope=None, seek_name=None):
|
|||||||
scope = stmt.get_parent_until(parsing.Function, Function, Execution,
|
scope = stmt.get_parent_until(parsing.Function, Function, Execution,
|
||||||
parsing.Class, Instance,
|
parsing.Class, Instance,
|
||||||
InstanceElement)
|
InstanceElement)
|
||||||
debug.dbg('follow_stmt', stmt, 'in', scope, seek_name)
|
debug.dbg('follow_stmt', stmt, stmt.parent, 'in', scope, seek_name)
|
||||||
|
|
||||||
call_list = stmt.get_assignment_calls()
|
call_list = stmt.get_assignment_calls()
|
||||||
debug.dbg('calls', call_list, call_list.values)
|
debug.dbg('calls', call_list, call_list.values)
|
||||||
|
|||||||
@@ -73,12 +73,14 @@ class Definition(object):
|
|||||||
self.scope = scope
|
self.scope = scope
|
||||||
|
|
||||||
def get_name(self):
|
def get_name(self):
|
||||||
return self.scope.name
|
try:
|
||||||
|
return self.scope.name
|
||||||
|
except AttributeError:
|
||||||
|
return self.scope.type
|
||||||
|
|
||||||
def get_module(self):
|
def get_module(self):
|
||||||
par = self.scope
|
par = self.scope
|
||||||
while True:
|
while True:
|
||||||
# TODO what to do with `evaluate.Array` ?
|
|
||||||
if par.parent is not None:
|
if par.parent is not None:
|
||||||
par = par.parent
|
par = par.parent
|
||||||
else:
|
else:
|
||||||
|
|||||||
36
parsetest.py
36
parsetest.py
@@ -158,23 +158,23 @@ a = 3; b = ""
|
|||||||
b,a=a,b
|
b,a=a,b
|
||||||
a.
|
a.
|
||||||
|
|
||||||
def decorator2(func):
|
|
||||||
def wrapper(*args):
|
|
||||||
return func(*args)
|
|
||||||
return wrapper
|
|
||||||
def decorator1(func):
|
|
||||||
def wrapper(*args):
|
|
||||||
return func(1, *args)
|
|
||||||
return wrapper
|
|
||||||
@decorator2
|
|
||||||
@decorator1
|
|
||||||
def decorated(a,b):
|
|
||||||
return a,b
|
|
||||||
exe = decorated(frozenset, '')
|
|
||||||
exe[1].
|
|
||||||
|
|
||||||
def rev(a=1, b=""):
|
|
||||||
return a, b
|
|
||||||
|
|
||||||
|
|
||||||
rev(b=list, a=set)[1].
|
class Ar():
|
||||||
|
def __init__(self, asd):
|
||||||
|
self.a = asd
|
||||||
|
|
||||||
|
def rename(self):
|
||||||
|
self.a2 = self.a
|
||||||
|
return self.a2
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Ar(1).rename()
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ class TestClass(object):
|
|||||||
self2.var_inst = first_param
|
self2.var_inst = first_param
|
||||||
self2.second = second_param
|
self2.second = second_param
|
||||||
self2.first = first_param
|
self2.first = first_param
|
||||||
|
a = 3
|
||||||
|
|
||||||
def var_func(self):
|
def var_func(self):
|
||||||
return 1
|
return 1
|
||||||
|
|||||||
@@ -136,10 +136,8 @@ def args_func(arg1, *args):
|
|||||||
exe = args_func(1, "", list)
|
exe = args_func(1, "", list)
|
||||||
#? int()
|
#? int()
|
||||||
exe[0]
|
exe[0]
|
||||||
|
|
||||||
#? tuple()
|
#? tuple()
|
||||||
exe[1].index
|
exe[1]
|
||||||
|
|
||||||
#? list()
|
#? list()
|
||||||
exe[1][1]
|
exe[1][1]
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ sys.path.append('.')
|
|||||||
import functions
|
import functions
|
||||||
from _compatibility import unicode, BytesIO
|
from _compatibility import unicode, BytesIO
|
||||||
|
|
||||||
|
only_line = int(sys.argv[2]) if len(sys.argv) > 2 else None
|
||||||
#functions.set_debug_function(functions.debug.print_to_stdout)
|
#functions.set_debug_function(functions.debug.print_to_stdout)
|
||||||
|
|
||||||
def run_completion_test(correct, source, line_nr, line):
|
def run_completion_test(correct, source, line_nr, line):
|
||||||
@@ -100,7 +101,7 @@ def completion_test(source):
|
|||||||
correct = None
|
correct = None
|
||||||
else:
|
else:
|
||||||
# reset the test, if only one specific test is wanted
|
# reset the test, if only one specific test is wanted
|
||||||
if len(sys.argv) > 2 and line_nr != int(sys.argv[2]):
|
if only_line is not None and line_nr != only_line:
|
||||||
correct = None
|
correct = None
|
||||||
import debug
|
import debug
|
||||||
debug.debug_function = \
|
debug.debug_function = \
|
||||||
|
|||||||
Reference in New Issue
Block a user