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):
|
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]))
|
||||||
|
|
||||||
|
|||||||
@@ -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):
|
||||||
|
|||||||
@@ -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
|
||||||
# -----------------
|
# -----------------
|
||||||
|
|||||||
Reference in New Issue
Block a user