@@ -2936,6 +2936,67 @@ def static_func(arg: int) -> str:
29362936 self .assertEqual (A .static_func .__name__ , 'static_func' )
29372937 self .assertEqual (A ().static_func .__name__ , 'static_func' )
29382938
2939+ def test_method_repr (self ):
2940+ class Callable :
2941+ def __call__ (self , * args ):
2942+ pass
2943+
2944+ class CallableWithName :
2945+ __name__ = 'NOQUALNAME'
2946+ def __call__ (self , * args ):
2947+ pass
2948+
2949+ class A :
2950+ @functools .singledispatchmethod
2951+ def func (self , arg ):
2952+ pass
2953+ @functools .singledispatchmethod
2954+ @classmethod
2955+ def cls_func (cls , arg ):
2956+ pass
2957+ @functools .singledispatchmethod
2958+ @staticmethod
2959+ def static_func (arg ):
2960+ pass
2961+ # No __qualname__, only __name__
2962+ no_qualname = functools .singledispatchmethod (CallableWithName ())
2963+ # No __qualname__, no __name__
2964+ no_name = functools .singledispatchmethod (Callable ())
2965+
2966+ self .assertEqual (repr (A .__dict__ ['func' ]),
2967+ f'<single dispatch method descriptor { A .__qualname__ } .func>' )
2968+ self .assertEqual (repr (A .__dict__ ['cls_func' ]),
2969+ f'<single dispatch method descriptor { A .__qualname__ } .cls_func>' )
2970+ self .assertEqual (repr (A .__dict__ ['static_func' ]),
2971+ f'<single dispatch method descriptor { A .__qualname__ } .static_func>' )
2972+ self .assertEqual (repr (A .__dict__ ['no_qualname' ]),
2973+ f'<single dispatch method descriptor NOQUALNAME>' )
2974+ self .assertEqual (repr (A .__dict__ ['no_name' ]),
2975+ f'<single dispatch method descriptor ?>' )
2976+
2977+ self .assertEqual (repr (A .func ),
2978+ f'<single dispatch method { A .__qualname__ } .func>' )
2979+ self .assertEqual (repr (A .cls_func ),
2980+ f'<single dispatch method { A .__qualname__ } .cls_func>' )
2981+ self .assertEqual (repr (A .static_func ),
2982+ f'<single dispatch method { A .__qualname__ } .static_func>' )
2983+ self .assertEqual (repr (A .no_qualname ),
2984+ f'<single dispatch method NOQUALNAME>' )
2985+ self .assertEqual (repr (A .no_name ),
2986+ f'<single dispatch method ?>' )
2987+
2988+ a = A ()
2989+ self .assertEqual (repr (a .func ),
2990+ f'<bound single dispatch method { A .__qualname__ } .func of { a !r} >' )
2991+ self .assertEqual (repr (a .cls_func ),
2992+ f'<bound single dispatch method { A .__qualname__ } .cls_func of { a !r} >' )
2993+ self .assertEqual (repr (a .static_func ),
2994+ f'<bound single dispatch method { A .__qualname__ } .static_func of { a !r} >' )
2995+ self .assertEqual (repr (a .no_qualname ),
2996+ f'<bound single dispatch method NOQUALNAME of { a !r} >' )
2997+ self .assertEqual (repr (a .no_name ),
2998+ f'<bound single dispatch method ? of { a !r} >' )
2999+
29393000 def test_double_wrapped_methods (self ):
29403001 def classmethod_friendly_decorator (func ):
29413002 wrapped = func .__func__
0 commit comments