0.2.1, ExternalDependency can take several types

This commit is contained in:
Roman Mogilatov 2015-01-24 00:31:30 +02:00
parent 92254b0276
commit 1631978790
2 changed files with 7 additions and 4 deletions

View File

@ -1 +1 @@
0.2.0 0.2.1

View File

@ -2,6 +2,7 @@
Standard providers. Standard providers.
""" """
from collections import Iterable
from .injections import InitArg, Attribute, Method from .injections import InitArg, Attribute, Method
@ -119,6 +120,8 @@ class ExternalDependency(Provider):
:param instance_of: type :param instance_of: type
""" """
if not isinstance(instance_of, Iterable):
instance_of = (instance_of,)
self.instance_of = instance_of self.instance_of = instance_of
self.dependency = None self.dependency = None
super(ExternalDependency, self).__init__() super(ExternalDependency, self).__init__()
@ -140,9 +143,9 @@ class ExternalDependency(Provider):
result = self.dependency.__call__(*args, **kwargs) result = self.dependency.__call__(*args, **kwargs)
if not isinstance(result, self.instance_of): if not any((isinstance(result, possible_type) for possible_type in self.instance_of)):
raise TypeError('{} is not an instance of {}'.format(result, raise TypeError('{} is not an instance of {}'.format(result, self.instance_of))
self.instance_of))
return result return result