From be94a1badc42e11b89112bfbd9fab2039b70452c Mon Sep 17 00:00:00 2001 From: Roman Mogilatov Date: Wed, 1 Jun 2016 16:00:11 +0300 Subject: [PATCH] Extract providers type checker into function --- dependency_injector/containers.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/dependency_injector/containers.py b/dependency_injector/containers.py index 2cf435fc..8e36f3ba 100644 --- a/dependency_injector/containers.py +++ b/dependency_injector/containers.py @@ -31,7 +31,7 @@ class DeclarativeContainerMetaClass(type): cls = type.__new__(mcs, class_name, bases, attributes) for provider in six.itervalues(cls.providers): - cls._check_provider_type(provider) + _check_provider_type(cls, provider) return cls @@ -42,7 +42,7 @@ class DeclarativeContainerMetaClass(type): dictionary. """ if utils.is_provider(value): - cls._check_provider_type(value) + _check_provider_type(cls, value) cls.providers[name] = value cls.cls_providers[name] = value super(DeclarativeContainerMetaClass, cls).__setattr__(name, value) @@ -58,11 +58,6 @@ class DeclarativeContainerMetaClass(type): del cls.cls_providers[name] super(DeclarativeContainerMetaClass, cls).__delattr__(name) - def _check_provider_type(cls, provider): - if not isinstance(provider, cls.provider_type): - raise errors.Error('{0} can contain only {1} ' - 'instances'.format(cls, cls.provider_type)) - @six.add_metaclass(DeclarativeContainerMetaClass) class DeclarativeContainer(object): @@ -174,3 +169,9 @@ def copy(container): return copied_container return _decorator + + +def _check_provider_type(cls, provider): + if not isinstance(provider, cls.provider_type): + raise errors.Error('{0} can contain only {1} ' + 'instances'.format(cls, cls.provider_type))