mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-02-12 09:30:46 +03:00
Add few minor refactorings
This commit is contained in:
parent
4291f0efc1
commit
b5ad081976
|
@ -52,9 +52,9 @@ class AbstractCatalog(object):
|
||||||
@classmethod
|
@classmethod
|
||||||
def filter(cls, provider_type):
|
def filter(cls, provider_type):
|
||||||
"""Return dict of providers, that are instance of provided type."""
|
"""Return dict of providers, that are instance of provided type."""
|
||||||
return dict([(name, provider)
|
return dict((name, provider)
|
||||||
for name, provider in six.iteritems(cls.providers)
|
for name, provider in six.iteritems(cls.providers)
|
||||||
if isinstance(provider, provider_type)])
|
if isinstance(provider, provider_type))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def override(cls, overriding):
|
def override(cls, overriding):
|
||||||
|
|
|
@ -54,11 +54,11 @@ def inject(*args, **kwargs):
|
||||||
:type injection: Injection
|
:type injection: Injection
|
||||||
:return: (callable) -> (callable)
|
:return: (callable) -> (callable)
|
||||||
"""
|
"""
|
||||||
injections = tuple((KwArg(name, value)
|
injections = tuple(KwArg(name, value)
|
||||||
for name, value in six.iteritems(kwargs)))
|
for name, value in six.iteritems(kwargs))
|
||||||
if args:
|
if args:
|
||||||
injections += tuple((ensure_is_injection(injection)
|
injections += tuple(ensure_is_injection(injection)
|
||||||
for injection in args))
|
for injection in args)
|
||||||
|
|
||||||
def decorator(callback):
|
def decorator(callback):
|
||||||
"""Dependency injection decorator."""
|
"""Dependency injection decorator."""
|
||||||
|
|
|
@ -108,18 +108,18 @@ class Factory(Provider):
|
||||||
raise Error('Factory provider expects to get callable, ' +
|
raise Error('Factory provider expects to get callable, ' +
|
||||||
'got {0} instead'.format(str(provides)))
|
'got {0} instead'.format(str(provides)))
|
||||||
self._provides = provides
|
self._provides = provides
|
||||||
self._kwargs = tuple((injection
|
self._kwargs = tuple(injection
|
||||||
for injection in injections
|
for injection in injections
|
||||||
if is_kwarg_injection(injection)))
|
if is_kwarg_injection(injection))
|
||||||
if kwargs:
|
if kwargs:
|
||||||
self._kwargs += tuple((KwArg(name, value)
|
self._kwargs += tuple(KwArg(name, value)
|
||||||
for name, value in six.iteritems(kwargs)))
|
for name, value in six.iteritems(kwargs))
|
||||||
self._attributes = tuple((injection
|
self._attributes = tuple(injection
|
||||||
for injection in injections
|
for injection in injections
|
||||||
if is_attribute_injection(injection)))
|
if is_attribute_injection(injection))
|
||||||
self._methods = tuple((injection
|
self._methods = tuple(injection
|
||||||
for injection in injections
|
for injection in injections
|
||||||
if is_method_injection(injection)))
|
if is_method_injection(injection))
|
||||||
super(Factory, self).__init__()
|
super(Factory, self).__init__()
|
||||||
|
|
||||||
def _provide(self, *args, **kwargs):
|
def _provide(self, *args, **kwargs):
|
||||||
|
@ -262,8 +262,8 @@ class Callable(Provider):
|
||||||
if not callable(callback):
|
if not callable(callback):
|
||||||
raise Error('Callable expected, got {0}'.format(str(callback)))
|
raise Error('Callable expected, got {0}'.format(str(callback)))
|
||||||
self._callback = callback
|
self._callback = callback
|
||||||
self._kwargs = tuple((KwArg(name, value)
|
self._kwargs = tuple(KwArg(name, value)
|
||||||
for name, value in six.iteritems(kwargs)))
|
for name, value in six.iteritems(kwargs))
|
||||||
super(Callable, self).__init__()
|
super(Callable, self).__init__()
|
||||||
|
|
||||||
def _provide(self, *args, **kwargs):
|
def _provide(self, *args, **kwargs):
|
||||||
|
|
|
@ -13,6 +13,10 @@ Development version
|
||||||
|
|
||||||
- No featues.
|
- No featues.
|
||||||
|
|
||||||
|
0.9.2
|
||||||
|
-----
|
||||||
|
- Add minor refactorings.
|
||||||
|
|
||||||
0.9.1
|
0.9.1
|
||||||
-----
|
-----
|
||||||
- Add simplified syntax of kwarg injections for ``di.Factory`` and
|
- Add simplified syntax of kwarg injections for ``di.Factory`` and
|
||||||
|
|
Loading…
Reference in New Issue
Block a user