Skip to content

Commit 2391061

Browse files
committed
Fix ClassDef insert
1 parent 4e3cf53 commit 2391061

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
@@ -178,13 +178,13 @@ def infer_typing_alias(
178178

179179
if res != astroid.Uninferable and isinstance(res, nodes.ClassDef):
180180
class_def = nodes.ClassDef(
181-
name=res.name,
182-
lineno=res.lineno,
183-
col_offset=res.col_offset,
181+
name=f"{res.name}_typing",
182+
lineno=0,
183+
col_offset=0,
184184
parent=res.parent,
185185
)
186186
class_def.postinit(
187-
bases=res.bases,
187+
bases=[res],
188188
body=res.body,
189189
decorators=res.decorators,
190190
metaclass=create_typing_metaclass(),
@@ -194,8 +194,8 @@ def infer_typing_alias(
194194
if len(node.args) == 2 and isinstance(node.args[0], nodes.Attribute):
195195
class_def = nodes.ClassDef(
196196
name=node.args[0].attrname,
197-
lineno=node.lineno,
198-
col_offset=node.col_offset,
197+
lineno=0,
198+
col_offset=0,
199199
parent=node.parent,
200200
)
201201
class_def.postinit(

tests/unittest_brain.py

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

12191219
def check_metaclass(node: nodes.ClassDef):
12201220
meta = node.metaclass()
1221-
assert (
1222-
isinstance(meta, nodes.ClassDef)
1223-
and meta.name == "ABCMeta_typing"
1224-
and "ABCMeta" == meta.basenames[0]
1225-
and meta.locals.get("__getitem__") is not None
1226-
)
1221+
assert isinstance(meta, nodes.ClassDef)
1222+
assert meta.name == "ABCMeta_typing"
1223+
assert "ABCMeta" == meta.basenames[0]
1224+
assert meta.locals.get("__getitem__") is not None
1225+
12271226
abc_meta = next(meta.bases[0].infer())
1228-
assert (
1229-
isinstance(abc_meta, nodes.ClassDef)
1230-
and abc_meta.name == "ABCMeta"
1231-
and abc_meta.locals.get("__getitem__") is None
1232-
)
1227+
assert isinstance(abc_meta, nodes.ClassDef)
1228+
assert abc_meta.name == "ABCMeta"
1229+
assert abc_meta.locals.get("__getitem__") is None
12331230

12341231
node = builder.extract_node(
12351232
"""
@@ -1248,6 +1245,7 @@ class Derived1(MutableSet[T]):
12481245
inferred,
12491246
[
12501247
"Derived1",
1248+
"MutableSet_typing",
12511249
"MutableSet",
12521250
"Set",
12531251
"Collection",
@@ -1271,6 +1269,7 @@ class Derived2(typing.OrderedDict[int, str]):
12711269
inferred,
12721270
[
12731271
"Derived2",
1272+
"OrderedDict_typing",
12741273
"OrderedDict",
12751274
"dict",
12761275
"object",

0 commit comments

Comments
 (0)