@@ -2411,14 +2411,18 @@ def _(cls, arg):
24112411 self .assertEqual (A .t (0.0 ).arg , "base" )
24122412
24132413 def test_abstractmethod_register (self ):
2414- class Abstract (abc .ABCMeta ):
2414+ class Abstract (metaclass = abc .ABCMeta ):
24152415
24162416 @functools .singledispatchmethod
24172417 @abc .abstractmethod
24182418 def add (self , x , y ):
24192419 pass
24202420
24212421 self .assertTrue (Abstract .add .__isabstractmethod__ )
2422+ self .assertTrue (Abstract .__dict__ ['add' ].__isabstractmethod__ )
2423+
2424+ with self .assertRaises (TypeError ):
2425+ Abstract ()
24222426
24232427 def test_type_ann_register (self ):
24242428 class A :
@@ -2479,6 +2483,42 @@ def _(cls, arg: str):
24792483 self .assertEqual (A .t ('' ).arg , "str" )
24802484 self .assertEqual (A .t (0.0 ).arg , "base" )
24812485
2486+ def test_method_wrapping_attributes (self ):
2487+ class A :
2488+ @functools .singledispatchmethod
2489+ def func (self , arg : int ) -> str :
2490+ """My function docstring"""
2491+ return str (arg )
2492+ @functools .singledispatchmethod
2493+ @classmethod
2494+ def cls_func (cls , arg : int ) -> str :
2495+ """My function docstring"""
2496+ return str (arg )
2497+ @functools .singledispatchmethod
2498+ @staticmethod
2499+ def static_func (arg : int ) -> str :
2500+ """My function docstring"""
2501+ return str (arg )
2502+
2503+ for meth in (
2504+ A .func ,
2505+ A ().func ,
2506+ A .cls_func ,
2507+ A ().cls_func ,
2508+ A .static_func ,
2509+ A ().static_func
2510+ ):
2511+ with self .subTest (meth = meth ):
2512+ self .assertEqual (meth .__doc__ , 'My function docstring' )
2513+ self .assertEqual (meth .__annotations__ ['arg' ], int )
2514+
2515+ self .assertEqual (A .func .__name__ , 'func' )
2516+ self .assertEqual (A ().func .__name__ , 'func' )
2517+ self .assertEqual (A .cls_func .__name__ , 'cls_func' )
2518+ self .assertEqual (A ().cls_func .__name__ , 'cls_func' )
2519+ self .assertEqual (A .static_func .__name__ , 'static_func' )
2520+ self .assertEqual (A ().static_func .__name__ , 'static_func' )
2521+
24822522 def test_invalid_registrations (self ):
24832523 msg_prefix = "Invalid first argument to `register()`: "
24842524 msg_suffix = (
0 commit comments