File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed 
tests/unit/containers/instance Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -317,6 +317,10 @@ class DynamicContainer(Container):
317317
318318 def  init_resources (self , resource_type = providers.Resource):
319319 """ Initialize all container resources.""" 
320+ 
321+  if  not  issubclass (resource_type, providers.Resource):
322+  raise  TypeError (" resource_type must be a subclass of Resource provider" 
323+ 
320324 futures =  []
321325
322326 for  provider in  self .traverse(types = [resource_type]):
@@ -330,6 +334,10 @@ class DynamicContainer(Container):
330334
331335 def  shutdown_resources (self , resource_type = providers.Resource):
332336 """ Shutdown all container resources.""" 
337+ 
338+  if  not  issubclass (resource_type, providers.Resource):
339+  raise  TypeError (" resource_type must be a subclass of Resource provider" 
340+ 
333341 def  _independent_resources (resources ):
334342 for  resource in  resources:
335343 for  other_resource in  resources:
Original file line number Diff line number Diff line change @@ -325,6 +325,19 @@ class Container(containers.DeclarativeContainer):
325325 assert  _init2 .shutdown_counter  ==  2 
326326
327327
328+ def  test_init_shutdown_resources_wrong_type () ->  None :
329+  class  Container (containers .DeclarativeContainer ):
330+  pass 
331+ 
332+  c  =  Container ()
333+ 
334+  with  raises (TypeError , match = r"resource_type must be a subclass of Resource provider" ):
335+  c .init_resources (int ) # type: ignore[arg-type] 
336+ 
337+  with  raises (TypeError , match = r"resource_type must be a subclass of Resource provider" ):
338+  c .shutdown_resources (int ) # type: ignore[arg-type] 
339+ 
340+ 
328341def  test_reset_singletons ():
329342 class  SubSubContainer (containers .DeclarativeContainer ):
330343 singleton  =  providers .Singleton (object )
                         You can’t perform that action at this time. 
           
                  
0 commit comments