Skip to content

Error with @inject typing and mypy #36

@zulrang

Description

@zulrang

This code works with mypy:

class MyClass:
    pass


di[MyClass] = MyClass()


async def my_async_func(my_class: MyClass) -> str:
    return MyClass.__class__.__name__


async def calling_func() -> str:
    return await my_async_func(di[MyClass])

While this code results in an error:

class MyClass:
    pass


di[MyClass] = MyClass()


@inject
async def my_async_func(my_class: MyClass) -> str:
    return MyClass.__class__.__name__


async def calling_func() -> str:
    return await my_async_func()

mypy error: error: Incompatible types in "await" (actual type "Union[Any, Callable[..., Any]]", expected type "Awaitable[Any]")

Aside from ignoring the calling line, is there any way to make mypy happy with the type returned from the @Inject decorator?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions