@@ -723,19 +723,46 @@ def configure_dict(binder: Binder):
723723 Injector ([configure_dict ])
724724
725725
726- def test_multibind_types_respect_the_bound_type_scope () -> None :
726+ def test_multibind_types_are_not_affected_by_the_bound_type_scope () -> None :
727727 def configure (binder : Binder ) -> None :
728728 binder .bind (PluginA , to = PluginA , scope = singleton )
729729 binder .multibind (List [Plugin ], to = PluginA )
730730
731731 injector = Injector ([configure ])
732732 first_list = injector .get (List [Plugin ])
733733 second_list = injector .get (List [Plugin ])
734- child_injector = injector .create_child_injector ()
735- third_list = child_injector .get (List [Plugin ])
736734
737- assert first_list [0 ] is second_list [0 ]
738- assert third_list [0 ] is second_list [0 ]
735+ assert injector .get (PluginA ) is injector .get (PluginA )
736+ assert first_list [0 ] is not injector .get (PluginA )
737+ assert first_list [0 ] is not second_list [0 ]
738+
739+
740+ def test_multibind_types_are_not_affected_by_the_bound_type_provider () -> None :
741+ def configure (binder : Binder ) -> None :
742+ binder .bind (PluginA , to = InstanceProvider (PluginA ()))
743+ binder .multibind (List [Plugin ], to = PluginA )
744+
745+ injector = Injector ([configure ])
746+ first_list = injector .get (List [Plugin ])
747+ second_list = injector .get (List [Plugin ])
748+
749+ assert injector .get (PluginA ) is injector .get (PluginA )
750+ assert first_list [0 ] is not injector .get (PluginA )
751+ assert first_list [0 ] is not second_list [0 ]
752+
753+
754+ def test_multibind_dict_types_use_their_own_bound_providers_and_scopes () -> None :
755+ def configure (binder : Binder ) -> None :
756+ binder .bind (PluginA , to = InstanceProvider (PluginA ()))
757+ binder .bind (PluginB , to = PluginB , scope = singleton )
758+ binder .multibind (Dict [str , Plugin ], to = {'a' : PluginA , 'b' : PluginB })
759+
760+ injector = Injector ([configure ])
761+
762+ dictionary = injector .get (Dict [str , Plugin ])
763+
764+ assert dictionary ['a' ] is not injector .get (PluginA )
765+ assert dictionary ['b' ] is not injector .get (PluginB )
739766
740767
741768def test_multibind_list_scopes_applies_to_the_bound_items () -> None :
0 commit comments