mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-01-31 03:36:41 +03:00
Refactor DeclarativeCatalog metaclass
This commit is contained in:
parent
7483e98f2b
commit
8b175f0b71
|
@ -63,31 +63,27 @@ class DeclarativeCatalogMetaClass(type):
|
|||
|
||||
def __new__(mcs, class_name, bases, attributes):
|
||||
"""Declarative catalog class factory."""
|
||||
cls_providers = dict((name, provider)
|
||||
cls = type.__new__(mcs, class_name, bases, attributes)
|
||||
|
||||
cls.Bundle = mcs.bundle_cls_factory(cls)
|
||||
cls.overridden_by = tuple()
|
||||
|
||||
cls_providers = tuple((name, provider)
|
||||
for name, provider in six.iteritems(attributes)
|
||||
if is_provider(provider))
|
||||
|
||||
inherited_providers = dict((name, provider)
|
||||
inherited_providers = tuple((name, provider)
|
||||
for base in bases if is_catalog(base)
|
||||
for name, provider in six.iteritems(
|
||||
base.providers))
|
||||
|
||||
providers = dict()
|
||||
providers.update(cls_providers)
|
||||
providers.update(inherited_providers)
|
||||
|
||||
cls = type.__new__(mcs, class_name, bases, attributes)
|
||||
|
||||
cls.cls_providers = cls_providers
|
||||
cls.inherited_providers = inherited_providers
|
||||
cls.providers = providers
|
||||
|
||||
cls.overridden_by = tuple()
|
||||
|
||||
cls.Bundle = mcs.bundle_cls_factory(cls)
|
||||
providers = cls_providers + inherited_providers
|
||||
|
||||
cls.cls_providers = dict(cls_providers)
|
||||
cls.inherited_providers = dict(inherited_providers)
|
||||
cls.providers = dict(providers)
|
||||
cls.provider_names = dict()
|
||||
for name, provider in six.iteritems(providers):
|
||||
for name, provider in providers:
|
||||
if provider in cls.provider_names:
|
||||
raise Error('Provider {0} could not be bound to the same '
|
||||
'catalog (or catalogs hierarchy) more '
|
||||
|
|
Loading…
Reference in New Issue
Block a user