1
0
forked from VimPlug/jedi

using super() in actual executed classes wasn't possible. fixes #421

This commit is contained in:
Dave Halter
2014-07-30 11:27:27 +02:00
parent 53671bca84
commit 3c92d175da
3 changed files with 16 additions and 5 deletions

View File

@@ -176,7 +176,7 @@ class Instance(use_metaclass(CachedMetaClass, Executable)):
def __getattr__(self, name): def __getattr__(self, name):
if name not in ['start_pos', 'end_pos', 'name', 'get_imports', if name not in ['start_pos', 'end_pos', 'name', 'get_imports',
'doc', 'raw_doc', 'asserts']: 'doc', 'raw_doc', 'asserts', 'py_bases']:
raise AttributeError("Instance %s: Don't touch this (%s)!" raise AttributeError("Instance %s: Don't touch this (%s)!"
% (self, name)) % (self, name))
return getattr(self.base, name) return getattr(self.base, name)

View File

@@ -91,13 +91,15 @@ class SuperInstance(er.Instance):
def builtins_super(evaluator, obj, params): def builtins_super(evaluator, obj, params):
# TODO make this able to detect multiple inheritance super # TODO make this able to detect multiple inheritance super
accept = (pr.Function,) accept = (pr.Function, er.FunctionExecution)
func = params.get_parent_until(accept) func = params.get_parent_until(accept)
if func.isinstance(*accept): if func.isinstance(*accept):
cls = func.get_parent_until(accept + (pr.Class,), wanted = (pr.Class, er.Instance)
cls = func.get_parent_until(accept + wanted,
include_current=False) include_current=False)
if isinstance(cls, pr.Class): if isinstance(cls, wanted):
cls = er.Class(evaluator, cls) if isinstance(cls, pr.Class):
cls = er.Class(evaluator, cls)
su = cls.py_bases() su = cls.py_bases()
if su: if su:
return evaluator.execute(su[0]) return evaluator.execute(su[0])

View File

@@ -398,6 +398,8 @@ PrivateVar().__var
# ----------------- # -----------------
class Super(object): class Super(object):
a = 3 a = 3
def return_sup(self):
return 1
class TestSuper(Super): class TestSuper(Super):
#? #?
@@ -414,6 +416,13 @@ class TestSuper(Super):
#? #?
super() super()
def return_sup(self):
#? int()
return super().return_sup()
#? int()
TestSuper().return_sup()
# ----------------- # -----------------
# if flow at class level # if flow at class level