1
1
# tag::MYMAX_TYPES[]
2
2
from typing import Protocol ,Any ,TypeVar ,overload ,Callable ,Iterable ,Union
3
3
4
+ MISSING = object ()
5
+ EMPTY_MSG = 'max() arg is an empty sequence'
6
+
4
7
class _SupportsLessThan (Protocol ):
5
8
def __lt__ (self ,other :Any )-> bool : ...
6
9
7
10
_T = TypeVar ('_T' )
8
11
_LT = TypeVar ('_LT' ,bound = _SupportsLessThan )
9
12
_DT = TypeVar ('_DT' )
10
13
11
- MISSING = object ()
12
- EMPTY_MSG = 'max() arg is an empty sequence'
13
-
14
14
@overload
15
15
def max (__arg1 :_LT ,__arg2 :_LT ,* _args :_LT ,key :None = ...)-> _LT :
16
16
...
@@ -29,8 +29,6 @@ def max(__iterable: Iterable[_LT], *, key: None = ..., default: _DT) -> Union[_L
29
29
@overload
30
30
def max (__iterable :Iterable [_T ],* ,key :Callable [[_T ],_LT ],default :_DT )-> Union [_T ,_DT ]:
31
31
...
32
- # end::MYMAX_TYPES[]
33
- # tag::MYMAX[]
34
32
def max (first ,* args ,key = None ,default = MISSING ):
35
33
if args :
36
34
series = args
@@ -55,7 +53,6 @@ def max(first, *args, key=None, default=MISSING):
55
53
candidate = current
56
54
candidate_key = current_key
57
55
return candidate
58
- # end::MYMAX[]
59
56
60
57
@overload
61
58
def min (__arg1 :_LT ,__arg2 :_LT ,* _args :_LT ,key :None = ...)-> _LT :