From 1631978790bea43b05311c9e3db6f8a5095b4f37 Mon Sep 17 00:00:00 2001 From: Roman Mogilatov Date: Sat, 24 Jan 2015 00:31:30 +0200 Subject: [PATCH] 0.2.1, ExternalDependency can take several types --- VERSION | 2 +- objects/providers.py | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/VERSION b/VERSION index 0ea3a944..0c62199f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.2.0 +0.2.1 diff --git a/objects/providers.py b/objects/providers.py index 0114090a..2c5ef271 100644 --- a/objects/providers.py +++ b/objects/providers.py @@ -2,6 +2,7 @@ Standard providers. """ +from collections import Iterable from .injections import InitArg, Attribute, Method @@ -119,6 +120,8 @@ class ExternalDependency(Provider): :param instance_of: type """ + if not isinstance(instance_of, Iterable): + instance_of = (instance_of,) self.instance_of = instance_of self.dependency = None super(ExternalDependency, self).__init__() @@ -140,9 +143,9 @@ class ExternalDependency(Provider): result = self.dependency.__call__(*args, **kwargs) - if not isinstance(result, self.instance_of): - raise TypeError('{} is not an instance of {}'.format(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, self.instance_of)) + return result