diff --git a/stdlib/2and3/_weakref.pyi b/stdlib/2and3/_weakref.pyi index 76c97df54..6a527c189 100644 --- a/stdlib/2and3/_weakref.pyi +++ b/stdlib/2and3/_weakref.pyi @@ -1,6 +1,7 @@ import sys -from typing import Any, Callable, Generic, Optional, TypeVar +from typing import Any, Callable, Generic, Optional, TypeVar, overload +_C = TypeVar('_C', bound=Callable[..., Any]) _T = TypeVar('_T') class CallableProxyType(object): # "weakcallableproxy" @@ -12,8 +13,7 @@ class ProxyType(object): # "weakproxy" class ReferenceType(Generic[_T]): if sys.version_info >= (3, 4): __callback__: Callable[[ReferenceType[_T]], Any] - def __init__(self, o: _T, callback: Callable[[ReferenceType[_T]], - Any] = ...) -> None: ... + def __init__(self, o: _T, callback: Optional[Callable[[ReferenceType[_T]], Any]] = ...) -> None: ... def __call__(self) -> Optional[_T]: ... def __hash__(self) -> int: ... @@ -21,4 +21,8 @@ ref = ReferenceType def getweakrefcount(object: Any) -> int: ... def getweakrefs(object: Any) -> int: ... -def proxy(object: _T, callback: Callable[[_T], Any] = ...) -> ref[_T]: ... +@overload +def proxy(object: _C, callback: Optional[Callable[[_C], Any]] = ...) -> CallableProxyType: ... +# Return CallableProxyType if object is callable, ProxyType otherwise +@overload +def proxy(object: _T, callback: Optional[Callable[[_T], Any]] = ...) -> Any: ...