@@ -566,6 +566,41 @@ def test_cfg_from_str(self) -> None:
566566 {"E" : {"f" : "b" , "F" : "B" }}, opts .cfg_from_str ("E=f:b,F:B" )
567567 )
568568
569+ def test_cfg_from_str_builtin_generic_types (self ) -> None :
570+ # basically a repeat of "test_cfg_from_str()" but with
571+ # list[str] and dict[str, str] instead of List[str] and Dict[str, str]
572+ opts = runopts ()
573+ opts .add ("K" , type_ = list [str ], help = "a list opt" , default = [])
574+ opts .add ("J" , type_ = str , help = "a str opt" , required = True )
575+ opts .add ("E" , type_ = dict [str , str ], help = "a dict opt" , default = [])
576+
577+ self .assertDictEqual ({}, opts .cfg_from_str ("" ))
578+ self .assertDictEqual ({}, opts .cfg_from_str ("UNKWN=b" ))
579+ self .assertDictEqual ({"K" : ["a" ], "J" : "b" }, opts .cfg_from_str ("K=a,J=b" ))
580+ self .assertDictEqual ({"K" : ["a" ]}, opts .cfg_from_str ("K=a,UNKWN=b" ))
581+ self .assertDictEqual ({"K" : ["a" , "b" ]}, opts .cfg_from_str ("K=a,b" ))
582+ self .assertDictEqual ({"K" : ["a" , "b" ]}, opts .cfg_from_str ("K=a;b" ))
583+ self .assertDictEqual ({"K" : ["a" , "b" ]}, opts .cfg_from_str ("K=a,b" ))
584+ self .assertDictEqual ({"K" : ["a" , "b" ]}, opts .cfg_from_str ("K=a,b;" ))
585+ self .assertDictEqual (
586+ {"K" : ["a" , "b" ], "J" : "d" }, opts .cfg_from_str ("K=a,b,J=d" )
587+ )
588+ self .assertDictEqual (
589+ {"K" : ["a" , "b" ], "J" : "d" }, opts .cfg_from_str ("K=a,b;J=d" )
590+ )
591+ self .assertDictEqual (
592+ {"K" : ["a" , "b" ], "J" : "d" }, opts .cfg_from_str ("K=a;b,J=d" )
593+ )
594+ self .assertDictEqual (
595+ {"K" : ["a" , "b" ], "J" : "d" }, opts .cfg_from_str ("K=a;b;J=d" )
596+ )
597+ self .assertDictEqual (
598+ {"K" : ["a" ], "J" : "d" }, opts .cfg_from_str ("J=d,K=a,UNKWN=e" )
599+ )
600+ self .assertDictEqual (
601+ {"E" : {"f" : "b" , "F" : "B" }}, opts .cfg_from_str ("E=f:b,F:B" )
602+ )
603+
569604 def test_resolve_from_str (self ) -> None :
570605 opts = runopts ()
571606 opts .add ("foo" , type_ = str , default = "" , help = "" )
0 commit comments