1
- # Stubs for functools (Python 3)
2
-
3
- # NOTE: These are incomplete!
4
-
5
- from abc import ABCMeta , abstractmethod
6
1
import sys
7
- from typing import Any , Callable , Generic , Dict , Iterable , Mapping , Optional , Sequence , Tuple , TypeVar , NamedTuple , overload
8
- from collections import namedtuple
2
+ from typing import Any , Callable , Generic , Dict , Iterable , Mapping , Optional , Sequence , Tuple , Type , TypeVar , NamedTuple , Union , overload
9
3
10
4
_AnyCallable = Callable [..., Any ]
11
5
@@ -19,15 +13,17 @@ def reduce(function: Callable[[_T, _T], _T],
19
13
sequence : Iterable [_T ]) -> _T : ...
20
14
21
15
22
- class CacheInfo (NamedTuple ('CacheInfo' , [
23
- ('hits' , int ), ('misses' , int ), ('maxsize' , int ), ('currsize' , int )])
24
- ):
25
- ...
16
+ class _CacheInfo (NamedTuple ('CacheInfo' , [
17
+ ('hits' , int ),
18
+ ('misses' , int ),
19
+ ('maxsize' , int ),
20
+ ('currsize' , int )
21
+ ])): ...
26
22
27
23
class _lru_cache_wrapper (Generic [_T ]):
28
24
__wrapped__ = ... # type: Callable[..., _T]
29
25
def __call__ (self , * args : Any , ** kwargs : Any ) -> _T : ...
30
- def cache_info (self ) -> CacheInfo : ...
26
+ def cache_info (self ) -> _CacheInfo : ...
31
27
32
28
class lru_cache ():
33
29
def __init__ (self , maxsize : Optional [int ] = ..., typed : bool = ...) -> None : ...
@@ -51,6 +47,22 @@ class partial(Generic[_T]):
51
47
def __call__ (self , * args : Any , ** kwargs : Any ) -> _T : ...
52
48
53
49
if sys .version_info >= (3 , 4 ):
50
+ # With protocols, this could change into a generic protocol that defines __get__ and returns _T
51
+ _Descriptor = Any
52
+
53
+ class partialmethod (Generic [_T ]):
54
+ func : Union [Callable [..., _T ], _Descriptor ]
55
+ args : Tuple [Any , ...]
56
+ keywords : Dict [str , Any ]
57
+
58
+ @overload
59
+ def __init__ (self , func : Callable [..., _T ], * args : Any , ** keywords : Any ) -> None : ...
60
+ @overload
61
+ def __init__ (self , func : _Descriptor , * args : Any , ** keywords : Any ) -> None : ...
62
+ def __get__ (self , obj : Any , cls : Type [Any ]) -> Callable [..., _T ]: ...
63
+ @property
64
+ def __isabstractmethod__ (self ) -> bool : ...
65
+
54
66
class _SingleDispatchCallable (Generic [_T ]):
55
67
registry = ... # type: Mapping[Any, Callable[..., _T]]
56
68
def dispatch (self , cls : Any ) -> Callable [..., _T ]: ...
0 commit comments