enthought / comtypes

A pure Python, lightweight COM client and server framework, based on the ctypes Python FFI package.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

fix `client.GetClassObject` type annotations and add tests

junkmd opened this issue · comments

Remaining tasks for #456.

if TYPE_CHECKING:
@overload
def GetClassObject(progid, clsctx=None, pServerInfo=None):
# type: (_UnionT[str, CoClass, GUID], Optional[int], Optional[comtypes.COSERVERINFO]) -> hints.IClassFactory
pass
@overload
def GetClassObject(progid, clsctx=None, pServerInfo=None, interface=None):
# type: (_UnionT[str, CoClass, GUID], Optional[int], Optional[comtypes.COSERVERINFO], Optional[Type[_T_IUnknown]]) -> _T_IUnknown
pass
def GetClassObject(progid, clsctx=None, pServerInfo=None, interface=None):
# type: (_UnionT[str, CoClass, GUID], Optional[int], Optional[comtypes.COSERVERINFO], Optional[Type[IUnknown]]) -> IUnknown
"""Create and return the class factory for a COM object.
'clsctx' specifies how to create the object, use the CLSCTX_... constants.
'pServerInfo', if used, must be a pointer to a comtypes.COSERVERINFO instance
'interface' may be used to request an interface other than IClassFactory
"""
clsid = GUID.from_progid(progid)
return comtypes.CoGetClassObject(clsid, clsctx, pServerInfo, interface)

  • remove if TYPE_CHECKING bridges, like #453.
  • change type hints from comment annotations to inline annotations, like #453.
  • add TestCase in test/test_client.py that call client.GetClassObject.
    • At least one of the tests should use a universal COM library such as those found in CI environments. Please do not use unittest.mock whenever possible.
  • make sure that if passing Type[_T_IUnknown] for interface, the return value will be analyzed as _T_IUnknown by static type checkers.
  • Before PR, please format the code by black (the maximum number of characters per line is 88, which is the default).

I hope someone who actually uses client.GetClassObject will PR along with the introduction of use cases, because I had not use this function.

This is related to #453.

Since comtypes.CoGetClassObject is also untested, we should avoid a situation where no tests without using unittest.mock.patch.