comtypes 1.4.5__zip → 1.4.6__zip

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. {comtypes-1.4.5 → comtypes-1.4.6}/CHANGES.txt +12 -0
  2. {comtypes-1.4.5/comtypes.egg-info → comtypes-1.4.6}/PKG-INFO +1 -1
  3. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/GUID.py +24 -24
  4. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/__init__.py +1 -1
  5. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/_memberspec.py +4 -12
  6. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/automation.py +12 -39
  7. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/client/__init__.py +2 -9
  8. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/client/_code_cache.py +2 -2
  9. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/hints.pyi +6 -18
  10. comtypes-1.4.6/comtypes/test/test_recordinfo.py +79 -0
  11. comtypes-1.4.6/comtypes/test/test_typeannotator.py +127 -0
  12. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/tools/codegenerator/codegenerator.py +0 -1
  13. comtypes-1.4.6/comtypes/tools/codegenerator/modulenamer.py +23 -0
  14. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/tools/codegenerator/typeannotator.py +27 -22
  15. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/tools/tlbparser.py +22 -24
  16. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/tools/typedesc_base.py +2 -8
  17. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/typeinfo.py +33 -35
  18. {comtypes-1.4.5 → comtypes-1.4.6/comtypes.egg-info}/PKG-INFO +1 -1
  19. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes.egg-info/SOURCES.txt +2 -0
  20. comtypes-1.4.5/comtypes/tools/codegenerator/modulenamer.py +0 -24
  21. {comtypes-1.4.5 → comtypes-1.4.6}/LICENSE.txt +0 -0
  22. {comtypes-1.4.5 → comtypes-1.4.6}/MANIFEST.in +0 -0
  23. {comtypes-1.4.5 → comtypes-1.4.6}/README.md +0 -0
  24. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/_comobject.py +0 -0
  25. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/_idl_stuff.py +0 -0
  26. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/_meta.py +0 -0
  27. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/_npsupport.py +0 -0
  28. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/_post_coinit/__init__.py +0 -0
  29. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/_post_coinit/bstr.py +0 -0
  30. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/_post_coinit/misc.py +0 -0
  31. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/_post_coinit/unknwn.py +0 -0
  32. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/_py_instance_method.py +0 -0
  33. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/_safearray.py +0 -0
  34. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/_tlib_version_checker.py +0 -0
  35. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/clear_cache.py +0 -0
  36. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/client/_constants.py +0 -0
  37. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/client/_events.py +0 -0
  38. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/client/_generate.py +0 -0
  39. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/client/dynamic.py +0 -0
  40. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/client/lazybind.py +0 -0
  41. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/connectionpoints.py +0 -0
  42. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/errorinfo.py +0 -0
  43. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/git.py +0 -0
  44. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/hresult.py +0 -0
  45. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/logutil.py +0 -0
  46. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/messageloop.py +0 -0
  47. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/patcher.py +0 -0
  48. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/persist.py +0 -0
  49. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/safearray.py +0 -0
  50. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/server/__init__.py +0 -0
  51. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/server/automation.py +0 -0
  52. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/server/connectionpoints.py +0 -0
  53. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/server/inprocserver.py +0 -0
  54. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/server/localserver.py +0 -0
  55. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/server/register.py +0 -0
  56. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/server/w_getopt.py +0 -0
  57. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/shelllink.py +0 -0
  58. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/stream.py +0 -0
  59. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/TestComServer.idl +0 -0
  60. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/TestComServer.py +0 -0
  61. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/TestComServer.tlb +0 -0
  62. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/TestDispServer.idl +0 -0
  63. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/TestDispServer.py +0 -0
  64. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/TestDispServer.tlb +0 -0
  65. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/__init__.py +0 -0
  66. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/find_memleak.py +0 -0
  67. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/mylib.idl +0 -0
  68. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/mylib.tlb +0 -0
  69. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/mytypelib.idl +0 -0
  70. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/runtests.py +0 -0
  71. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/setup.py +0 -0
  72. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_BSTR.py +0 -0
  73. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_DISPPARAMS.py +0 -0
  74. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_GUID.py +0 -0
  75. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_QueryService.py +0 -0
  76. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_agilent.py +0 -0
  77. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_avmc.py +0 -0
  78. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_basic.py +0 -0
  79. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_casesensitivity.py +0 -0
  80. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_clear_cache.py +0 -0
  81. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_client.py +0 -0
  82. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_client_dynamic.py +0 -0
  83. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_client_regenerate_modules.py +0 -0
  84. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_collections.py +0 -0
  85. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_comserver.py +0 -0
  86. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_createwrappers.py +0 -0
  87. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_dict.py +0 -0
  88. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_dispifc_records.py +0 -0
  89. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_dispifc_safearrays.py +0 -0
  90. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_dispinterface.py +0 -0
  91. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_dyndispatch.py +0 -0
  92. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_excel.py +0 -0
  93. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_findgendir.py +0 -0
  94. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_getactiveobj.py +0 -0
  95. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_ie.py +0 -0
  96. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_ienum.py +0 -0
  97. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_imfattributes.py +0 -0
  98. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_inout_args.py +0 -0
  99. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_istream.py +0 -0
  100. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_jscript.js +0 -0
  101. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_midl_safearray_create.py +0 -0
  102. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_msscript.py +0 -0
  103. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_npsupport.py +0 -0
  104. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_outparam.py +0 -0
  105. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_propputref.py +0 -0
  106. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_pump_events.py +0 -0
  107. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_safearray.py +0 -0
  108. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_sapi.py +0 -0
  109. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_server.py +0 -0
  110. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_showevents.py +0 -0
  111. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_subinterface.py +0 -0
  112. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_typeinfo.py +0 -0
  113. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_urlhistory.py +0 -0
  114. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_variant.py +0 -0
  115. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_win32com_interop.py +0 -0
  116. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_wmi.py +0 -0
  117. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/test_word.py +0 -0
  118. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/test/urlhist.tlb +0 -0
  119. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/tools/__init__.py +0 -0
  120. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/tools/codegenerator/__init__.py +0 -0
  121. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/tools/codegenerator/helpers.py +0 -0
  122. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/tools/codegenerator/namespaces.py +0 -0
  123. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/tools/codegenerator/packing.py +0 -0
  124. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/tools/typedesc.py +0 -0
  125. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/util.py +0 -0
  126. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes/viewobject.py +0 -0
  127. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes.egg-info/dependency_links.txt +0 -0
  128. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes.egg-info/entry_points.txt +0 -0
  129. {comtypes-1.4.5 → comtypes-1.4.6}/comtypes.egg-info/top_level.txt +0 -0
  130. {comtypes-1.4.5 → comtypes-1.4.6}/pyproject.toml +0 -0
  131. {comtypes-1.4.5 → comtypes-1.4.6}/setup.cfg +0 -0
  132. {comtypes-1.4.5 → comtypes-1.4.6}/setup.py +0 -0
