mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-06 12:14:27 +08:00
weakproxy fixes (#2450)
* The callback argument to ref() and proxy() is optional, per documentation * proxy() returns a ProxyType or CallableProxyType Closes #1627
This commit is contained in:
committed by
Jelle Zijlstra
parent
65863bebf4
commit
9f98737119
@@ -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: ...
|
||||
|
||||
Reference in New Issue
Block a user