Skip to content

Call Instance.__init__ in nodes.Const #1689

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions astroid/bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,15 @@ class Proxy:
def __init__(
self, proxied: nodes.ClassDef | nodes.Lambda | Proxy | None = None
) -> None:
if proxied is not None:
if proxied is None:
# This is a hack to allow calling this __init__ during bootstrapping of
# builtin classes and their docstrings.
# For Const and Generator nodes the _proxied attribute is set during bootstrapping
# as we first need to build the ClassDef that they can proxy.
# Thus, if proxied is None self should be a Const or Generator
# as that is the only way _proxied will be correctly set as a ClassDef.
assert isinstance(self, (nodes.Const, Generator))
else:
self._proxied = proxied

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

def __init__(self, proxied: nodes.ClassDef) -> None:
def __init__(self, proxied: nodes.ClassDef | None) -> None:
super().__init__(proxied)

def __repr__(self):
Expand Down Expand Up @@ -587,6 +595,8 @@ class Generator(BaseInstance):
Proxied class is set once for all in raw_building.
"""

_proxied: nodes.ClassDef

special_attributes = lazy_descriptor(objectmodel.GeneratorModel)

def __init__(self, parent=None, generator_initial_context=None):
Expand Down
2 changes: 2 additions & 0 deletions astroid/nodes/node_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1914,6 +1914,8 @@ def __init__(
parent=parent,
)

Instance.__init__(self, None)

infer_unary_op: ClassVar[InferUnaryOp[Const]]

def __getattr__(self, name):
Expand Down