You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classfinalize: # TODO: This is a good candidate for to be a `Generic[_P, _T]` classdef__init__(self, __obj: object, __func: Callable[_P, Any], *args: _P.args, **kwargs: _P.kwargs) ->None: ...
def__call__(self, _: Any= ...) ->Any|None: ...
defdetach(self) ->tuple[Any, Any, tuple[Any, ...], dict[str, Any]] |None: ...
defpeek(self) ->tuple[Any, Any, tuple[Any, ...], dict[str, Any]] |None: ...
@propertydefalive(self) ->bool: ...
atexit: bool
Looking at the documentation for finalize, seen here I can see that:
finalize provides a straight forward way to register a cleanup function to be called when an object is garbage collected. This is simpler to use than setting up a callback function on a raw weak reference, since the module automatically ensures that the finalizer remains alive until the object is collected.
Note, the use of _P.args in the tuple I believe is not allowed, though it's how as a user I had originally understood and expected ParamSpec to work. Similar to how I expected it to be able to be bound to a function so that you could re-use a parameter specification of an existing function in other functions, essentially always keeping them up to date.
Yes, I was thinking about typing methods like detach:
defdetach(self):
"""If alive then mark as dead and return (obj, func, args, kwargs); otherwise return None"""info=self._registry.get(self)
obj=infoandinfo.weakref()
ifobjisnotNoneandself._registry.pop(self, None):
return (obj, info.func, info.args, info.kwargsor {})
Activity
kkirsche commentedon Jul 29, 2022
Note, the use of _P.args in the tuple I believe is not allowed, though it's how as a user I had originally understood and expected ParamSpec to work. Similar to how I expected it to be able to be bound to a function so that you could re-use a parameter specification of an existing function in other functions, essentially always keeping them up to date.
srittau commentedon Jul 29, 2022
Cc @sobolevn as author of that comment.
sobolevn commentedon Jul 29, 2022
Yes, I was thinking about typing methods like
detach:kkirsche commentedon Aug 18, 2022
Closing as I fundamentally disagree with the suggested fix of simply removing the todo.