Add Callable.injections read-only attribute for getting a full list of Callable injections

This commit is contained in:
Roman Mogilatov 2015-10-22 17:41:31 +03:00
parent 2052992a99
commit 5bdca32779
3 changed files with 15 additions and 1 deletions

View File

@ -264,6 +264,11 @@ class Callable(Provider):
return self.callback(*_get_injectable_args(args, self.args), return self.callback(*_get_injectable_args(args, self.args),
**_get_injectable_kwargs(kwargs, self.kwargs)) **_get_injectable_kwargs(kwargs, self.kwargs))
@property
def injections(self):
"""Return tuple of all injections."""
return self.args + self.kwargs
class Config(Provider): class Config(Provider):
"""Config provider. """Config provider.

View File

@ -17,9 +17,13 @@ Development version
examples. examples.
- Add functionality for using positional argument injections with - Add functionality for using positional argument injections with
``di.Factory``, ``di.Singleton`` and ``di.Callable`` providers. ``di.Factory``, ``di.Singleton`` and ``di.Callable`` providers.
- Add functionality for decorating classes with ``@di.inject``.
- Add ``di.Singleton.injections`` attribute that represents a tuple of all
``di.Singleton`` injections (including args, kwargs, attributes and methods).
- Add ``di.Callable.injections`` attribute that represents a tuple of all
``di.Callable`` injections (including args and kwargs).
- Add optimization for ``di.Injection.value`` property that will compute - Add optimization for ``di.Injection.value`` property that will compute
type of injection once, instead of doing this on every call. type of injection once, instead of doing this on every call.
- Add functionality for decorating classes with ``@di.inject``.
- Add support of Python 3.5. - Add support of Python 3.5.
- Add support of six 1.10.0. - Add support of six 1.10.0.
- Add minor refactorings and code style fixes. - Add minor refactorings and code style fixes.

View File

@ -755,6 +755,11 @@ class CallableTests(unittest.TestCase):
self.assertTupleEqual(provider(), (1, 2, 3, 4)) self.assertTupleEqual(provider(), (1, 2, 3, 4))
def test_injections(self):
"""Test getting a full list of injections using injections property."""
provider = di.Factory(self.example, 1, 2, arg3=3, arg4=4)
self.assertEquals(len(provider.injections), 4)
class ConfigTests(unittest.TestCase): class ConfigTests(unittest.TestCase):
"""Config test cases.""" """Config test cases."""