2222from contextvars import ContextVar , copy_context
2323from inspect import iscoroutinefunction
2424from types import FunctionType
25- from typing import (
26- TYPE_CHECKING ,
27- Any ,
28- Callable ,
29- Optional ,
30- Sequence ,
31- Type ,
32- TypeVar ,
33- cast ,
34- )
25+ from typing import TYPE_CHECKING , cast
3526from weakref import ref as weak_ref
3627
3728from .dbus_common_elements import (
4132 DbusSomethingAsync ,
4233)
4334from .dbus_exceptions import DbusFailedError
44- from .sd_bus_internals import DbusNoReplyFlag , SdBusMessage
45-
46- CURRENT_MESSAGE : ContextVar [SdBusMessage ] = ContextVar ('CURRENT_MESSAGE' )
35+ from .sd_bus_internals import DbusNoReplyFlag
4736
37+ if TYPE_CHECKING :
38+ from typing import Any , Callable , Optional , Sequence , Type , TypeVar
4839
49- def get_current_message () -> SdBusMessage :
50- return CURRENT_MESSAGE . get ()
40+ from . dbus_proxy_async_interface_base import DbusInterfaceBaseAsync
41+ from . sd_bus_internals import SdBusMessage
5142
43+ T = TypeVar ('T' )
44+ else :
45+ T = None
5246
53- T_input = TypeVar ('T_input' )
54- T = TypeVar ('T' )
47+ CURRENT_MESSAGE : ContextVar [SdBusMessage ] = ContextVar ('CURRENT_MESSAGE' )
5548
5649
57- if TYPE_CHECKING :
58- from . dbus_proxy_async_interface_base import DbusInterfaceBaseAsync
50+ def get_current_message () -> SdBusMessage :
51+ return CURRENT_MESSAGE . get ()
5952
6053
6154class DbusMethodAsync (DbusMethodCommon , DbusSomethingAsync ):
@@ -212,14 +205,14 @@ def dbus_method_async(
212205 result_args_names : Sequence [str ] = (),
213206 input_args_names : Sequence [str ] = (),
214207 method_name : Optional [str ] = None ,
215- ) -> Callable [[T_input ], T_input ]:
208+ ) -> Callable [[T ], T ]:
216209
217210 assert not isinstance (input_signature , FunctionType ), (
218211 "Passed function to decorator directly. "
219212 "Did you forget () round brackets?"
220213 )
221214
222- def dbus_method_decorator (original_method : T_input ) -> T_input :
215+ def dbus_method_decorator (original_method : T ) -> T :
223216 assert isinstance (original_method , FunctionType )
224217 assert iscoroutinefunction (original_method ), (
225218 "Expected coroutine function. " ,
@@ -235,7 +228,7 @@ def dbus_method_decorator(original_method: T_input) -> T_input:
235228 flags = flags ,
236229 )
237230
238- return cast (T_input , new_wrapper )
231+ return cast (T , new_wrapper )
239232
240233 return dbus_method_decorator
241234
0 commit comments