Skip to content

Commit

Permalink
Extract providers type checker into function
Browse files Browse the repository at this point in the history
  • Loading branch information
rmk135 committed Jun 1, 2016
1 parent 1c15965 commit be94a1b
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions dependency_injector/containers.py
Expand Up @@ -31,7 +31,7 @@ def __new__(mcs, class_name, bases, attributes):
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

Expand All @@ -42,7 +42,7 @@ def __setattr__(cls, name, value):
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)
Expand All @@ -58,11 +58,6 @@ def __delattr__(cls, name):
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):
Expand Down Expand Up @@ -174,3 +169,9 @@ def _decorator(copied_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))

0 comments on commit be94a1b

Please sign in to comment.