Skip to content

Commit 72ac2ce

Browse files
authored
stubgen: fix invoking mro() (#10138)
Fixes #10137
1 parent 3c4f019 commit 72ac2ce

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

mypy/stubgenc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ def generate_c_type_stub(module: ModuleType,
352352
if attr not in done:
353353
static_properties.append('%s: ClassVar[%s] = ...' % (
354354
attr, strip_or_import(get_type_fullname(type(value)), module, imports)))
355-
all_bases = obj.mro()
355+
all_bases = type.mro(obj)
356356
if all_bases[-1] is object:
357357
# TODO: Is this always object?
358358
del all_bases[-1]

mypy/test/teststubgen.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,16 @@ class TestClass(argparse.Action):
710710
assert_equal(output, ['class C(argparse.Action): ...', ])
711711
assert_equal(imports, ['import argparse'])
712712

713+
def test_generate_c_type_inheritance_builtin_type(self) -> None:
714+
class TestClass(type):
715+
pass
716+
output = [] # type: List[str]
717+
imports = [] # type: List[str]
718+
mod = ModuleType('module', '')
719+
generate_c_type_stub(mod, 'C', TestClass, output, imports)
720+
assert_equal(output, ['class C(type): ...', ])
721+
assert_equal(imports, [])
722+
713723
def test_generate_c_type_with_docstring(self) -> None:
714724
class TestClass:
715725
def test(self, arg0: str) -> None:

0 commit comments

Comments
 (0)