@@ -1,6 +1,18 @@
1
1
  Comtypes CHANGELOG
2
2
  ==================
3
3
 
4
+ Release 1.4.6
5
+ --------------
6
+ * Add tests and method annotations for ``IRecordInfo``. By @junkmd.
7
+ * Improve static typings in ``automation``. By @junkmd.
8
+ * Tidy up import part in some modules. By @junkmd.
9
+ * Refer to ``Any`` and ``Tuple`` from the ``hints`` stub instead of directly importing them in generated modules. By @junkmd.
10
+ * Modernize ``GUID.py``. By @junkmd.
11
+ * Improve ``codegenerator.modulenamer`` static typing. By @junkmd.
12
+ * Avoid using keywords in ``TYPE_CHECKING`` blocks. By @junkmd.
13
+ * Improve member defining parts of ``ParseInterface`` and ``ParseDispatch``. By @junkmd.
14
+ * Fix Annoying SyntaxWarning. By @v01d-gh.
15
+
4
16
  Release 1.4.5
5
17
  --------------
6
18
  * Split ``__init__.py`` into some modules. By @junkmd.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: comtypes
3
- Version: 1.4.5
3
+ Version: 1.4.6
4
4
  Summary: Pure Python COM package
5
5
  Home-page: https://github.com/enthought/comtypes
6
6
  Download-URL: https://github.com/enthought/comtypes/releases
@@ -1,8 +1,12 @@
1
- from ctypes import *
2
- import sys
1
+ from ctypes import oledll, windll
2
+ from ctypes import byref, c_byte, c_ushort, c_ulong, c_wchar_p, Structure
3
+ from typing import Any, TYPE_CHECKING
3
4
 
