From acc9259ddd30b6433dc93ea1604325ca38448132 Mon Sep 17 00:00:00 2001 From: Roman Mogilatov Date: Sat, 11 Jul 2015 23:34:23 +0300 Subject: [PATCH] Removing delegate option from injections --- examples/singleton_and_factory.py | 5 ++--- objects/injections.py | 7 +++---- tox.ini | 4 ++-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/examples/singleton_and_factory.py b/examples/singleton_and_factory.py index 8a1b6853..6a8b4f70 100644 --- a/examples/singleton_and_factory.py +++ b/examples/singleton_and_factory.py @@ -52,10 +52,9 @@ class UserService(object): # Users factory and UserService provider: +users_factory = Factory(User) users_service = Singleton(UserService, - KwArg('users_factory', - Delegate(Factory(User)))) - + KwArg('users_factory', Delegate(users_factory))) # Creating several User objects: user1 = users_service().get_by_id(1) diff --git a/objects/injections.py b/objects/injections.py index 15d20a5c..c574071b 100644 --- a/objects/injections.py +++ b/objects/injections.py @@ -8,18 +8,17 @@ class Injection(object): """Base injection class.""" __IS_OBJECTS_INJECTION__ = True - __slots__ = ('name', 'injectable', 'delegate') + __slots__ = ('name', 'injectable') - def __init__(self, name, injectable, delegate=False): + def __init__(self, name, injectable): """Initializer.""" self.name = name self.injectable = injectable - self.delegate = delegate @property def value(self): """Return injectable value.""" - if is_provider(self.injectable) and not self.delegate: + if is_provider(self.injectable): return self.injectable() return self.injectable diff --git a/tox.ini b/tox.ini index 2dff08c0..54d47a1f 100644 --- a/tox.ini +++ b/tox.ini @@ -39,14 +39,14 @@ basepython=python2.7 deps= flake8 commands= - flake8 --max-complexity=8 objects + flake8 --max-complexity=8 objects/ [testenv:pep257] basepython=python2.7 deps= pep257 commands= - pep257 objects + pep257 objects/ [testenv:py26] basepython=python2.6