Skip to content

Commit 56c7d24

Browse files
committed
Fix ClassDef insert
1 parent 0686160 commit 56c7d24

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

astroid/brain/brain_typing.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,13 @@ def infer_typing_alias(
180180

181181
if res != astroid.Uninferable and isinstance(res, nodes.ClassDef):
182182
class_def = nodes.ClassDef(
183-
name=res.name,
184-
lineno=res.lineno,
185-
col_offset=res.col_offset,
183+
name=f"{res.name}_typing",
184+
lineno=0,
185+
col_offset=0,
186186
parent=res.parent,
187187
)
188188
class_def.postinit(
189-
bases=res.bases,
189+
bases=[res],
190190
body=res.body,
191191
decorators=res.decorators,
192192
metaclass=create_typing_metaclass(),
@@ -196,8 +196,8 @@ def infer_typing_alias(
196196
if len(node.args) == 2 and isinstance(node.args[0], nodes.Attribute):
197197
class_def = nodes.ClassDef(
198198
name=node.args[0].attrname,
199-
lineno=node.lineno,
200-
col_offset=node.col_offset,
199+
lineno=0,
200+
col_offset=0,
201201
parent=node.parent,
202202
)
203203
class_def.postinit(

tests/unittest_brain.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,18 +1220,15 @@ def test_typing_alias_type(self):
12201220

12211221
def check_metaclass(node: nodes.ClassDef):
12221222
meta = node.metaclass()
1223-
assert (
1224-
isinstance(meta, nodes.ClassDef)
1225-
and meta.name == "ABCMeta_typing"
1226-
and "ABCMeta" == meta.basenames[0]
1227-
and meta.locals.get("__getitem__") is not None
1228-
)
1223+
assert isinstance(meta, nodes.ClassDef)
1224+
assert meta.name == "ABCMeta_typing"
1225+
assert "ABCMeta" == meta.basenames[0]
1226+
assert meta.locals.get("__getitem__") is not None
1227+
12291228
abc_meta = next(meta.bases[0].infer())
1230-
assert (
1231-
isinstance(abc_meta, nodes.ClassDef)
1232-
and abc_meta.name == "ABCMeta"
1233-
and abc_meta.locals.get("__getitem__") is None
1234-
)
1229+
assert isinstance(abc_meta, nodes.ClassDef)
1230+
assert abc_meta.name == "ABCMeta"
1231+
assert abc_meta.locals.get("__getitem__") is None
12351232

12361233
node = builder.extract_node(
12371234
"""
@@ -1250,6 +1247,7 @@ class Derived1(MutableSet[T]):
12501247
inferred,
12511248
[
12521249
"Derived1",
1250+
"MutableSet_typing",
12531251
"MutableSet",
12541252
"Set",
12551253
"Collection",
@@ -1273,6 +1271,7 @@ class Derived2(typing.OrderedDict[int, str]):
12731271
inferred,
12741272
[
12751273
"Derived2",
1274+
"OrderedDict_typing",
12761275
"OrderedDict",
12771276
"dict",
12781277
"object",

0 commit comments

Comments
 (0)