5
+ if TYPE_CHECKING:
6
+ from comtypes import hints # type: ignore
4
7
 
5
- def binary(obj):
8
+
9
+ def binary(obj: "GUID") -> bytes:
6
10
  return bytes(obj)
7
11
 
8
12
 
@@ -31,37 +35,32 @@ class GUID(Structure):
31
35
  _CLSIDFromString(str(name), byref(self))
32
36
 
33
37
  def __repr__(self):
34
- return 'GUID("%s")' % str(self)
38
+ return f'GUID("{str(self)}")'
35
39
 
36
- def __unicode__(self):
40
+ def __str__(self) -> str:
37
41
  p = c_wchar_p()
38
42
  _StringFromCLSID(byref(self), byref(p))
39
43
  result = p.value
40
44
  _CoTaskMemFree(p)
41
- return result
42
-
43
- __str__ = __unicode__
44
-
45
- def __cmp__(self, other):
46
- if isinstance(other, GUID):
47
- return cmp(binary(self), binary(other))
48
- return -1
45
+ # stringified `GUID_null` would be '{00000000-0000-0000-0000-000000000000}'
46
+ # Should we do `assert result is not None`?
47
+ return result # type: ignore
49
48
 
50
- def __bool__(self):
49
+ def __bool__(self) -> bool:
51
50
  return self != GUID_null
52
51
 
53
- def __eq__(self, other):
52
+ def __eq__(self, other) -> bool:
54
53
  return isinstance(other, GUID) and binary(self) == binary(other)
55
54
 
56
- def __hash__(self):
55
+ def __hash__(self) -> int:
57
56
  # We make GUID instances hashable, although they are mutable.
58
57
  return hash(binary(self))
59
58
 
60
- def copy(self):
59
+ def copy(self) -> "GUID":
61
60
  return GUID(str(self))
62
61
 
63
62
  @classmethod
64
- def from_progid(cls, progid):
63
+ def from_progid(cls, progid: Any) -> "hints.Self":
65
64
  """Get guid from progid, ..."""
66
65
  if hasattr(progid, "_reg_clsid_"):
67
66
  progid = progid._reg_clsid_
@@ -74,19 +73,20 @@ class GUID(Structure):
74
73
  _CLSIDFromProgID(str(progid), byref(inst))
75
74
  return inst
76
75
  else:
77
- raise TypeError("Cannot construct guid from %r" % progid)
76
+ raise TypeError(f"Cannot construct guid from {progid!r}")
78
77
 
79
- def as_progid(self):
80
- "Convert a GUID into a progid"
78
+ def as_progid(self) -> str:
79
+ """Convert a GUID into a progid"""
81
80
  progid = c_wchar_p()
82
81
  _ProgIDFromCLSID(byref(self), byref(progid))
83
82
  result = progid.value
84
83
  _CoTaskMemFree(progid)
85
- return result
84
+ # Should we do `assert result is not None`?
85
+ return result # type: ignore
86
86
 
87
87
  @classmethod
88
- def create_new(cls):
89
- "Create a brand new guid"
88
+ def create_new(cls) -> "hints.Self":
89
+ """Create a brand new guid"""
90
90
  guid = cls()
91
91
  _CoCreateGuid(byref(guid))
92
92
  return guid
@@ -1,5 +1,5 @@
1
1
  # comtypes version numbers follow semver (http://semver.org/) and PEP 440
2
- __version__ = "1.4.5"
2
+ __version__ = "1.4.6"
3
3
 
4
4
  try:
5
5
  from _ctypes import COMError # noqa
@@ -1,16 +1,8 @@
1
1
  import ctypes
2
- from typing import (
3
- Any,
4
- Callable,
5
- Dict,
6
- Iterator,
7
- List,
8
- NamedTuple,
9
- Optional,
10
- Tuple,
11
- Type,
12
- Union as _UnionT,
13
- )
2
+ from typing import Any, NamedTuple
3
+ from typing import Dict, List, Tuple, Type
4
+ from typing import Optional, Union as _UnionT
5
+ from typing import Callable, Iterator
14
6
 
15
7
  from comtypes import _CData
16
8
  import comtypes
@@ -7,18 +7,9 @@ from ctypes import *
7
7
  from ctypes import _Pointer
8
8
  from _ctypes import CopyComPointer
