Skip to content

Commit 29dcc35

Browse files
DanielNoordcdce8p
andauthored
Fix typing and postinit in build_class (#1452)
Co-authored-by: Marc Mueller <[email protected]>
1 parent 2a064ba commit 29dcc35

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

astroid/raw_building.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import sys
3333
import types
3434
import warnings
35-
from typing import List, Optional
35+
from typing import Iterable, List, Optional
3636

3737
from astroid import bases, nodes
3838
from astroid.manager import AstroidManager
@@ -116,20 +116,17 @@ def build_module(name: str, doc: Optional[str] = None) -> nodes.Module:
116116
return node
117117

118118

119-
def build_class(name, basenames=(), doc=None):
120-
"""create and initialize an astroid ClassDef node"""
119+
def build_class(
120+
name: str, basenames: Iterable[str] = (), doc: Optional[str] = None
121+
) -> nodes.ClassDef:
122+
"""Create and initialize an astroid ClassDef node."""
121123
node = nodes.ClassDef(name)
122124
node.postinit(
123-
bases=[],
125+
bases=[nodes.Name(name=base, parent=node) for base in basenames],
124126
body=[],
125127
decorators=None,
126128
doc_node=nodes.Const(value=doc) if doc else None,
127129
)
128-
# TODO: Use the actual postinit method instead of appending manually
129-
for base in basenames:
130-
basenode = nodes.Name(name=base)
131-
node.bases.append(basenode)
132-
basenode.parent = node
133130
return node
134131

135132

0 commit comments

Comments
 (0)