Skip to content

Commit 01ca8b6

Browse files
committed
Call Instance.__init__ in nodes.Const
1 parent 9224558 commit 01ca8b6

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Diff for: astroid/bases.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,15 @@ class Proxy:
109109
def __init__(
110110
self, proxied: nodes.ClassDef | nodes.Lambda | Proxy | None = None
111111
) -> None:
112-
if proxied is not None:
112+
if proxied is None:
113+
# This is a hack to allow calling this __init__ during bootstrapping of
114+
# builtin classes and their docstrings.
115+
# For Const and Generator nodes the _proxied attribute is set during bootstrapping
116+
# as we first need to build the ClassDef that they can proxy.
117+
# Thus, if proxied is None self should be a Const or Generator
118+
# as that is the only way _proxied will be correctly set as a ClassDef.
119+
assert isinstance(self, (nodes.Const, Generator))
120+
else:
113121
self._proxied = proxied
114122

115123
def __getattr__(self, name):
@@ -300,7 +308,7 @@ class Instance(BaseInstance):
300308
# pylint: disable=unnecessary-lambda
301309
special_attributes = lazy_descriptor(lambda: objectmodel.InstanceModel())
302310

303-
def __init__(self, proxied: nodes.ClassDef) -> None:
311+
def __init__(self, proxied: nodes.ClassDef | None) -> None:
304312
super().__init__(proxied)
305313

306314
def __repr__(self):
@@ -587,6 +595,8 @@ class Generator(BaseInstance):
587595
Proxied class is set once for all in raw_building.
588596
"""
589597

598+
_proxied: nodes.ClassDef
599+
590600
special_attributes = lazy_descriptor(objectmodel.GeneratorModel)
591601

592602
def __init__(self, parent=None, generator_initial_context=None):

Diff for: astroid/nodes/node_classes.py

+2
Original file line numberDiff line numberDiff line change
@@ -1914,6 +1914,8 @@ def __init__(
19141914
parent=parent,
19151915
)
19161916

1917+
Instance.__init__(self, None)
1918+
19171919
infer_unary_op: ClassVar[InferUnaryOp[Const]]
19181920

19191921
def __getattr__(self, name):

0 commit comments

Comments
 (0)