@@ -2411,14 +2411,18 @@ def _(cls, arg):
2411
2411
self .assertEqual (A .t (0.0 ).arg , "base" )
2412
2412
2413
2413
def test_abstractmethod_register (self ):
2414
- class Abstract (abc .ABCMeta ):
2414
+ class Abstract (metaclass = abc .ABCMeta ):
2415
2415
2416
2416
@functools .singledispatchmethod
2417
2417
@abc .abstractmethod
2418
2418
def add (self , x , y ):
2419
2419
pass
2420
2420
2421
2421
self .assertTrue (Abstract .add .__isabstractmethod__ )
2422
+ self .assertTrue (Abstract .__dict__ ['add' ].__isabstractmethod__ )
2423
+
2424
+ with self .assertRaises (TypeError ):
2425
+ Abstract ()
2422
2426
2423
2427
def test_type_ann_register (self ):
2424
2428
class A :
@@ -2479,6 +2483,42 @@ def _(cls, arg: str):
2479
2483
self .assertEqual (A .t ('' ).arg , "str" )
2480
2484
self .assertEqual (A .t (0.0 ).arg , "base" )
2481
2485
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
+
2482
2522
def test_invalid_registrations (self ):
2483
2523
msg_prefix = "Invalid first argument to `register()`: "
2484
2524
msg_suffix = (
0 commit comments