Skip to content

TypeError: __aenter__() takes at most 0 arguments #1170

@p-sawicki

Description

@p-sawicki

Using async with on an instance of a compiled class fails with the error above after wrappers for async functions with the CO_COROUTINE flag were added in python/mypy@81eaa5d.

To reproduce:

Compile test.py mypyc test.py

import asyncio

class Manager:
    async def __aenter__(self) -> None:
        await asyncio.sleep(0)

    async def __aexit__(self, exc_type: object, exc: object, tb: object) -> None:
        await asyncio.sleep(0)

async def test():
    ctx = Manager()
    async with ctx:
        print("test")
    
asyncio.run(test())

Run python -c 'import test'

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions