__getattr__ arbitrary returns fix

This commit is contained in:
Dave Halter
2014-04-27 23:15:32 +02:00
parent 45d3bbff0d
commit d106b2ce2b
3 changed files with 13 additions and 12 deletions

View File

@@ -528,10 +528,6 @@ class Script(object):
for d in set(definitions): for d in set(definitions):
if isinstance(d, (pr.Module, compiled.CompiledObject)): if isinstance(d, (pr.Module, compiled.CompiledObject)):
names.append(classes.Definition(self._evaluator, d)) names.append(classes.Definition(self._evaluator, d))
elif isinstance(d, er.Instance):
# Instances can be ignored, because they have been created by
# ``__getattr__``.
pass
else: else:
names.append(classes.Definition(self._evaluator, d.names[-1])) names.append(classes.Definition(self._evaluator, d.names[-1]))

View File

@@ -95,14 +95,6 @@ class NameFinder(object):
if result: if result:
break break
if not result and isinstance(self.scope, er.Instance):
# handling __getattr__ / __getattribute__
for r in self._check_getattr(self.scope):
if not isinstance(r, compiled.CompiledObject):
new_name = copy.copy(r.name)
new_name.parent = r
result.append(new_name)
debug.dbg('finder.filter_name "%s" in (%s-%s): %s@%s', self.name_str, debug.dbg('finder.filter_name "%s" in (%s-%s): %s@%s', self.name_str,
self.scope, nscope, u(result), self.position) self.scope, nscope, u(result), self.position)
return result return result
@@ -197,6 +189,11 @@ class NameFinder(object):
if typ.isinstance(er.Function) and resolve_decorator: if typ.isinstance(er.Function) and resolve_decorator:
typ = typ.get_decorated_func() typ = typ.get_decorated_func()
types.append(typ) types.append(typ)
if not names and isinstance(self.scope, er.Instance):
# handling __getattr__ / __getattribute__
types = self._check_getattr(self.scope)
return types return types
def _remove_statements(self, stmt): def _remove_statements(self, stmt):

View File

@@ -356,6 +356,14 @@ Wrapper(Base()).ret(3)
#? int() #? int()
Wrapper2(Base()).ret(3) Wrapper2(Base()).ret(3)
class GetattrArray():
def __getattr__(self, name):
return [1]
#? int()
GetattrArray().something[0]
# ----------------- # -----------------
# private vars # private vars
# ----------------- # -----------------