From c13bee6fb5b582b6552da2d0cc65851bf5126e05 Mon Sep 17 00:00:00 2001 From: Roman Mogilatov Date: Mon, 19 Oct 2015 10:50:17 +0300 Subject: [PATCH] Add optimization for `Injection.value` property --- dependency_injector/injections.py | 5 +++-- docs/main/changelog.rst | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/dependency_injector/injections.py b/dependency_injector/injections.py index bc0cf797..a7a29084 100644 --- a/dependency_injector/injections.py +++ b/dependency_injector/injections.py @@ -21,17 +21,18 @@ class Injection(object): """Base injection class.""" __IS_INJECTION__ = True - __slots__ = ('name', 'injectable') + __slots__ = ('name', 'injectable', 'is_provider') def __init__(self, name, injectable): """Initializer.""" self.name = name self.injectable = injectable + self.is_provider = is_provider(injectable) @property def value(self): """Return injectable value.""" - if is_provider(self.injectable): + if self.is_provider: return self.injectable() return self.injectable diff --git a/docs/main/changelog.rst b/docs/main/changelog.rst index 93016d4c..20c321eb 100644 --- a/docs/main/changelog.rst +++ b/docs/main/changelog.rst @@ -18,6 +18,8 @@ Development version examples. - Add support of Python 3.5. - Add support of six 1.10.0. +- Add optimization for ``di.Injection.value`` property that will compute + type of injection once, instead of doing this on every call. - Add minor refactorings and code style fixes. 0.9.5