11# tag::MYMAX_TYPES[]
22from typing import Protocol , Any , TypeVar , overload , Callable , Iterable , Union
33
4- class _Comparable (Protocol ):
4+ class SupportsLessThan (Protocol ):
55 def __lt__ (self , other : Any ) -> bool : ...
66
7- _T = TypeVar ('_T ' )
8- _CT = TypeVar ('_CT ' , bound = _Comparable )
9- _DT = TypeVar ('_DT ' )
7+ T = TypeVar ('T ' )
8+ LT = TypeVar ('LT ' , bound = SupportsLessThan )
9+ DT = TypeVar ('DT ' )
1010
1111MISSING = object ()
1212EMPTY_MSG = 'max() arg is an empty sequence'
1313
1414@overload
15- def max (__arg1 : _CT , __arg2 : _CT , * _args : _CT , key : None = ...) -> _CT :
15+ def max (__arg1 : LT , __arg2 : LT , * _args : LT , key : None = ...) -> LT :
1616 ...
1717@overload
18- def max (__arg1 : _T , __arg2 : _T , * _args : _T , key : Callable [[_T ], _CT ]) -> _T :
18+ def max (__arg1 : T , __arg2 : T , * _args : T , key : Callable [[T ], LT ]) -> T :
1919 ...
2020@overload
21- def max (__iterable : Iterable [_CT ], * , key : None = ...) -> _CT :
21+ def max (__iterable : Iterable [LT ], * , key : None = ...) -> LT :
2222 ...
2323@overload
24- def max (__iterable : Iterable [_T ], * , key : Callable [[_T ], _CT ]) -> _T :
24+ def max (__iterable : Iterable [T ], * , key : Callable [[T ], LT ]) -> T :
2525 ...
2626@overload
27- def max (__iterable : Iterable [_CT ], * , key : None = ...,
28- default : _DT ) -> Union [_CT , _DT ]:
27+ def max (__iterable : Iterable [LT ], * , key : None = ...,
28+ default : DT ) -> Union [LT , DT ]:
2929 ...
3030@overload
31- def max (__iterable : Iterable [_T ], * , key : Callable [[_T ], _CT ],
32- default : _DT ) -> Union [_T , _DT ]:
31+ def max (__iterable : Iterable [T ], * , key : Callable [[T ], LT ],
32+ default : DT ) -> Union [T , DT ]:
3333 ...
3434# end::MYMAX_TYPES[]
3535# tag::MYMAX[]
@@ -57,4 +57,4 @@ def max(first, *args, key=None, default=MISSING):
5757 candidate = current
5858 candidate_key = current_key
5959 return candidate
60- # end::MYMAX[]
60+ # end::MYMAX[]
0 commit comments