Skip to content

Creating a provider of ABC #266

@awaizman1

Description

@awaizman1

Hi,

I'm trying to create a Dependency provider for some python interface I have in the form of abstract-base-class (ABC).
Trying creating the provider raises an error.
What is the correct way for achieving this?

# file testc.py

from abc import ABC

from dependency_injector import providers

class Base(ABC):
    pass

class Impl(Base):
    pass

p = providers.Dependency(Base)  # this line raises
p.provided_by(providers.Object(Impl()))

I get the following error:

Traceback (most recent call last):
  File "testc.py", line 13, in <module>
    p = providers.Dependency(Base)
TypeError: Argument 'instance_of' has incorrect type (expected type, got ABCMeta)

Thanks

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions