mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-22 09:36:48 +03:00
Add container name to the representation of the dependency provider
This commit is contained in:
parent
0d8f2ff44e
commit
8b770772a1
|
@ -13,6 +13,7 @@ Development version
|
|||
are defined.
|
||||
See issue: `#383 <https://github.com/ets-labs/python-dependency-injector/issues/383>`_.
|
||||
Thanks to `@shaunc <https://github.com/shaunc>`_ for suggesting the feature.
|
||||
- Add container name to the representation of the ``Dependency`` provider.
|
||||
- Add docs cross-links between ``Singleton`` provider and "Reset container singletons"
|
||||
pages.
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -689,7 +689,12 @@ cdef class Dependency(Provider):
|
|||
|
||||
:rtype: str
|
||||
"""
|
||||
return represent_provider(provider=self, provides=self.__instance_of)
|
||||
name = f'<{self.__class__.__module__}.{self.__class__.__name__}'
|
||||
name += f'({repr(self.__instance_of)}) at {hex(id(self))}'
|
||||
if self.parent_name:
|
||||
name += f', container name: "{self.parent_name}"'
|
||||
name += f'>'
|
||||
return name
|
||||
|
||||
def __repr__(self):
|
||||
"""Return string representation of provider.
|
||||
|
|
|
@ -591,6 +591,18 @@ class DependencyTests(unittest.TestCase):
|
|||
repr(list),
|
||||
hex(id(self.provider))))
|
||||
|
||||
def test_repr_in_container(self):
|
||||
class Container(containers.DeclarativeContainer):
|
||||
dependency = providers.Dependency(instance_of=int)
|
||||
|
||||
container = Container()
|
||||
|
||||
self.assertEqual(repr(container.dependency),
|
||||
'<dependency_injector.providers.'
|
||||
'Dependency({0}) at {1}, container name: "Container.dependency">'.format(
|
||||
repr(int),
|
||||
hex(id(container.dependency))))
|
||||
|
||||
|
||||
class ExternalDependencyTests(unittest.TestCase):
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user