From a4ad5cd9fe79f0b2d072e0f8355cfab1afc71be9 Mon Sep 17 00:00:00 2001 From: Gen Date: Fri, 26 Feb 2021 01:42:38 -0800 Subject: [PATCH 1/2] Fix mro invoking --- mypy/stubgenc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mypy/stubgenc.py b/mypy/stubgenc.py index a0a783bed32f..c75f7d4f0cc6 100755 --- a/mypy/stubgenc.py +++ b/mypy/stubgenc.py @@ -352,7 +352,7 @@ def generate_c_type_stub(module: ModuleType, if attr not in done: static_properties.append('%s: ClassVar[%s] = ...' % ( attr, strip_or_import(get_type_fullname(type(value)), module, imports))) - all_bases = obj.mro() + all_bases = type.mro(obj) if all_bases[-1] is object: # TODO: Is this always object? del all_bases[-1] From 7b990b618c0628783735f7a68e8ac927f8926e9d Mon Sep 17 00:00:00 2001 From: Gen Date: Fri, 26 Feb 2021 14:19:16 -0800 Subject: [PATCH 2/2] Add unit test for inheritance builtin type. --- mypy/test/teststubgen.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mypy/test/teststubgen.py b/mypy/test/teststubgen.py index 981035b0892b..62feb0784a42 100644 --- a/mypy/test/teststubgen.py +++ b/mypy/test/teststubgen.py @@ -710,6 +710,16 @@ class TestClass(argparse.Action): assert_equal(output, ['class C(argparse.Action): ...', ]) assert_equal(imports, ['import argparse']) + def test_generate_c_type_inheritance_builtin_type(self) -> None: + class TestClass(type): + pass + output = [] # type: List[str] + imports = [] # type: List[str] + mod = ModuleType('module', '') + generate_c_type_stub(mod, 'C', TestClass, output, imports) + assert_equal(output, ['class C(type): ...', ]) + assert_equal(imports, []) + def test_generate_c_type_with_docstring(self) -> None: class TestClass: def test(self, arg0: str) -> None: