@@ -3483,60 +3483,52 @@ def test_register_genericalias(self):
34833483 def f (arg ):
34843484 return "default"
34853485
3486- with self .assertRaisesRegex (TypeError , "Invalid first argument to " ):
3487- f .register (list [int ], lambda arg : "types.GenericAlias" )
3488- with self .assertRaisesRegex (TypeError , "Invalid first argument to " ):
3489- f .register (typing .List [int ], lambda arg : "typing.GenericAlias" )
3490- with self .assertRaisesRegex (TypeError , "Invalid first argument to " ):
3491- f .register (list [int ] | str , lambda arg : "types.UnionTypes(types.GenericAlias)" )
3492- with self .assertRaisesRegex (TypeError , "Invalid first argument to " ):
3493- f .register (typing .List [float ] | bytes , lambda arg : "typing.Union[typing.GenericAlias]" )
3494-
3495- self .assertEqual (f ([1 ]), "default" )
3496- self .assertEqual (f ([1.0 ]), "default" )
3497- self .assertEqual (f ("" ), "default" )
3486+ f .register (list [int ], lambda arg : "types.GenericAlias" )
3487+ f .register (list [float ] | str , lambda arg : "types.UnionTypes(types.GenericAlias)" )
3488+
3489+ self .assertEqual (f ([1 ]), "types.GenericAlias" )
3490+ self .assertEqual (f ([1.0 ]), "types.UnionTypes(types.GenericAlias)" )
3491+ self .assertEqual (f ("" ), "types.UnionTypes(types.GenericAlias)" )
34983492 self .assertEqual (f (b"" ), "default" )
34993493
35003494 def test_register_genericalias_decorator (self ):
35013495 @functools .singledispatch
35023496 def f (arg ):
35033497 return "default"
35043498
3505- with self .assertRaisesRegex (TypeError , "Invalid first argument to " ):
3506- f .register (list [int ])
3507- with self .assertRaisesRegex (TypeError , "Invalid first argument to " ):
3508- f .register (typing .List [int ])
3509- with self .assertRaisesRegex (TypeError , "Invalid first argument to " ):
3510- f .register (list [int ] | str )
3511- with self .assertRaisesRegex (TypeError , "Invalid first argument to " ):
3512- f .register (typing .List [int ] | str )
3499+ f .register (list [int ])
3500+ #f.register(typing.List[int])
3501+ f .register (list [int ] | str )
3502+ #f.register(typing.List[int] | str)
35133503
35143504 def test_register_genericalias_annotation (self ):
35153505 @functools .singledispatch
35163506 def f (arg ):
35173507 return "default"
35183508
3519- with self . assertRaisesRegex ( TypeError , "Invalid annotation for 'arg'" ):
3520- @ f . register
3521- def _ ( arg : list [ int ]):
3522- return "types.GenericAlias"
3509+ @ f . register
3510+ def _ ( arg : list [ int ]):
3511+ return "types.GenericAlias"
3512+
35233513 with self .assertRaisesRegex (TypeError , "Invalid annotation for 'arg'" ):
35243514 @f .register
35253515 def _ (arg : typing .List [float ]):
35263516 return "typing.GenericAlias"
3527- with self .assertRaisesRegex (TypeError , "Invalid annotation for 'arg'" ):
3528- @f .register
3529- def _ (arg : list [int ] | str ):
3530- return "types.UnionType(types.GenericAlias)"
3517+
3518+ @f .register
3519+ def _ (arg : list [bytes ] | str ):
3520+ return "types.UnionType(types.GenericAlias)"
3521+
35313522 with self .assertRaisesRegex (TypeError , "Invalid annotation for 'arg'" ):
35323523 @f .register
35333524 def _ (arg : typing .List [float ] | bytes ):
35343525 return "typing.Union[typing.GenericAlias]"
35353526
3536- self .assertEqual (f ([1 ]), "default " )
3527+ self .assertEqual (f ([1 ]), "types.GenericAlias " )
35373528 self .assertEqual (f ([1.0 ]), "default" )
3538- self .assertEqual (f ("" ), "default " )
3529+ self .assertEqual (f ("" ), "types.UnionType(types.GenericAlias) " )
35393530 self .assertEqual (f (b"" ), "default" )
3531+ self .assertEqual (f ([b"" ]), "types.UnionType(types.GenericAlias)" )
35403532
35413533 def test_forward_reference (self ):
35423534 @functools .singledispatch
0 commit comments