Merge branch 'feature/rename-external-dependency' into develop

This commit is contained in:
Roman Mogylatov 2017-12-21 22:55:10 +02:00
commit 828a04de88
11 changed files with 3795 additions and 2707 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 41 KiB

View File

@ -7,6 +7,13 @@ that were made in every particular version.
From version 0.7.6 *Dependency Injector* framework strictly
follows `Semantic versioning`_
Development version
-------------------
- Rename ``ExternalDependency`` provider to ``Dependency``.
- Add default value for ``instance_of`` argument of ``Dependency`` provider -
``Dependency(instance_of=object)``.
3.8.2
-----
- Fix padding problem in code samples in docs (part 2).

View File

@ -1,9 +1,9 @@
External dependency providers
-----------------------------
Dependency providers
--------------------
.. currentmodule:: dependency_injector.providers
:py:class:`ExternalDependency` provider can be useful for development of
:py:class:`Dependency` provider can be useful for development of
self-sufficient libraries / modules / applications that have required external
dependencies.
@ -35,11 +35,10 @@ Example:
Instead of this, ``UsersService`` has external dependency, that has to
be satisfied by cleint's code, out of library's scope.
.. image:: /images/providers/external_dependency.png
.. image:: /images/providers/dependency.png
.. literalinclude:: ../../examples/providers/external_dependency.py
.. literalinclude:: ../../examples/providers/dependency.py
:language: python
:linenos:
.. disqus::

View File

@ -21,6 +21,6 @@ Providers package API docs - :py:mod:`dependency_injector.providers`
singleton
callable
object
external_dependency
dependency
overriding
custom

View File

@ -1,4 +1,4 @@
"""`ExternalDependency` providers example."""
"""`Dependency` providers example."""
import sqlite3
import contextlib
@ -45,7 +45,7 @@ class UsersService(object):
# Database and UsersService providers:
database = providers.ExternalDependency(instance_of=sqlite3.dbapi2.Connection)
database = providers.Dependency(instance_of=sqlite3.dbapi2.Connection)
users_service_factory = providers.Factory(UsersService,
database=database)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -25,10 +25,14 @@ cdef class Delegate(Object):
pass
cdef class ExternalDependency(Provider):
cdef class Dependency(Provider):
cdef type __instance_of
cdef class ExternalDependency(Dependency):
pass
cdef class OverridingContext(object):
cdef Provider __overridden
cdef Provider __overriding

View File

@ -295,8 +295,8 @@ cdef class Delegate(Object):
super(Delegate, self).__init__(ensure_is_provider(provides))
cdef class ExternalDependency(Provider):
""":py:class:`ExternalDependency` provider describes dependency interface.
cdef class Dependency(Provider):
""":py:class:`Dependency` provider describes dependency interface.
This provider is used for description of dependency interface. That might
be useful when dependency could be provided in the client's code only,
@ -305,7 +305,7 @@ cdef class ExternalDependency(Provider):
.. code-block:: python
database_provider = ExternalDependency(sqlite3.dbapi2.Connection)
database_provider = Dependency(sqlite3.dbapi2.Connection)
database_provider.override(Factory(sqlite3.connect, ':memory:'))
database = database_provider()
@ -315,12 +315,12 @@ cdef class ExternalDependency(Provider):
Class of required dependency.
:type: type
"""
"""
def __init__(self, type instance_of):
def __init__(self, type instance_of=object):
"""Initializer."""
self.__instance_of = instance_of
super(ExternalDependency, self).__init__()
super(Dependency, self).__init__()
def __deepcopy__(self, memo):
"""Create and return full copy of provider."""
@ -391,6 +391,33 @@ cdef class ExternalDependency(Provider):
return self.override(provider)
cdef class ExternalDependency(Dependency):
""":py:class:`ExternalDependency` provider describes dependency interface.
This provider is used for description of dependency interface. That might
be useful when dependency could be provided in the client's code only,
but it's interface is known. Such situations could happen when required
dependency has non-determenistic list of dependencies itself.
.. code-block:: python
database_provider = ExternalDependency(sqlite3.dbapi2.Connection)
database_provider.override(Factory(sqlite3.connect, ':memory:'))
database = database_provider()
.. deprecated:: 3.9
Use :py:class:`Dependency` instead.
.. py:attribute:: instance_of
Class of required dependency.
:type: type
"""
cdef class OverridingContext(object):
"""Provider overriding context.

View File

@ -229,13 +229,13 @@ class DelegateTests(unittest.TestCase):
hex(id(self.delegate))))
class ExternalDependencyTests(unittest.TestCase):
class DependencyTests(unittest.TestCase):
def setUp(self):
self.provider = providers.ExternalDependency(instance_of=list)
self.provider = providers.Dependency(instance_of=list)
def test_init_with_not_class(self):
self.assertRaises(TypeError, providers.ExternalDependency, object())
self.assertRaises(TypeError, providers.Dependency, object())
def test_is_provider(self):
self.assertTrue(providers.is_provider(self.provider))
@ -252,15 +252,15 @@ class ExternalDependencyTests(unittest.TestCase):
self.assertRaises(errors.Error, self.provider)
def test_deepcopy(self):
provider = providers.ExternalDependency(int)
provider = providers.Dependency(int)
provider_copy = providers.deepcopy(provider)
self.assertIsNot(provider, provider_copy)
self.assertIsInstance(provider, providers.ExternalDependency)
self.assertIsInstance(provider, providers.Dependency)
def test_deepcopy_from_memo(self):
provider = providers.ExternalDependency(int)
provider = providers.Dependency(int)
provider_copy_memo = providers.Provider()
provider_copy = providers.deepcopy(
@ -269,7 +269,7 @@ class ExternalDependencyTests(unittest.TestCase):
self.assertIs(provider_copy, provider_copy_memo)
def test_deepcopy_overridden(self):
provider = providers.ExternalDependency(int)
provider = providers.Dependency(int)
overriding_provider = providers.Provider()
provider.override(overriding_provider)
@ -278,7 +278,7 @@ class ExternalDependencyTests(unittest.TestCase):
overriding_provider_copy = provider_copy.overridden[0]
self.assertIsNot(provider, provider_copy)
self.assertIsInstance(provider, providers.ExternalDependency)
self.assertIsInstance(provider, providers.Dependency)
self.assertIsNot(overriding_provider, overriding_provider_copy)
self.assertIsInstance(overriding_provider_copy, providers.Provider)
@ -286,6 +286,15 @@ class ExternalDependencyTests(unittest.TestCase):
def test_repr(self):
self.assertEqual(repr(self.provider),
'<dependency_injector.providers.'
'ExternalDependency({0}) at {1}>'.format(
'Dependency({0}) at {1}>'.format(
repr(list),
hex(id(self.provider))))
class ExternalDependencyTests(unittest.TestCase):
def setUp(self):
self.provider = providers.ExternalDependency(instance_of=list)
def test_is_instance(self):
self.assertIsInstance(self.provider, providers.Dependency)