mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-02-07 15:10:47 +03:00
Add provider type checks for declarative container
This commit is contained in:
parent
ed7f354afe
commit
d8f03c4487
|
@ -26,7 +26,18 @@ class DeclarativeContainerMetaClass(type):
|
||||||
attributes['inherited_providers'] = dict(inherited_providers)
|
attributes['inherited_providers'] = dict(inherited_providers)
|
||||||
attributes['providers'] = dict(cls_providers + inherited_providers)
|
attributes['providers'] = dict(cls_providers + inherited_providers)
|
||||||
|
|
||||||
return type.__new__(mcs, class_name, bases, attributes)
|
cls = type.__new__(mcs, class_name, bases, attributes)
|
||||||
|
|
||||||
|
if cls.provider_type:
|
||||||
|
for provider in six.itervalues(cls.providers):
|
||||||
|
try:
|
||||||
|
assert isinstance(provider, cls.provider_type)
|
||||||
|
except AssertionError:
|
||||||
|
raise errors.Error('{0} can contain only {1} '
|
||||||
|
'instances'.format(cls,
|
||||||
|
cls.provider_type))
|
||||||
|
|
||||||
|
return cls
|
||||||
|
|
||||||
def __setattr__(cls, name, value):
|
def __setattr__(cls, name, value):
|
||||||
"""Set class attribute.
|
"""Set class attribute.
|
||||||
|
@ -57,6 +68,8 @@ class DeclarativeContainer(object):
|
||||||
|
|
||||||
__IS_CATALOG__ = True
|
__IS_CATALOG__ = True
|
||||||
|
|
||||||
|
provider_type = None
|
||||||
|
|
||||||
providers = dict()
|
providers = dict()
|
||||||
cls_providers = dict()
|
cls_providers = dict()
|
||||||
inherited_providers = dict()
|
inherited_providers = dict()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user