diff options
author | Jacob Walls <jacobtylerwalls@gmail.com> | 2022-07-02 18:25:06 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-02 18:25:06 -0400 |
commit | dd80a68fc93d507c3a8182ea5b94f6cbe0e348a7 (patch) | |
tree | 80f9936fd4e5fe99b8e67428fc861a25e3ea6eb3 /astroid/bases.py | |
parent | 3621e2e7d68653d66cbf770e6dcb61ba541117f1 (diff) | |
download | astroid-git-dd80a68fc93d507c3a8182ea5b94f6cbe0e348a7.tar.gz |
Prevent creating `Instance` that proxies another `Instance` when inferring `__new__(cls)` (#1682)
Diffstat (limited to 'astroid/bases.py')
-rw-r--r-- | astroid/bases.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/astroid/bases.py b/astroid/bases.py index a3f2017f..c1607260 100644 --- a/astroid/bases.py +++ b/astroid/bases.py @@ -293,6 +293,9 @@ class Instance(BaseInstance): # pylint: disable=unnecessary-lambda special_attributes = lazy_descriptor(lambda: objectmodel.InstanceModel()) + def __init__(self, proxied: nodes.ClassDef) -> None: + super().__init__(proxied) + def __repr__(self): return "<Instance of {}.{} at 0x{}>".format( self._proxied.root().name, self._proxied.name, id(self) @@ -434,9 +437,12 @@ class UnboundMethod(Proxy): return node_context = context.extra_context.get(caller.args[0]) - infer = caller.args[0].infer(context=node_context) - - yield from (Instance(x) if x is not Uninferable else x for x in infer) # type: ignore[misc,arg-type] + for inferred in caller.args[0].infer(context=node_context): + if inferred is Uninferable: + yield inferred + if isinstance(inferred, nodes.ClassDef): + yield Instance(inferred) + raise InferenceError def bool_value(self, context=None): return True |