9
9
  from ctypes.wintypes import DWORD, LONG, UINT, VARIANT_BOOL, WCHAR, WORD
10
- from typing import (
11
- Any,
12
- Callable,
13
- ClassVar,
14
- List,
15
- Optional,
16
- TYPE_CHECKING,
17
- Tuple,
18
- Union as _UnionT,
19
- )
20
-
21
- from comtypes import BSTR, COMError, COMMETHOD, GUID, IID, IUnknown, STDMETHOD
10
+ from typing import Any, ClassVar, Dict, List, Optional, TYPE_CHECKING, Type
11
+
12
+ from comtypes import _CData, BSTR, COMError, COMMETHOD, GUID, IID, IUnknown, STDMETHOD
22
13
  from comtypes.hresult import *
23
14
  from comtypes._memberspec import _DispMemberSpec
24
15
  import comtypes.patcher
@@ -649,7 +640,7 @@ class _(object):
649
640
  def __setitem__(self, index, value):
650
641
  # This is to support the same sematics as a pointer instance:
651
642
  # variant[0] = value
652
- self[index].value = value
643
+ self[index].value = value # type: ignore
653
644
 
654
645
 
655
646
  ################################################################
@@ -789,28 +780,8 @@ DISPID_DESTRUCTOR = -7
789
780
  DISPID_COLLECT = -8
790
781
 
791
782
 
792
- RawGetIDsOfNamesFunc = Callable[
793
- [_byref_type, "Array[c_wchar_p]", int, int, "Array[DISPID]"], int
794
- ]
795
- # fmt: off
796
- RawInvokeFunc = Callable[
797
- [
798
- int, _byref_type, int, int, # dispIdMember, riid, lcid, wFlags
799
- _UnionT[_byref_type, DISPPARAMS], # *pDispParams
800
- _UnionT[_byref_type, VARIANT], # pVarResult
801
- _UnionT[_byref_type, EXCEPINFO, None], # pExcepInfo
802
- _UnionT[_byref_type, c_uint], # puArgErr
803
- ],
804
- int,
805
- ]
806
- # fmt: on
807
-
808
-
809
783
  class IDispatch(IUnknown):
810
784
  _disp_methods_: ClassVar[List[_DispMemberSpec]]
811
- _GetTypeInfo: Callable[[int, int], IUnknown]
812
- __com_GetIDsOfNames: RawGetIDsOfNamesFunc
813
- __com_Invoke: RawInvokeFunc
814
785
 
815
786
  _iid_ = GUID("{00020400-0000-0000-C000-000000000046}")
