11# A part of NonVisual Desktop Access (NVDA)
22# This file is covered by the GNU General Public License.
33# See the file COPYING for more details.
4- # Copyright (C) 2023-2024 NV Access Limited
4+ # Copyright (C) 2023-2025 NV Access Limited
55
66
7- from __future__ import annotations
7+ from collections . abc import Callable
88from typing import (
99 Generator ,
1010 ContextManager ,
11- Callable ,
1211 Concatenate ,
13- ParamSpec ,
14- TypeVar ,
1512)
1613import functools
1714import contextlib
1815from . import builder
1916
20-
21- _remoteFunc_self = TypeVar ("_remoteFunc_self" , bound = builder ._RemoteBase )
22- _remoteFunc_paramSpec = ParamSpec ("_remoteFunc_paramSpec" )
23- _remoteFunc_return = TypeVar ("_remoteFunc_return" )
17+ _remoteFunc_self = builder ._RemoteBase
2418
2519
2620class _BaseRemoteFuncWrapper :
@@ -29,13 +23,13 @@ def generateArgsKwargsString(self, *args, **kwargs) -> str:
2923 kwargsString = ", " .join (f"{ key } ={ repr (val )} " for key , val in kwargs .items ())
3024 return f"({ ', ' .join ([argsString , kwargsString ])} )"
3125
32- def _execRawFunc (
26+ def _execRawFunc [ ** P , R ] (
3327 self ,
34- func : Callable [Concatenate [_remoteFunc_self , _remoteFunc_paramSpec ], _remoteFunc_return ],
28+ func : Callable [Concatenate [_remoteFunc_self , P ], R ],
3529 funcSelf : _remoteFunc_self ,
36- * args : _remoteFunc_paramSpec .args ,
37- ** kwargs : _remoteFunc_paramSpec .kwargs ,
38- ) -> _remoteFunc_return :
30+ * args : P .args ,
31+ ** kwargs : P .kwargs ,
32+ ) -> R :
3933 main = funcSelf .rob .getInstructionList ("main" )
4034 main .addComment (
4135 f"Entering { func .__qualname__ } { self .generateArgsKwargsString (* args , ** kwargs )} " ,
@@ -44,16 +38,16 @@ def _execRawFunc(
4438 main .addComment (f"Exiting { func .__qualname__ } " )
4539 return res
4640
47- def __call__ (
41+ def __call__ [ ** P , R ] (
4842 self ,
49- func : Callable [Concatenate [_remoteFunc_self , _remoteFunc_paramSpec ], _remoteFunc_return ],
50- ) -> Callable [Concatenate [_remoteFunc_self , _remoteFunc_paramSpec ], _remoteFunc_return ]:
43+ func : Callable [Concatenate [_remoteFunc_self , P ], R ],
44+ ) -> Callable [Concatenate [_remoteFunc_self , P ], R ]:
5145 @functools .wraps (func )
5246 def wrapper (
5347 funcSelf : _remoteFunc_self ,
54- * args : _remoteFunc_paramSpec .args ,
55- ** kwargs : _remoteFunc_paramSpec .kwargs ,
56- ) -> _remoteFunc_return :
48+ * args : P .args ,
49+ ** kwargs : P .kwargs ,
50+ ) -> R :
5751 return self ._execRawFunc (func , funcSelf , * args , ** kwargs )
5852
5953 return wrapper
@@ -65,40 +59,40 @@ class RemoteMethodWrapper(_BaseRemoteFuncWrapper):
6559 def __init__ (self , mutable : bool = False ):
6660 self ._mutable = mutable
6761
68- def _execRawFunc (
62+ def _execRawFunc [ ** P , R ] (
6963 self ,
70- func : Callable [Concatenate [_remoteFunc_self , _remoteFunc_paramSpec ], _remoteFunc_return ],
64+ func : Callable [Concatenate [_remoteFunc_self , P ], R ],
7165 funcSelf : _remoteFunc_self ,
72- * args : _remoteFunc_paramSpec .args ,
73- ** kwargs : _remoteFunc_paramSpec .kwargs ,
74- ) -> _remoteFunc_return :
66+ * args : P .args ,
67+ ** kwargs : P .kwargs ,
68+ ) -> R :
7569 if self ._mutable and not funcSelf ._mutable :
7670 raise RuntimeError (f"{ funcSelf .__class__ .__name__ } is not mutable" )
7771 return super ()._execRawFunc (func , funcSelf , * args , ** kwargs )
7872
7973
8074class RemoteContextManager (_BaseRemoteFuncWrapper ):
81- def __call__ (
75+ def __call__ [ ** P , R ] (
8276 self ,
8377 func : Callable [
84- Concatenate [_remoteFunc_self , _remoteFunc_paramSpec ],
85- Generator [_remoteFunc_return , None , None ],
78+ Concatenate [_remoteFunc_self , P ],
79+ Generator [R , None , None ],
8680 ],
87- ) -> Callable [Concatenate [_remoteFunc_self , _remoteFunc_paramSpec ], ContextManager [_remoteFunc_return ]]:
81+ ) -> Callable [Concatenate [_remoteFunc_self , P ], ContextManager [R ]]:
8882 contextFunc = contextlib .contextmanager (func )
8983 return super ().__call__ (contextFunc )
9084
9185 @contextlib .contextmanager
92- def _execRawFunc (
86+ def _execRawFunc [ ** P , R ] (
9387 self ,
9488 func : Callable [
95- Concatenate [_remoteFunc_self , _remoteFunc_paramSpec ],
96- ContextManager [_remoteFunc_return ],
89+ Concatenate [_remoteFunc_self , P ],
90+ ContextManager [R ],
9791 ],
9892 funcSelf : _remoteFunc_self ,
99- * args : _remoteFunc_paramSpec .args ,
100- ** kwargs : _remoteFunc_paramSpec .kwargs ,
101- ) -> Generator [_remoteFunc_return , None , None ]:
93+ * args : P .args ,
94+ ** kwargs : P .kwargs ,
95+ ) -> Generator [R , None , None ]:
10296 main = funcSelf .rob .getInstructionList ("main" )
10397 main .addComment (
10498 f"Entering context manager { func .__qualname__ } { self .generateArgsKwargsString (* args , ** kwargs )} " ,
0 commit comments