do class scoping the right way (no direct access to class stuff in methods)

This commit is contained in:
David Halter
2012-05-28 02:10:42 +02:00
parent 5f0926d045
commit 1661196701
2 changed files with 11 additions and 5 deletions

View File

@@ -93,7 +93,7 @@ class Instance(Executable):
else: else:
return func return func
def get_subscope(self, name): def get_subscope_by_name(self, name):
for sub in reversed(self.base.subscopes): for sub in reversed(self.base.subscopes):
if sub.name.get_code() == name: if sub.name.get_code() == name:
return sub return sub
@@ -307,7 +307,7 @@ class Execution(Executable):
else: else:
try: try:
# if it is an instance, we try to execute the __call__(). # if it is an instance, we try to execute the __call__().
call_method = self.base.get_subscope('__call__') call_method = self.base.get_subscope_by_name('__call__')
except (AttributeError, KeyError): except (AttributeError, KeyError):
debug.warning("no execution possible", self.base) debug.warning("no execution possible", self.base)
else: else:
@@ -701,9 +701,10 @@ def get_names_for_scope(scope, position=None, star_search=True):
""" """
start_scope = scope start_scope = scope
while scope: while scope:
# class variables/functions are only available # `parsing.Class` is used, because the parent is never `Class`.
if (not isinstance(scope, Class) or scope == start_scope) \ # ignore the Flows, because the classes and functions care for that.
and not isinstance(scope, parsing.Flow): if not (scope != start_scope and isinstance(scope, (parsing.Class))
or isinstance(scope, parsing.Flow)):
try: try:
yield scope, get_defined_names_for_position(scope, position) yield scope, get_defined_names_for_position(scope, position)
except StopIteration: except StopIteration:

View File

@@ -26,6 +26,11 @@ class TestClass(object):
self.var_ self.var_
def ret(self, a1): def ret(self, a1):
# should not know any class functions!
#? []
values
#? []
ret
return a1 return a1
# should not work # should not work