44
44
logger = logging .getLogger (__name__ )
45
45
46
46
47
- def wrap_outparam (punk ):
48
- # type: (Any) -> Any
47
+ def wrap_outparam (punk : Any ) -> Any :
49
48
logger .debug ("wrap_outparam(%s)" , punk )
50
49
if not punk :
51
50
return None
@@ -54,8 +53,7 @@ def wrap_outparam(punk):
54
53
return punk
55
54
56
55
57
- def GetBestInterface (punk ):
58
- # type: (Any) -> Any
56
+ def GetBestInterface (punk : Any ) -> Any :
59
57
"""Try to QueryInterface a COM pointer to the 'most useful'
60
58
interface.
61
59
@@ -151,21 +149,23 @@ def GetBestInterface(punk):
151
149
#
152
150
# Object creation
153
151
#
154
- if comtypes .TYPE_CHECKING :
152
+ @overload
153
+ def GetActiveObject (progid : _UnionT [str , CoClass , GUID ]) -> Any :
154
+ ...
155
155
156
- @overload
157
- def GetActiveObject (progid ):
158
- # type: (_UnionT[str, CoClass, GUID]) -> Any
159
- pass
160
156
161
- @overload
162
- def GetActiveObject (progid , interface ):
163
- # type: (_UnionT[str, CoClass, GUID], Type[_T_IUnknown]) -> _T_IUnknown
164
- pass
157
+ @overload
158
+ def GetActiveObject (
159
+ progid : _UnionT [str , CoClass , GUID ], interface : Type [_T_IUnknown ]
160
+ ) -> _T_IUnknown :
161
+ ...
165
162
166
163
167
- def GetActiveObject (progid , interface = None , dynamic = False ):
168
- # type: (_UnionT[str, CoClass, GUID], Optional[Any], bool) -> Any
164
+ def GetActiveObject (
165
+ progid : _UnionT [str , CoClass , GUID ],
166
+ interface : Optional [Type [IUnknown ]] = None ,
167
+ dynamic : bool = False ,
168
+ ) -> Any :
169
169
"""Return a pointer to a running COM object that has been
170
170
registered with COM.
171
171
@@ -188,8 +188,9 @@ def GetActiveObject(progid, interface=None, dynamic=False):
188
188
return _manage (obj , clsid , interface = interface )
189
189
190
190
191
- def _manage (obj , clsid , interface ):
192
- # type: (Any, Optional[GUID], Optional[Type[IUnknown]]) -> Any
191
+ def _manage (
192
+ obj : Any , clsid : Optional [GUID ], interface : Optional [Type [IUnknown ]]
193
+ ) -> Any :
193
194
obj .__dict__ ["__clsid" ] = str (clsid )
194
195
if interface is None :
195
196
obj = GetBestInterface (obj )
@@ -221,35 +222,33 @@ def GetClassObject(progid, clsctx=None, pServerInfo=None, interface=None):
221
222
return comtypes .CoGetClassObject (clsid , clsctx , pServerInfo , interface )
222
223
223
224
224
- if TYPE_CHECKING :
225
+ @overload
226
+ def CreateObject (progid : _UnionT [str , CoClass , GUID ]) -> Any :
227
+ ...
225
228
226
- @overload
227
- def CreateObject (progid ):
228
- # type: (_UnionT[str, CoClass, GUID]) -> Any
229
- pass
230
229
231
- @overload
232
- def CreateObject (
233
- progid ,
234
- clsctx = None ,
235
- machine = None ,
236
- interface = None ,
237
- dynamic = False ,
238
- pServerInfo = None ,
239
- ):
240
- # type: (_UnionT[str, CoClass, GUID], Optional[int], Optional[str], Optional[Type[_T_IUnknown]], bool, Optional[comtypes.COSERVERINFO]) -> _T_IUnknown
241
- pass
230
+ @overload
231
+ def CreateObject (
232
+ progid : _UnionT [str , CoClass , GUID ],
233
+ clsctx : Optional [int ] = None ,
234
+ machine : Optional [str ] = None ,
235
+ interface : Optional [Type [_T_IUnknown ]] = None ,
236
+ dynamic : bool = ...,
237
+ pServerInfo : Optional [comtypes .COSERVERINFO ] = None ,
238
+ ) -> _T_IUnknown :
239
+ ...
242
240
243
241
244
242
def CreateObject (
245
- progid , # which object to create
246
- clsctx = None , # how to create the object
247
- machine = None , # where to create the object
248
- interface = None , # the interface we want
249
- dynamic = False , # use dynamic dispatch
250
- pServerInfo = None , # server info struct for remoting
251
- ):
252
- # type: (_UnionT[str, CoClass, GUID], Optional[int], Optional[str], Optional[Type[IUnknown]], bool, Optional[comtypes.COSERVERINFO]) -> Any
243
+ progid : _UnionT [str , CoClass , GUID ], # which object to create
244
+ clsctx : Optional [int ] = None , # how to create the object
245
+ machine : Optional [str ] = None , # where to create the object
246
+ interface : Optional [Type [IUnknown ]] = None , # the interface we want
247
+ dynamic : bool = False , # use dynamic dispatch
248
+ pServerInfo : Optional [
249
+ comtypes .COSERVERINFO
250
+ ] = None , # server info struct for remoting
251
+ ) -> Any :
253
252
"""Create a COM object from 'progid', and try to QueryInterface()
254
253
it to the most useful interface, generating typelib support on
255
254
demand. A pointer to this interface is returned.
@@ -304,21 +303,21 @@ def CreateObject(
304
303
return _manage (obj , clsid , interface = interface )
305
304
306
305
307
- if TYPE_CHECKING :
306
+ @overload
307
+ def CoGetObject (displayname : str , interface : Type [_T_IUnknown ]) -> _T_IUnknown :
308
+ ...
308
309
309
- @overload
310
- def CoGetObject (displayname , interface ):
311
- # type: (str, Type[_T_IUnknown]) -> _T_IUnknown
312
- pass
313
310
314
- @overload
315
- def CoGetObject (displayname , interface = None , dynamic = False ):
316
- # type: (str, None, bool) -> Any
317
- pass
311
+ @overload
312
+ def CoGetObject (displayname : str , interface : None = None , dynamic : bool = False ) -> Any :
313
+ ...
318
314
319
315
320
- def CoGetObject (displayname , interface = None , dynamic = False ):
321
- # type: (str, Optional[Type[comtypes.IUnknown]], bool) -> Any
316
+ def CoGetObject (
317
+ displayname : str ,
318
+ interface : Optional [Type [comtypes .IUnknown ]] = None ,
319
+ dynamic : bool = False ,
320
+ ) -> Any :
322
321
"""Create an object by calling CoGetObject(displayname).
323
322
324
323
Additional parameters have the same meaning as in CreateObject().
0 commit comments