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