Skip to content

Mypy error when getting abstract classes #143

Open
@davidparsson

Description

@davidparsson

Using Injector to bind a concrete class to an abstract interface, and then getting an instance of that interface causes a mypy error:

class MyABC(ABC): pass
class MyClass(MyABC): pass

injector = Injector()
injector.binder.bind(MyABC, to=MyClass)  # error: Only concrete class can be given where "Type[MyABC]" is expected
injector.get(MyABC)  # error: Only concrete class can be given where "Type[MyABC]" is expected

I hope that this can be resolved by fixing type hints (although it's certainly possible to configure Injector so that the type hints will be incorrect).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions