Change CatalogBundle initialization procedure

This commit is contained in:
Roman Mogilatov 2015-11-11 15:19:24 +02:00
parent 548847f83a
commit 677e7143a2

View File

@ -22,9 +22,10 @@ class CatalogBundle(object):
def __init__(self, *providers): def __init__(self, *providers):
"""Initializer.""" """Initializer."""
self.providers = dict((self.catalog.get_provider_bind_name(provider), self.providers = dict()
provider) for provider in providers:
for provider in providers) provider_name = self.catalog.get_provider_bind_name(provider)
self.providers[provider_name] = provider
self.__dict__.update(self.providers) self.__dict__.update(self.providers)
super(CatalogBundle, self).__init__() super(CatalogBundle, self).__init__()
@ -68,8 +69,8 @@ class DynamicCatalog(object):
"""Catalog of providers.""" """Catalog of providers."""
__IS_CATALOG__ = True __IS_CATALOG__ = True
__slots__ = ('Bundle', 'providers', 'provider_names', __slots__ = ('Bundle', 'name', 'providers', 'provider_names',
'overridden_by', 'name') 'overridden_by')
def __init__(self, **providers): def __init__(self, **providers):
"""Initializer. """Initializer.
@ -80,6 +81,8 @@ class DynamicCatalog(object):
:type kwargs: dict[str, dependency_injector.providers.Provider] :type kwargs: dict[str, dependency_injector.providers.Provider]
""" """
self.Bundle = CatalogBundle.sub_cls_factory(self) self.Bundle = CatalogBundle.sub_cls_factory(self)
self.name = '.'.join((self.__class__.__module__,
self.__class__.__name__))
self.providers = dict() self.providers = dict()
self.provider_names = dict() self.provider_names = dict()
for name, provider in six.iteritems(providers): for name, provider in six.iteritems(providers):
@ -91,8 +94,6 @@ class DynamicCatalog(object):
self.provider_names[provider] = name self.provider_names[provider] = name
self.providers[name] = provider self.providers[name] = provider
self.overridden_by = tuple() self.overridden_by = tuple()
self.name = '.'.join((self.__class__.__module__,
self.__class__.__name__))
def is_bundle_owner(self, bundle): def is_bundle_owner(self, bundle):
"""Check if catalog is bundle owner.""" """Check if catalog is bundle owner."""