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