Skip to content

Commit d469f2a

Browse files
committed
Update documentation for multibind
1 parent 4bc95be commit d469f2a

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

injector/__init__.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -504,22 +504,25 @@ def multibind(
504504
505505
A multi-binding contributes values to a list or to a dictionary. For example::
506506
507-
binder.multibind(List[str], to=['some', 'strings'])
508-
binder.multibind(List[str], to=['other', 'strings'])
509-
injector.get(List[str]) # ['some', 'strings', 'other', 'strings']
507+
binder.multibind(list[Interface], to=A)
508+
binder.multibind(list[Interface], to=[B, C()])
509+
injector.get(list[Interface]) # [<A object at 0x1000>, <B object at 0x2000>, <C object at 0x3000>]
510510
511-
binder.multibind(Dict[str, int], to={'key': 11})
512-
binder.multibind(Dict[str, int], to={'other_key': 33})
513-
injector.get(Dict[str, int]) # {'key': 11, 'other_key': 33}
511+
binder.multibind(dict[str, Interface], to={'key': A})
512+
binder.multibind(dict[str, Interface], to={'other_key': B})
513+
injector.get(dict[str, Interface]) # {'key': <A object at 0x1000>, 'other_key': <B object at 0x2000>}
514514
515515
.. versionchanged:: 0.17.0
516516
Added support for using `typing.Dict` and `typing.List` instances as interfaces.
517517
Deprecated support for `MappingKey`, `SequenceKey` and single-item lists and
518518
dictionaries as interfaces.
519519
520-
:param interface: typing.Dict or typing.List instance to bind to.
521-
:param to: Instance, class to bind to, or an explicit :class:`Provider`
522-
subclass. Must provide a list or a dictionary, depending on the interface.
520+
:param interface: A generic list[T] or dict[str, T] type to bind to.
521+
522+
:param to: A list/dict to bind to, where the values are either instances or classes implementing T.
523+
Can also be an explicit :class:`Provider` or a callable that returns a list/dict.
524+
For lists, this can also be a class implementing T (e.g. multibind(list[T], to=A))
525+
523526
:param scope: Optional Scope in which to bind.
524527
"""
525528
if interface not in self._bindings:

0 commit comments

Comments
 (0)