add functools.partialmethod (#1316)

Plus other cleanup to the py3 functools stub
This commit is contained in:
Jelle Zijlstra
2017-05-23 15:36:09 -07:00
committed by Matthias Kramm
parent 9ae9a9e741
commit 42cd0f59e5

View File

@@ -1,11 +1,5 @@
# Stubs for functools (Python 3)
# NOTE: These are incomplete!
from abc import ABCMeta, abstractmethod
import sys
from typing import Any, Callable, Generic, Dict, Iterable, Mapping, Optional, Sequence, Tuple, TypeVar, NamedTuple, overload
from collections import namedtuple
from typing import Any, Callable, Generic, Dict, Iterable, Mapping, Optional, Sequence, Tuple, Type, TypeVar, NamedTuple, Union, overload
_AnyCallable = Callable[..., Any]
@@ -19,15 +13,17 @@ def reduce(function: Callable[[_T, _T], _T],
sequence: Iterable[_T]) -> _T: ...
class CacheInfo(NamedTuple('CacheInfo', [
('hits', int), ('misses', int), ('maxsize', int), ('currsize', int)])
):
...
class _CacheInfo(NamedTuple('CacheInfo', [
('hits', int),
('misses', int),
('maxsize', int),
('currsize', int)
])): ...
class _lru_cache_wrapper(Generic[_T]):
__wrapped__ = ... # type: Callable[..., _T]
def __call__(self, *args: Any, **kwargs: Any) -> _T: ...
def cache_info(self) -> CacheInfo: ...
def cache_info(self) -> _CacheInfo: ...
class lru_cache():
def __init__(self, maxsize: Optional[int] = ..., typed: bool = ...) -> None: ...
@@ -51,6 +47,22 @@ class partial(Generic[_T]):
def __call__(self, *args: Any, **kwargs: Any) -> _T: ...
if sys.version_info >= (3, 4):
# With protocols, this could change into a generic protocol that defines __get__ and returns _T
_Descriptor = Any
class partialmethod(Generic[_T]):
func: Union[Callable[..., _T], _Descriptor]
args: Tuple[Any, ...]
keywords: Dict[str, Any]
@overload
def __init__(self, func: Callable[..., _T], *args: Any, **keywords: Any) -> None: ...
@overload
def __init__(self, func: _Descriptor, *args: Any, **keywords: Any) -> None: ...
def __get__(self, obj: Any, cls: Type[Any]) -> Callable[..., _T]: ...
@property
def __isabstractmethod__(self) -> bool: ...
class _SingleDispatchCallable(Generic[_T]):
registry = ... # type: Mapping[Any, Callable[..., _T]]
def dispatch(self, cls: Any) -> Callable[..., _T]: ...