@@ -2401,14 +2401,18 @@ def _(cls, arg):
2401
2401
self .assertEqual (A .t (0.0 ).arg , "base" )
2402
2402
2403
2403
def test_abstractmethod_register (self ):
2404
- class Abstract (abc .ABCMeta ):
2404
+ class Abstract (metaclass = abc .ABCMeta ):
2405
2405
2406
2406
@functools .singledispatchmethod
2407
2407
@abc .abstractmethod
2408
2408
def add (self , x , y ):
2409
2409
pass
2410
2410
2411
2411
self .assertTrue (Abstract .add .__isabstractmethod__ )
2412
+ self .assertTrue (Abstract .__dict__ ['add' ].__isabstractmethod__ )
2413
+
2414
+ with self .assertRaises (TypeError ):
2415
+ Abstract ()
2412
2416
2413
2417
def test_type_ann_register (self ):
2414
2418
class A :
@@ -2469,6 +2473,42 @@ def _(cls, arg: str):
2469
2473
self .assertEqual (A .t ('' ).arg , "str" )
2470
2474
self .assertEqual (A .t (0.0 ).arg , "base" )
2471
2475
2476
+ def test_method_wrapping_attributes (self ):
2477
+ class A :
2478
+ @functools .singledispatchmethod
2479
+ def func (self , arg : int ) -> str :
2480
+ """My function docstring"""
2481
+ return str (arg )
2482
+ @functools .singledispatchmethod
2483
+ @classmethod
2484
+ def cls_func (cls , arg : int ) -> str :
2485
+ """My function docstring"""
2486
+ return str (arg )
2487
+ @functools .singledispatchmethod
2488
+ @staticmethod
2489
+ def static_func (arg : int ) -> str :
2490
+ """My function docstring"""
2491
+ return str (arg )
2492
+
2493
+ for meth in (
2494
+ A .func ,
2495
+ A ().func ,
2496
+ A .cls_func ,
2497
+ A ().cls_func ,
2498
+ A .static_func ,
2499
+ A ().static_func
2500
+ ):
2501
+ with self .subTest (meth = meth ):
2502
+ self .assertEqual (meth .__doc__ , 'My function docstring' )
2503
+ self .assertEqual (meth .__annotations__ ['arg' ], int )
2504
+
2505
+ self .assertEqual (A .func .__name__ , 'func' )
2506
+ self .assertEqual (A ().func .__name__ , 'func' )
2507
+ self .assertEqual (A .cls_func .__name__ , 'cls_func' )
2508
+ self .assertEqual (A ().cls_func .__name__ , 'cls_func' )
2509
+ self .assertEqual (A .static_func .__name__ , 'static_func' )
2510
+ self .assertEqual (A ().static_func .__name__ , 'static_func' )
2511
+
2472
2512
def test_invalid_registrations (self ):
2473
2513
msg_prefix = "Invalid first argument to `register()`: "
2474
2514
msg_suffix = (
0 commit comments