@@ -781,6 +781,44 @@ def configure(binder: Binder) -> None:
781781 assert first_list [2 ] is second_list [2 ]
782782
783783
784+ def test_multibind_list_scopes_applies_to_the_bound_items_not_types () -> None :
785+ def configure (binder : Binder ) -> None :
786+ binder .multibind (List [Plugin ], to = PluginA )
787+ binder .multibind (List [Plugin ], to = [PluginA , PluginB ], scope = singleton )
788+ binder .multibind (List [Plugin ], to = PluginA )
789+ binder .multibind (List [Plugin ], to = PluginA , scope = singleton )
790+
791+ injector = Injector ([configure ])
792+ first_list = injector .get (List [Plugin ])
793+ second_list = injector .get (List [Plugin ])
794+
795+ assert first_list is not second_list
796+ assert first_list [0 ] is not second_list [0 ]
797+ assert first_list [1 ] is second_list [1 ]
798+ assert first_list [2 ] is second_list [2 ]
799+ assert first_list [3 ] is not second_list [3 ]
800+ assert first_list [4 ] is second_list [4 ]
801+
802+
803+ def test_multibind_dict_scopes_applies_to_the_bound_items_in_the_multibound_dict () -> None :
804+ SingletonPlugins = Annotated [Plugin , "singleton" ]
805+ OtherPlugins = Annotated [Plugin , "other" ]
806+
807+ def configure (binder : Binder ) -> None :
808+ binder .multibind (Dict [str , SingletonPlugins ], to = {'a' : PluginA }, scope = singleton )
809+ binder .multibind (Dict [str , OtherPlugins ], to = {'a' : PluginA })
810+
811+ injector = Injector ([configure ])
812+ singletons_1 = injector .get (Dict [str , SingletonPlugins ])
813+ singletons_2 = injector .get (Dict [str , SingletonPlugins ])
814+ others_1 = injector .get (Dict [str , OtherPlugins ])
815+ others_2 = injector .get (Dict [str , OtherPlugins ])
816+
817+ assert singletons_1 ['a' ] is singletons_2 ['a' ]
818+ assert singletons_1 ['a' ] is not others_1 ['a' ]
819+ assert others_1 ['a' ] is not others_2 ['a' ]
820+
821+
784822def test_multibind_list_scopes_applies_to_the_bound_items_in_the_multibound_list () -> None :
785823 SingletonPlugins = Annotated [Plugin , "singleton" ]
786824 OtherPlugins = Annotated [Plugin , "other" ]
0 commit comments