File tree Expand file tree Collapse file tree 3 files changed +11
-1
lines changed Expand file tree Collapse file tree 3 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ Development version
13
13
- Fix ``container.reset_singleton() `` to reset all provider types, not only ``Singleton ``.
14
14
- Improve ``container.traverse(types=[...]) `` and ``provider.traverse(types=[...]) `` typing stubs
15
15
to return ``types `` -typed iterator.
16
+ - Update docs on creating custom providers with a requirement to specify ``.related `` property.
16
17
17
18
4.18.0
18
19
------
Original file line number Diff line number Diff line change @@ -20,8 +20,11 @@ To create a custom provider you need to follow these rules:
20
20
from the ``providers `` module. After the a new provider object is created use
21
21
``Provider._copy_overriding() `` method to copy all overriding providers. See the example
22
22
below.
23
- 4. If the new provider has a ``__init__() `` method, it should call the parent
23
+ 4. If new provider has a ``__init__() `` method, it should call the parent
24
24
``Provider.__init__() ``.
25
+ 5. If new provider stores any other providers, these providers should be listed in
26
+ ``.related `` property. Property ``.related `` also should yield providers from parent
27
+ ``.related `` property.
25
28
26
29
.. literalinclude :: ../../examples/providers/custom_factory.py
27
30
:language: python
Original file line number Diff line number Diff line change @@ -25,6 +25,12 @@ def __deepcopy__(self, memo):
25
25
26
26
return copied
27
27
28
+ @property
29
+ def related (self ):
30
+ """Return related providers generator."""
31
+ yield from [self ._factory ]
32
+ yield from super ().related
33
+
28
34
def _provide (self , args , kwargs ):
29
35
return self ._factory (* args , ** kwargs )
30
36
You can’t perform that action at this time.
0 commit comments