mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 06:44:46 +08:00
__getattr__ arbitrary returns fix
This commit is contained in:
@@ -528,10 +528,6 @@ class Script(object):
|
||||
for d in set(definitions):
|
||||
if isinstance(d, (pr.Module, compiled.CompiledObject)):
|
||||
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:
|
||||
names.append(classes.Definition(self._evaluator, d.names[-1]))
|
||||
|
||||
|
||||
@@ -95,14 +95,6 @@ class NameFinder(object):
|
||||
if result:
|
||||
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,
|
||||
self.scope, nscope, u(result), self.position)
|
||||
return result
|
||||
@@ -197,6 +189,11 @@ class NameFinder(object):
|
||||
if typ.isinstance(er.Function) and resolve_decorator:
|
||||
typ = typ.get_decorated_func()
|
||||
types.append(typ)
|
||||
|
||||
if not names and isinstance(self.scope, er.Instance):
|
||||
# handling __getattr__ / __getattribute__
|
||||
types = self._check_getattr(self.scope)
|
||||
|
||||
return types
|
||||
|
||||
def _remove_statements(self, stmt):
|
||||
|
||||
@@ -356,6 +356,14 @@ Wrapper(Base()).ret(3)
|
||||
#? int()
|
||||
Wrapper2(Base()).ret(3)
|
||||
|
||||
class GetattrArray():
|
||||
def __getattr__(self, name):
|
||||
return [1]
|
||||
|
||||
#? int()
|
||||
GetattrArray().something[0]
|
||||
|
||||
|
||||
# -----------------
|
||||
# private vars
|
||||
# -----------------
|
||||
|
||||
Reference in New Issue
Block a user