Skip to content

TypeError with async methods and inheritance #1141

@JukkaL

Description

@JukkaL

This was reported by @Chainfire at python/mypy#19376 (comment).

This raises TypeError (see the above link for the traceback):

from typing import Type

import asyncio
import traceback


class Parent:
    async def test(self) -> int:
        raise NotImplementedError()

    async def run(self) -> int:
        return await self.test()


class ChildTypeError1(Parent):
    async def test(self) -> int:
        return 1


class ChildTypeError2(Parent):
    async def run(self) -> int:
        return await self.test()


def test(cls: Type[Parent]) -> None:
    print(str(cls.__name__))
    try:
        print("- ", asyncio.run(cls().run()))
    except NotImplementedError:
        pass
    except Exception:
        traceback.print_exc()
        exit(1)


test(ChildTypeError1)
test(ChildTypeError2)
exit(0)

This is a regression introduced in python/mypy#19376 by me.

Metadata

Metadata

Assignees

Labels

crashFailing compile-time asserts, unhandled exceptions, or generated C code that's blowing up.priority-0-high

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions