8000 add functools.partialmethod (#1316) · python/typeshed@42cd0f5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 42cd0f5

Browse files
JelleZijlstramatthiaskramm
authored andcommitted
add functools.partialmethod (#1316)
Plus other cleanup to the py3 functools stub
1 parent 9ae9a9e commit 42cd0f5

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

stdlib/3/functools.pyi

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
# Stubs for functools (Python 3)
2-
3-
# NOTE: These are incomplete!
4-
5-
from abc import ABCMeta, abstractmethod
61
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
93

104
_AnyCallable = Callable[..., Any]
115

@@ -19,15 +13,17 @@ def reduce(function: Callable[[_T, _T], _T],
1913
sequence: Iterable[_T]) -> _T: ...
2014

2115

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+
])): ...
2622

2723
class _lru_cache_wrapper(Generic[_T]):
2824
__wrapped__ = ... # type: Callable[..., _T]
2925
def __call__(self, *args: Any, **kwargs: Any) -> _T: ...
30-
def cache_info(self) -> CacheInfo: ...
26+
def cache_info(self) -> _CacheInfo: ...
3127

3228
class lru_cache():
3329
def __init__(self, maxsize: Optional[int] = ..., typed: bool = ...) -> None: ...
@@ -51,6 +47,22 @@ class partial(Generic[_T]):
5147
def __call__(self, *args: Any, **kwargs: Any) -> _T: ...
5248

5349
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+
5466
class _SingleDispatchCallable(Generic[_T]):
5567
registry = ... # type: Mapping[Any, Callable[..., _T]]
5668
def dispatch(self, cls: Any) -> Callable[..., _T]: ...

0 commit comments

Comments
 (0)
0