@@ -2,7 +2,7 @@ import threading
2
2
from _typeshed import ConvertibleToInt , Incomplete , Unused
3
3
from collections .abc import Callable , Iterable , Mapping , MutableMapping , Sequence
4
4
from logging import Logger , _Level as _LoggingLevel
5
- from typing import Any
5
+ from typing import Any , Generic , TypeVar , overload
6
6
7
7
__all__ = [
8
8
"sub_debug" ,
@@ -22,6 +22,9 @@ __all__ = [
22
22
"SUBWARNING" ,
23
23
]
24
24
25
+ _T = TypeVar ("_T" )
26
+ _R_co = TypeVar ("_R_co" , default = Any , covariant = True )
27
+
25
28
NOTSET : int
26
29
SUBDEBUG : int
27
30
DEBUG : int
@@ -42,13 +45,29 @@ def is_abstract_socket_namespace(address: str | bytes | None) -> bool: ...
42
45
abstract_sockets_supported : bool
43
46
44
47
def get_temp_dir () -> str : ...
45
- def register_after_fork (obj , func : Callable [[Incomplete ], object ]) -> None : ...
48
+ def register_after_fork (obj : _T , func : Callable [[_T ], object ]) -> None : ...
46
49
47
- class Finalize :
50
+ class Finalize (Generic [_R_co ]):
51
+ # "args" and "kwargs" are passed as arguments to "callback".
52
+ @overload
53
+ def __init__ (
54
+ self ,
55
+ obj : None ,
56
+ callback : Callable [..., _R_co ],
57
+ * ,
58
+ args : Sequence [Any ] = (),
59
+ kwargs : Mapping [str , Any ] | None = None ,
60
+ exitpriority : int ,
61
+ ) -> None : ...
62
+ @overload
63
+ def __init__ (
64
+ self , obj : None , callback : Callable [..., _R_co ], args : Sequence [Any ], kwargs : Mapping [str , Any ] | None , exitpriority : int
65
+ ) -> None : ...
66
+ @overload
48
67
def __init__ (
49
68
self ,
50
- obj : Incomplete | None ,
51
- callback : Callable [..., Incomplete ],
69
+ obj : Any ,
70
+ callback : Callable [..., _R_co ],
52
71
args : Sequence [Any ] = (),
53
72
kwargs : Mapping [str , Any ] | None = None ,
54
73
exitpriority : int | None = None ,
@@ -59,7 +78,7 @@ class Finalize:
59
78
_finalizer_registry : MutableMapping [Incomplete , Incomplete ] = {},
60
79
sub_debug : Callable [..., object ] = ...,
61
80
getpid : Callable [[], int ] = ...,
62
- ): ...
81
+ ) -> _R_co : ...
63
82
def cancel (self ) -> None : ...
64
83
def still_active (self ) -> bool : ...
65
84
0 commit comments