816
787
  _methods_ = [
@@ -851,7 +822,7 @@ class IDispatch(IUnknown):
851
822
  """Return type information. Index 0 specifies typeinfo for IDispatch"""
852
823
  import comtypes.typeinfo
853
824
 
854
- result = self._GetTypeInfo(index, lcid)
825
+ result = self._GetTypeInfo(index, lcid) # type: ignore
855
826
  return result.QueryInterface(comtypes.typeinfo.ITypeInfo)
856
827
 
857
828
  def GetIDsOfNames(self, *names: str, **kw: Any) -> List[int]:
@@ -860,7 +831,7 @@ class IDispatch(IUnknown):
860
831
  assert not kw
861
832
  arr = (c_wchar_p * len(names))(*names)
862
833
  ids = (DISPID * len(names))()
863
- self.__com_GetIDsOfNames(riid_null, arr, len(names), lcid, ids)
834
+ self.__com_GetIDsOfNames(riid_null, arr, len(names), lcid, ids) # type: ignore
864
835
  return ids[:]
865
836
 
866
837
  def _invoke(self, memid: int, invkind: int, lcid: int, *args: Any) -> Any:
@@ -880,7 +851,9 @@ class IDispatch(IUnknown):
880
851
  dp.rgdispidNamedArgs = pointer(DISPID(DISPID_PROPERTYPUT))
881
852
  dp.rgvarg = array
882
853
 
883
- self.__com_Invoke(memid, riid_null, lcid, invkind, dp, var, None, argerr)
854
+ self.__com_Invoke( # type: ignore
855
+ memid, riid_null, lcid, invkind, dp, var, None, argerr
856
+ )
884
857
  return var._get_value(dynamic=True)
885
858
 
886
859
  def __make_dp(self, _invkind: int, *args: Any) -> DISPPARAMS:
@@ -916,7 +889,7 @@ class IDispatch(IUnknown):
916
889
  excepinfo = EXCEPINFO()
917
890
  argerr = c_uint()
918
891
  try:
919
- self.__com_Invoke(
892
+ self.__com_Invoke( # type: ignore
920
893
  dispid,
921
894
  riid_null,
922
895
  _lcid,
@@ -980,7 +953,7 @@ _arraycode_to_vartype = {
980
953
  "B": VT_UI1,
981
954
  }
982
955
 
983
- _ctype_to_vartype = {
956
+ _ctype_to_vartype: Dict[Type[_CData], int] = {
984
957
  c_byte: VT_I1,
985
958
  c_ubyte: VT_UI1,
986
959
  c_short: VT_I2,
@@ -1016,7 +989,7 @@ _ctype_to_vartype = {
1016
989
  # POINTER(IDispatch): VT_DISPATCH,
1017
990
  }
1018
991
 
1019
- _vartype_to_ctype = {}
992
+ _vartype_to_ctype: Dict[int, Type[_CData]] = {}
1020
993
  for c, v in _ctype_to_vartype.items():
1021
994
  _vartype_to_ctype[v] = c
1022
995
  _vartype_to_ctype[VT_INT] = _vartype_to_ctype[VT_I4]
@@ -12,15 +12,8 @@ import ctypes
12
12
  import logging
13
13
  import os
14
14
  import sys
15
- from typing import (
16
- Any,
17
- Optional,
18
- overload,
19
- Type,
20
- TYPE_CHECKING,
21
- TypeVar,
22
- Union as _UnionT,
23
- )
15
+ from typing import Any, overload, TypeVar, TYPE_CHECKING
16
+ from typing import Optional, Type, Union as _UnionT
24
17
 
25
18
  import comtypes
26
19
  from comtypes.hresult import *
@@ -34,10 +34,10 @@ def _find_gen_dir():
34
34
  appended to comtypes.gen.__path__ .
35
35
 
36
36
  For a Python script using comtypes, the additional directory is
37
- '%APPDATA%\<username>\Python\Python25\comtypes_cache'.
37
+ '%APPDATA%\\<username>\\Python\\Python25\\comtypes_cache'.
38
38
 
39
39
  For an executable frozen with py2exe, the additional directory is
40
- '%TEMP%\comtypes_cache\<imagebasename>-25'.
40
+ '%TEMP%\\comtypes_cache\\<imagebasename>-25'.
41
41
  """
42
42
  _create_comtypes_gen_package()
43
43
  from comtypes import gen
@@ -3,22 +3,10 @@
3
3
  # - utilities for type hints.
4
4
  import ctypes
5
5
  import sys
6
- from typing import (
7
- Any,
8
- Callable,
9
- ClassVar,
10
- Generic,
11
- Iterator,
12
- List,
13
- NoReturn,
14
- Sequence,
15
- Tuple,
16
- Type,
17
- TypeVar,
18
- Optional,
19
- overload,
20
- Union as _UnionT,
21
- )
6
+ from typing import Any as Any, ClassVar, Generic, NoReturn, TypeVar, overload
7
+ from typing import Optional, Union as _UnionT
8
+ from typing import List, Tuple as Tuple, Type
9
+ from typing import Callable, Iterator, Sequence
22
10
 
23
11
  if sys.version_info >= (3, 8):
24
12
  from typing import Protocol
@@ -35,9 +23,9 @@ else:
35
23
  from typing_extensions import Concatenate, ParamSpec, TypeAlias
36
24
  from typing_extensions import TypeGuard as TypeGuard
37
25
  if sys.version_info >= (3, 11):
38
- from typing import Self
26
+ from typing import Self as Self
39
27
  else:
40
- from typing_extensions import Self
28
+ from typing_extensions import Self as Self
41
29
 
42
30
  import comtypes
43
31
  from comtypes import IUnknown as IUnknown, GUID as GUID
@@ -0,0 +1,79 @@
1
+ # coding: utf-8
2
+
3
+ import unittest
4
+
5
+ from comtypes import typeinfo
6
+ from comtypes.client import GetModule
7
+ from ctypes import byref, pointer, sizeof
8
+
9
+ ComtypesCppTestSrvLib_GUID = "{07D2AEE5-1DF8-4D2C-953A-554ADFD25F99}"
10
+
11
+ try:
12
+ GetModule((ComtypesCppTestSrvLib_GUID, 1, 0, 0))
13
+ from comtypes.gen.ComtypesCppTestSrvLib import StructRecordParamTest
14
+
15
+ IMPORT_FAILED = False
16
+ except (ImportError, OSError):
17
+ IMPORT_FAILED = True
18
+
19
+
20
+ def _create_recordinfo() -> typeinfo.IRecordInfo:
21
+ return typeinfo.GetRecordInfoFromGuids(*StructRecordParamTest._recordinfo_)
22
+
23
+
24
+ def _create_record(
25
+ question: str, answer: int, needs_clarification: bool
26
+ ) -> "StructRecordParamTest":
27
+ record = StructRecordParamTest()
28
+ record.question = question
29
+ record.answer = answer
30
+ record.needs_clarification = needs_clarification
31
+ return record
32
+
33
+
34
+ @unittest.skipIf(IMPORT_FAILED, "This depends on the out of process COM-server.")
35
+ class Test_IRecordInfo(unittest.TestCase):
36
+ def test_RecordCopy(self):
37
+ dst_rec = StructRecordParamTest()
38
+ ri = _create_recordinfo()
39
+ ri.RecordCopy(pointer(_create_record("foo", 3, True)), byref(dst_rec))
40
+ self.assertEqual(dst_rec.question, "foo")
41
+ self.assertEqual(dst_rec.answer, 3)
42
+ self.assertEqual(dst_rec.needs_clarification, True)
43
+
44
+ def test_GetGuid(self):
45
+ *_, expected_guid = StructRecordParamTest._recordinfo_
46
+ self.assertEqual(str(_create_recordinfo().GetGuid()), expected_guid)
47
+
48
+ def test_GetName(self):
49
+ self.assertEqual(
50
+ _create_recordinfo().GetName(),
51
+ StructRecordParamTest.__qualname__,
52
+ )
53
+
54
+ def test_GetSize(self):
55
+ self.assertEqual(
56
+ _create_recordinfo().GetSize(),
57
+ sizeof(StructRecordParamTest),
58
+ )
59
+
60
+ def test_GetTypeInfo(self):
61
+ ta = _create_recordinfo().GetTypeInfo().GetTypeAttr()
62
+ *_, expected_guid = StructRecordParamTest._recordinfo_
63
+ self.assertEqual(str(ta.guid), expected_guid)
64
+
65
+ def test_IsMatchingType(self):
66
+ ri = _create_recordinfo()
67
+ ti = ri.GetTypeInfo()
68
+ self.assertTrue(typeinfo.GetRecordInfoFromTypeInfo(ti).IsMatchingType(ri))
69
+
70
+ def test_RecordCreateCopy(self):
71
+ ri = _create_recordinfo()
72
+ actual = ri.RecordCreateCopy(byref(_create_record("foo", 3, True)))
73
+ self.assertIsInstance(actual, int)
74
+ dst_rec = StructRecordParamTest()
75
+ ri.RecordCopy(actual, byref(dst_rec))
76
+ ri.RecordDestroy(actual)
77
+ self.assertEqual(dst_rec.question, "foo")
78
+ self.assertEqual(dst_rec.answer, 3)
79
+ self.assertEqual(dst_rec.needs_clarification, True)
@@ -0,0 +1,127 @@
1
+ import unittest
2
+
3
+ from comtypes.tools import typedesc
4
+ from comtypes.tools.codegenerator import typeannotator
5
+ from comtypes.tools.tlbparser import (
6
+ BSTR_type,
7
+ HRESULT_type,
8
+ VARIANT_type,
9
+ VARIANT_BOOL_type,
10
+ )
11
+
12
+
13
+ iunknown_type = typedesc.ComInterface(
14
+ "IUnknown", None, "{00000000-0000-0000-C000-000000000046}", ["hidden"], None
15
+ )
16
+ idispatch_type = typedesc.ComInterface(
17
+ "IDispatch",
18
+ iunknown_type,
19
+ "{00020400-0000-0000-C000-000000000046}",
20
+ ["restricted"],
21
+ None,
22
+ )
23
+ void_type = typedesc.FundamentalType("void", 0, 0)
24
+
25
+
26
+ class Test_AvoidUsingKeywords(unittest.TestCase):
27
+ def _create_typedesc_disp_interface(self) -> typedesc.DispInterface:
28
+ guid = "{00000000-0000-0000-0000-000000000000}"
29
+ itf = typedesc.DispInterface("IDispDerived", idispatch_type, guid, [], None)
30
+ ham = typedesc.DispProperty(0, "ham", BSTR_type, ["readonly"], None)
31
+ bacon = typedesc.DispMethod(
32
+ 472, 1, "bacon", VARIANT_BOOL_type, ["hidden"], None
33
+ )
34
+ bacon.add_argument(VARIANT_type, "and", ["in"], None)
35
+ bacon.add_argument(VARIANT_type, "foo", ["in"], None)
36
+ get_spam = typedesc.DispMethod(6, 2, "spam", VARIANT_type, ["propget"], None)
37
+ get_spam.add_argument(VARIANT_type, "arg1", ["in", "optional"], None)
38
+ put_spam = typedesc.DispMethod(6, 4, "spam", void_type, ["propput"], None)
39
+ put_spam.add_argument(VARIANT_type, "arg1", ["in", "optional"], None)
40
+ put_spam.add_argument(VARIANT_type, "arg2", ["in"], None)
41
+ except_ = typedesc.DispProperty(1, "except", BSTR_type, ["readonly"], None)
42
+ raise_ = typedesc.DispMethod(
43
+ 474, 1, "raise", VARIANT_BOOL_type, ["hidden"], None
44
+ )
45
+ raise_.add_argument(VARIANT_type, "foo", ["in"], None)
46
+ raise_.add_argument(VARIANT_type, "bar", ["in", "optional"], None)
47
+ get_def = typedesc.DispMethod(8, 2, "def", VARIANT_type, ["propget"], None)
48
+ get_def.add_argument(VARIANT_type, "arg1", ["in", "optional"], None)
49
+ put_def = typedesc.DispMethod(8, 4, "def", void_type, ["propput"], None)
50
+ put_def.add_argument(VARIANT_type, "arg1", ["in", "optional"], None)
51
+ put_def.add_argument(VARIANT_type, "arg2", ["in"], None)
52
+ for m in [ham, bacon, get_spam, put_spam, except_, raise_, get_def, put_def]:
53
+ itf.add_member(m)
54
+ return itf
55
+
56
+ def test_disp_interface(self):
57
+ itf = self._create_typedesc_disp_interface()
58
+ expected = (
59
+ " @property # dispprop\n"
60
+ " def ham(self) -> hints.Incomplete: ...\n"
61
+ " pass # @property # dispprop\n"
62
+ " pass # avoid using a keyword for def except(self) -> hints.Incomplete: ...\n" # noqa
63
+ " def bacon(self, *args: hints.Any, **kwargs: hints.Any) -> hints.Incomplete: ...\n" # noqa
64
+ " def _get_spam(self, arg1: hints.Incomplete = ...) -> hints.Incomplete: ...\n" # noqa
65
+ " def _set_spam(self, arg1: hints.Incomplete = ..., **kwargs: hints.Any) -> hints.Incomplete: ...\n" # noqa
66
+ " spam = hints.named_property('spam', _get_spam, _set_spam)\n"
67
+ " pass # avoid using a keyword for def raise(self, foo: hints.Incomplete, bar: hints.Incomplete = ...) -> hints.Incomplete: ...\n" # noqa
68
+ " def _get_def(self, arg1: hints.Incomplete = ...) -> hints.Incomplete: ...\n" # noqa
69
+ " def _set_def(self, arg1: hints.Incomplete = ..., **kwargs: hints.Any) -> hints.Incomplete: ...\n" # noqa
70
+ " pass # avoid using a keyword for def = hints.named_property('def', _get_def, _set_def)" # noqa
71
+ )
72
+ self.assertEqual(
73
+ expected, typeannotator.DispInterfaceMembersAnnotator(itf).generate()
74
+ )
75
+
76
+ def _create_typedesc_com_interface(self) -> typedesc.ComInterface:
77
+ guid = "{00000000-0000-0000-0000-000000000000}"
78
+ itf = typedesc.ComInterface(
79
+ "IUnkDerived", iunknown_type, guid, ["hidden"], None
80
+ )
81
+ spam = typedesc.ComMethod(
82
+ 2, 1610678269, "spam", HRESULT_type, ["propget"], None
83
+ )
84
+ get_ham = typedesc.ComMethod(
85
+ 2, 1610678270, "ham", HRESULT_type, ["propget"], None
86
+ )
87
+ put_ham = typedesc.ComMethod(
88
+ 4, 1610678270, "ham", HRESULT_type, ["propput"], None
89
+ )
90
+ bacon = typedesc.ComMethod(1, 1610678271, "bacon", HRESULT_type, [], None)
91
+ bacon.add_argument(VARIANT_type, "foo", ["in"], None)
92
+ bacon.add_argument(VARIANT_type, "or", ["in"], None)
93
+ global_ = typedesc.ComMethod(
94
+ 2, 1610678272, "global", HRESULT_type, ["propget"], None
95
+ )
96
+ get_class = typedesc.ComMethod(
97
+ 2, 1610678273, "class", HRESULT_type, ["propget"], None
98
+ )
99
+ put_class = typedesc.ComMethod(
100
+ 4, 1610678273, "class", HRESULT_type, ["propput"], None
101
+ )
102
+ pass_ = typedesc.ComMethod(1, 1610678274, "pass", HRESULT_type, [], None)
103
+ pass_.add_argument(VARIANT_type, "foo", ["in"], None)
104
+ pass_.add_argument(VARIANT_type, "bar", ["in", "optional"], None)
105
+ members = [spam, get_ham, put_ham, bacon, global_, get_class, put_class, pass_]
106
+ itf.extend_members(members)
107
+ return itf
108
+
109
+ def test_com_interface(self):
110
+ itf = self._create_typedesc_com_interface()
111
+ expected = (
112
+ " def _get_spam(self) -> hints.Hresult: ...\n"
113
+ " spam = hints.normal_property(_get_spam)\n"
114
+ " def _get_ham(self) -> hints.Hresult: ...\n"
115
+ " def _set_ham(self) -> hints.Hresult: ...\n"
116
+ " ham = hints.normal_property(_get_ham, _set_ham)\n"
117
+ " def bacon(self, *args: hints.Any, **kwargs: hints.Any) -> hints.Hresult: ...\n" # noqa
118
+ " def _get_global(self) -> hints.Hresult: ...\n"
119
+ " pass # avoid using a keyword for global = hints.normal_property(_get_global)\n" # noqa
120
+ " def _get_class(self) -> hints.Hresult: ...\n"
121
+ " def _set_class(self) -> hints.Hresult: ...\n"
122
+ " pass # avoid using a keyword for class = hints.normal_property(_get_class, _set_class)\n" # noqa
123
+ " pass # avoid using a keyword for def pass(self, foo: hints.Incomplete, bar: hints.Incomplete = ...) -> hints.Hresult: ..." # noqa
124
+ )
125
+ self.assertEqual(
126
+ expected, typeannotator.ComInterfaceMembersAnnotator(itf).generate()
127
+ )
@@ -196,7 +196,6 @@ class CodeGenerator(object):
196
196
  print("from typing import TYPE_CHECKING", file=output)
197
197
  print(file=output)
198
198
  print("if TYPE_CHECKING:", file=output)
199
- print(" from typing import Any, Tuple", file=output)
200
199
  print(" from comtypes import hints", file=output)
201
200
  print(file=output)
202
201
  print(file=output)
@@ -0,0 +1,23 @@
1
+ from typing import Optional
2
+
3
+ import comtypes
4
+ from comtypes import typeinfo
5
+
6
+
7
+ def name_wrapper_module(tlib: typeinfo.ITypeLib) -> str:
8
+ """Determine the name of a typelib wrapper module"""
9
+ libattr = tlib.GetLibAttr()
10
+ guid = str(libattr.guid)[1:-1].replace("-", "_")
11
+ modname = f"_{guid}_{libattr.lcid}_{libattr.wMajorVerNum}_{libattr.wMinorVerNum}"
12
+ return f"comtypes.gen.{modname}"
13
+
14
+
15
+ def name_friendly_module(tlib: typeinfo.ITypeLib) -> Optional[str]:
16
+ """Determine the friendly-name of a typelib module.
17
+ If cannot get friendly-name from typelib, returns `None`.
18
+ """
19
+ try:
20
+ modulename = tlib.GetDocumentation(-1)[0]
21
+ except comtypes.COMError:
22
+ return
23
+ return f"comtypes.gen.{modulename}"