comtypes 1.4.10__zip → 1.4.11__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 (145) hide show
  1. {comtypes-1.4.10 → comtypes-1.4.11}/CHANGES.txt +22 -0
  2. {comtypes-1.4.10/comtypes.egg-info → comtypes-1.4.11}/PKG-INFO +3 -2
  3. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/__init__.py +4 -4
  4. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/_comobject.py +23 -25
  5. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/_memberspec.py +100 -74
  6. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/_meta.py +1 -1
  7. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/_post_coinit/_cominterface_meta_patcher.py +3 -5
  8. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/_post_coinit/unknwn.py +29 -20
  9. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/_vtbl.py +52 -55
  10. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/automation.py +9 -10
  11. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/client/_code_cache.py +9 -23
  12. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/client/_events.py +87 -49
  13. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/client/_generate.py +0 -2
  14. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/connectionpoints.py +37 -3
  15. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/errorinfo.py +53 -15
  16. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/hints.pyi +15 -2
  17. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/hresult.py +16 -6
  18. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/messageloop.py +14 -12
  19. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/server/connectionpoints.py +68 -67
  20. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/server/inprocserver.py +8 -5
  21. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/server/localserver.py +14 -20
  22. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/server/register.py +2 -2
  23. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_GUID.py +6 -7
  24. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_basic.py +6 -3
  25. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_collections.py +6 -3
  26. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_comobject.py +19 -6
  27. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_comserver.py +25 -2
  28. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_dict.py +2 -1
  29. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_dyndispatch.py +4 -2
  30. comtypes-1.4.11/comtypes/test/test_errorinfo.py +115 -0
  31. comtypes-1.4.11/comtypes/test/test_hresult.py +48 -0
  32. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_inout_args.py +9 -2
  33. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_safearray.py +2 -1
  34. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_server_register.py +2 -1
  35. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_typeinfo.py +19 -2
  36. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_variant.py +2 -1
  37. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_w_getopt.py +4 -4
  38. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/tools/tlbparser.py +7 -6
  39. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/typeinfo.py +14 -9
  40. {comtypes-1.4.10 → comtypes-1.4.11/comtypes.egg-info}/PKG-INFO +3 -2
  41. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes.egg-info/SOURCES.txt +2 -0
  42. {comtypes-1.4.10 → comtypes-1.4.11}/pyproject.toml +1 -6
  43. {comtypes-1.4.10 → comtypes-1.4.11}/LICENSE.txt +0 -0
  44. {comtypes-1.4.10 → comtypes-1.4.11}/MANIFEST.in +0 -0
  45. {comtypes-1.4.10 → comtypes-1.4.11}/README.md +0 -0
  46. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/GUID.py +0 -0
  47. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/_npsupport.py +0 -0
  48. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/_post_coinit/__init__.py +0 -0
  49. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/_post_coinit/bstr.py +0 -0
  50. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/_post_coinit/instancemethod.py +0 -0
  51. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/_post_coinit/misc.py +0 -0
  52. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/_safearray.py +0 -0
  53. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/_tlib_version_checker.py +0 -0
  54. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/clear_cache.py +0 -0
  55. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/client/__init__.py +0 -0
  56. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/client/_activeobj.py +0 -0
  57. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/client/_constants.py +0 -0
  58. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/client/_create.py +0 -0
  59. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/client/_managing.py +0 -0
  60. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/client/dynamic.py +0 -0
  61. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/client/lazybind.py +0 -0
  62. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/git.py +0 -0
  63. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/logutil.py +0 -0
  64. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/patcher.py +0 -0
  65. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/persist.py +0 -0
  66. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/safearray.py +0 -0
  67. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/server/__init__.py +0 -0
  68. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/server/automation.py +0 -0
  69. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/server/w_getopt.py +0 -0
  70. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/shelllink.py +0 -0
  71. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/stream.py +0 -0
  72. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/TestComServer.idl +0 -0
  73. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/TestComServer.py +0 -0
  74. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/TestComServer.tlb +0 -0
  75. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/TestDispServer.idl +0 -0
  76. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/TestDispServer.py +0 -0
  77. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/TestDispServer.tlb +0 -0
  78. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/__init__.py +0 -0
  79. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/find_memleak.py +0 -0
  80. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/mylib.idl +0 -0
  81. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/mylib.tlb +0 -0
  82. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/mytypelib.idl +0 -0
  83. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/runtests.py +0 -0
  84. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/setup.py +0 -0
  85. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_BSTR.py +0 -0
  86. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_DISPPARAMS.py +0 -0
  87. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_QueryService.py +0 -0
  88. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_agilent.py +0 -0
  89. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_avmc.py +0 -0
  90. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_casesensitivity.py +0 -0
  91. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_clear_cache.py +0 -0
  92. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_client.py +0 -0
  93. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_client_dynamic.py +0 -0
  94. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_client_regenerate_modules.py +0 -0
  95. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_createwrappers.py +0 -0
  96. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_dispifc_records.py +0 -0
  97. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_dispifc_safearrays.py +0 -0
  98. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_dispinterface.py +0 -0
  99. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_excel.py +0 -0
  100. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_findgendir.py +0 -0
  101. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_getactiveobj.py +0 -0
  102. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_ie.py +0 -0
  103. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_ienum.py +0 -0
  104. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_imfattributes.py +0 -0
  105. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_jscript.js +0 -0
  106. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_midl_safearray_create.py +0 -0
  107. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_monikers.py +0 -0
  108. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_msscript.py +0 -0
  109. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_npsupport.py +0 -0
  110. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_outparam.py +0 -0
  111. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_persist.py +0 -0
  112. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_pump_events.py +0 -0
  113. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_recordinfo.py +0 -0
  114. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_sapi.py +0 -0
  115. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_server.py +0 -0
  116. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_shelllink.py +0 -0
  117. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_showevents.py +0 -0
  118. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_storage.py +0 -0
  119. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_stream.py +0 -0
  120. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_subinterface.py +0 -0
  121. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_typeannotator.py +0 -0
  122. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_urlhistory.py +0 -0
  123. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_win32com_interop.py +0 -0
  124. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_wmi.py +0 -0
  125. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/test_word.py +0 -0
  126. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/test/urlhist.tlb +0 -0
  127. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/tools/__init__.py +0 -0
  128. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/tools/codegenerator/__init__.py +0 -0
  129. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/tools/codegenerator/codegenerator.py +0 -0
  130. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/tools/codegenerator/comments.py +0 -0
  131. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/tools/codegenerator/heads.py +0 -0
  132. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/tools/codegenerator/helpers.py +0 -0
  133. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/tools/codegenerator/modulenamer.py +0 -0
  134. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/tools/codegenerator/namespaces.py +0 -0
  135. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/tools/codegenerator/packing.py +0 -0
  136. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/tools/codegenerator/typeannotator.py +0 -0
  137. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/tools/typedesc.py +0 -0
  138. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/tools/typedesc_base.py +0 -0
  139. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/util.py +0 -0
  140. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes/viewobject.py +0 -0
  141. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes.egg-info/dependency_links.txt +0 -0
  142. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes.egg-info/entry_points.txt +0 -0
  143. {comtypes-1.4.10 → comtypes-1.4.11}/comtypes.egg-info/top_level.txt +0 -0
  144. {comtypes-1.4.10 → comtypes-1.4.11}/setup.cfg +0 -0
  145. {comtypes-1.4.10 → comtypes-1.4.11}/setup.py +0 -0
@@ -1,6 +1,28 @@
1
1
  Comtypes CHANGELOG
2
2
  ==================
3
3
 
4
+ Release 1.4.11
5
+ --------------
6
+ * Improve ``PARAMFLAG_...`` and ``DISPATCH_...`` constants definitions and imports. By @junkmd.
7
+ * Introduce the ``_CDataType`` alias from typeshed. By @junkmd.
8
+ * Replace ``260`` literals/constant definitions with imports from ``ctypes.wintypes.MAX_PATH``. By @junkmd.
9
+ * Replace ``client._code_cache._get_module_filename`` with ``typeinfo.GetModuleFileName``. By @junkmd.
10
+ * Improve ``client._code_cache.SHGetSpecialFolderPath`` definition. By @junkmd.
11
+ * Add type annotations to many modules. By @junkmd.
12
+ * Add constants to many modules. By @junkmd.
13
+ * Improve import block styles to many modules. By @junkmd.
14
+ * Add ``SupportErrorInfoTest`` to ``test_comserver``. By @junkmd.
15
+ * Add ``test_errorinfo``. By @junkmd.
16
+ * Improve the type safety of ``errorinfo.ReportException``. By @junkmd.
17
+ * Change the method of retrieving the values of each field in ``_...MemberSpec`` from unpacking to dot access. By @junkmd.
18
+ * Split ``server.connectionpoints.ConnectionPointImpl._call_sinks``. By @junkmd.
19
+ * Refactor ``create_vtbl_mapping``, ``create_dispimpl`` and ``_encode_idl``. By @junkmd.
20
+ * Add ``test_hresult``. By @junkmd.
21
+ * Add ``Test_Vtbl`` to ``test_comobject.py``. By @junkmd.
22
+ * Delint ``IUnknown_AddRef`` and ``IUnknown_Release``. By @junkmd.
23
+ * Convert ``assertRaises`` usage to context manager for improved readability. By @junkmd.
24
+ * Remove the unused ``PATH`` variable from ``client/_generate.py``. By @moi15moi.
25
+
4
26
  Release 1.4.10
5
27
  --------------
6
28
  * Replace ``GetModuleFileNameA`` with ``GetModuleFileNameW`` to prevent a ``TypeError``. By @junkmd.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: comtypes
3
- Version: 1.4.10
3
+ Version: 1.4.11
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
@@ -17,6 +17,7 @@ Requires-Python: >=3.8
17
17
  Description-Content-Type: text/markdown
18
18
  License-File: LICENSE.txt
19
19
  Dynamic: download-url
20
+ Dynamic: license-file
20
21
 
21
22
  # comtypes
22
23
 
@@ -1,5 +1,5 @@
1
1
  # comtypes version numbers follow semver (http://semver.org/) and PEP 440
2
- __version__ = "1.4.10"
2
+ __version__ = "1.4.11"
3
3
 
4
4
  try:
5
5
  from _ctypes import COMError # noqa
@@ -26,7 +26,7 @@ import sys
26
26
  from ctypes import * # noqa # type: ignore
27
27
  from ctypes import HRESULT, OleDLL, WinDLL, _SimpleCData, c_int, c_ulong
28
28
  from ctypes.wintypes import DWORD, LPVOID
29
- from typing import TYPE_CHECKING
29
+ from typing import TYPE_CHECKING, Dict, Type
30
30
 
31
31
  if TYPE_CHECKING:
32
32
  from ctypes import _CData # only in `typeshed`, private in runtime
@@ -172,10 +172,10 @@ def CoUninitialize():
172
172
  # global registries.
173
173
 
174
174
  # allows to find interface classes by guid strings (iid)
175
- com_interface_registry = {}
175
+ com_interface_registry: Dict[str, Type["IUnknown"]] = {}
176
176
 
177
177
  # allows to find coclasses by guid strings (clsid)
178
- com_coclass_registry = {}
178
+ com_coclass_registry: Dict[str, Type["CoClass"]] = {}
179
179
 
180
180
 
181
181
  ################################################################
@@ -5,7 +5,6 @@ from ctypes import (
5
5
  POINTER,
6
6
  FormatError,
7
7
  OleDLL,
8
- Structure,
9
8
  WinDLL,
10
9
  byref,
11
10
  c_long,
@@ -29,11 +28,21 @@ from typing import (
29
28
  )
30
29
  from typing import Union as _UnionT
31
30
 
31
+ import comtypes
32
32
  from comtypes import GUID, IPersist, IUnknown, _CoUninitialize, hresult
33
+ from comtypes._memberspec import DISPATCH_METHOD as DISPATCH_METHOD
34
+ from comtypes._memberspec import DISPATCH_PROPERTYGET as DISPATCH_PROPERTYGET
35
+ from comtypes._memberspec import DISPATCH_PROPERTYPUT as DISPATCH_PROPERTYPUT
36
+ from comtypes._memberspec import DISPATCH_PROPERTYPUTREF as DISPATCH_PROPERTYPUTREF
33
37
  from comtypes._vtbl import _MethodFinder, create_dispimpl, create_vtbl_mapping
34
38
  from comtypes.automation import DISPID, DISPPARAMS, EXCEPINFO, VARIANT
35
39
  from comtypes.errorinfo import ISupportErrorInfo
36
- from comtypes.typeinfo import IProvideClassInfo, IProvideClassInfo2, ITypeInfo
40
+ from comtypes.typeinfo import (
41
+ GUIDKIND_DEFAULT_SOURCE_DISP_IID,
42
+ IProvideClassInfo,
43
+ IProvideClassInfo2,
44
+ ITypeInfo,
45
+ )
37
46
 
38
47
  if TYPE_CHECKING:
39
48
  from ctypes import _CArgObject, _Pointer
@@ -46,11 +55,6 @@ _debug = logger.debug
46
55
  ################################################################
47
56
  # COM object implementation
48
57
 
49
- # so we don't have to import comtypes.automation
50
- DISPATCH_METHOD = 1
51
- DISPATCH_PROPERTYGET = 2
52
- DISPATCH_PROPERTYPUT = 4
53
- DISPATCH_PROPERTYPUTREF = 8
54
58
 
55
59
  ################################################################
56
60
 
@@ -210,18 +214,18 @@ class COMObject(object):
210
214
  _reg_clsid_: ClassVar[GUID]
211
215
  _reg_typelib_: ClassVar[Tuple[str, int, int]]
212
216
  __typelib: "hints.ITypeLib"
213
- _com_pointers_: Dict[GUID, "_Pointer[_Pointer[Structure]]"]
214
- _dispimpl_: Dict[Tuple[int, int], Callable[..., Any]]
217
+ _com_pointers_: Dict[GUID, "hints.LP_LP_Vtbl"]
218
+ _dispimpl_: Dict[Tuple[comtypes.dispid, int], Callable[..., Any]]
215
219
 
216
- def __new__(cls, *args, **kw):
220
+ def __new__(cls, *args: Any, **kw: Any) -> "hints.Self":
217
221
  self = super(COMObject, cls).__new__(cls)
218
222
  if isinstance(self, c_void_p):
219
223
  # We build the VTables only for direct instances of
220
224
  # CoClass, not for POINTERs to CoClass.
221
- return self
225
+ return self # type: ignore
222
226
  if hasattr(self, "_com_interfaces_"):
223
227
  self.__prepare_comobject()
224
- return self
228
+ return self # type: ignore
225
229
 
226
230
  def __prepare_comobject(self) -> None:
227
231
  # When a CoClass instance is created, COM pointers to all
@@ -326,10 +330,10 @@ class COMObject(object):
326
330
  def IUnknown_AddRef(
327
331
  self,
328
332
  this: Any,
329
- __InterlockedIncrement: Callable[[c_long], int] = _InterlockedIncrement,
333
+ _increment: Callable[[c_long], int] = _InterlockedIncrement,
330
334
  _debug=_debug,
331
335
  ) -> int:
332
- result = __InterlockedIncrement(self._refcnt)
336
+ result = _increment(self._refcnt)
333
337
  if result == 1:
334
338
  self.__keep__(self)
335
339
  _debug("%r.AddRef() -> %s", self, result)
@@ -343,14 +347,14 @@ class COMObject(object):
343
347
  def IUnknown_Release(
344
348
  self,
345
349
  this: Any,
346
- __InterlockedDecrement: Callable[[c_long], int] = _InterlockedDecrement,
350
+ _decrement: Callable[[c_long], int] = _InterlockedDecrement,
347
351
  _debug=_debug,
348
352
  ) -> int:
349
353
  # If this is called at COM shutdown, _InterlockedDecrement()
350
354
  # must still be available, although module level variables may
351
355
  # have been deleted already - so we supply it as default
352
356
  # argument.
353
- result = __InterlockedDecrement(self._refcnt)
357
+ result = _decrement(self._refcnt)
354
358
  _debug("%r.Release() -> %s", self, result)
355
359
  if result == 0:
356
360
  self._final_release_()
@@ -417,8 +421,7 @@ class COMObject(object):
417
421
  # IProvideClassInfo2::GetGUID implementation
418
422
 
419
423
  def IProvideClassInfo2_GetGUID(self, dwGuidKind: int) -> GUID:
420
- # GUIDKIND_DEFAULT_SOURCE_DISP_IID = 1
421
- if dwGuidKind != 1:
424
+ if dwGuidKind != GUIDKIND_DEFAULT_SOURCE_DISP_IID:
422
425
  raise WindowsError(hresult.E_INVALIDARG)
423
426
  return self._outgoing_interfaces_[0]._iid_
424
427
 
@@ -516,10 +519,7 @@ class COMObject(object):
516
519
  #
517
520
  params = pDispParams[0]
518
521
 
519
- if wFlags & (4 | 8):
520
- # DISPATCH_PROPERTYPUT
521
- # DISPATCH_PROPERTYPUTREF
522
- #
522
+ if wFlags & (DISPATCH_PROPERTYPUT | DISPATCH_PROPERTYPUTREF):
523
523
  # How are the parameters unpacked for propertyput
524
524
  # operations with additional parameters? Can propput
525
525
  # have additional args?
@@ -530,9 +530,7 @@ class COMObject(object):
530
530
  # DISPATCH_PROPERTYPUTREF is specified.
531
531
  return mth(this, *args)
532
532
 
533
- else:
534
- # DISPATCH_METHOD
535
- # DISPATCH_PROPERTYGET
533
+ else: # wFlags & (DISPATCH_METHOD | DISPATCH_PROPERTYGET)
536
534
  # the positions of named arguments
537
535
  #
538
536
  # 2to3 has problems to translate 'range(...)[::-1]'
@@ -1,5 +1,6 @@
1
1
  import ctypes
2
2
  from typing import (
3
+ TYPE_CHECKING,
3
4
  Any,
4
5
  Callable,
5
6
  Dict,
@@ -8,33 +9,51 @@ from typing import (
8
9
  Literal,
9
10
  NamedTuple,
10
11
  Optional,
12
+ Sequence,
11
13
  Tuple,
12
14
  Type,
13
15
  )
14
16
  from typing import Union as _UnionT
15
17
 
16
18
  import comtypes
17
- from comtypes import _CData
18
19
 
19
- _PositionalParamFlagType = Tuple[int, Optional[str]]
20
- _OptionalParamFlagType = Tuple[int, Optional[str], Any]
21
- _ParamFlagType = _UnionT[_PositionalParamFlagType, _OptionalParamFlagType]
22
- _PositionalArgSpecElmType = Tuple[List[str], Type[_CData], str]
23
- _OptionalArgSpecElmType = Tuple[List[str], Type[_CData], str, Any]
24
- _ArgSpecElmType = _UnionT[_PositionalArgSpecElmType, _OptionalArgSpecElmType]
20
+ if TYPE_CHECKING:
21
+ from _ctypes import _PyCSimpleType
22
+ from ctypes import _CArgObject, _CDataType
25
23
 
24
+ from comtypes import hints # type: ignore
25
+ else:
26
+ _PyCSimpleType = type(ctypes.c_int)
27
+ _CArgObject = type(ctypes.byref(ctypes.c_int()))
28
+
29
+
30
+ DISPATCH_METHOD = 1
31
+ DISPATCH_PROPERTYGET = 2
32
+ DISPATCH_PROPERTYPUT = 4
33
+ DISPATCH_PROPERTYPUTREF = 8
34
+
35
+ PARAMFLAG_NONE = 0
36
+ PARAMFLAG_FIN = 1
37
+ PARAMFLAG_FOUT = 2
38
+ PARAMFLAG_FLCID = 4
39
+ PARAMFLAG_FRETVAL = 8
40
+ PARAMFLAG_FOPT = 16
41
+ PARAMFLAG_FHASDEFAULT = 32
42
+ PARAMFLAG_FHASCUSTDATA = 64
26
43
 
27
44
  _PARAMFLAGS = {
28
- "in": 1,
29
- "out": 2,
30
- "lcid": 4,
31
- "retval": 8,
32
- "optional": 16,
45
+ "in": PARAMFLAG_FIN,
46
+ "out": PARAMFLAG_FOUT,
47
+ "lcid": PARAMFLAG_FLCID,
48
+ "retval": PARAMFLAG_FRETVAL,
49
+ "optional": PARAMFLAG_FOPT,
33
50
  }
34
51
 
35
52
 
36
- def _encode_idl(names):
37
- # sum up all values found in _PARAMFLAGS, ignoring all others.
53
+ def _encode_idl(names: Sequence[str]) -> int:
54
+ """Sums up 'in', 'out', 'lcid', 'retval' and 'optional' values
55
+ found in _PARAMFLAGS, ignoring all other PARAMFLAG_... stuff.
56
+ """
38
57
  return sum([_PARAMFLAGS.get(n, 0) for n in names])
39
58
 
40
59
 
@@ -43,20 +62,20 @@ _NOTHING = object()
43
62
 
44
63
  def _unpack_argspec(
45
64
  idl: List[str],
46
- typ: Type[_CData],
65
+ typ: Type["_CDataType"],
47
66
  name: Optional[str] = None,
48
67
  defval: Any = _NOTHING,
49
- ) -> Tuple[List[str], Type[_CData], Optional[str], Any]:
68
+ ) -> Tuple[List[str], Type["_CDataType"], Optional[str], Any]:
50
69
  return idl, typ, name, defval
51
70
 
52
71
 
53
72
  def _resolve_argspec(
54
- items: Tuple[_ArgSpecElmType, ...],
55
- ) -> Tuple[Tuple[_ParamFlagType, ...], Tuple[Type[_CData], ...]]:
73
+ items: Tuple["hints.ArgSpecElmType", ...],
74
+ ) -> Tuple[Tuple["hints.ParamFlagType", ...], Tuple[Type["_CDataType"], ...]]:
56
75
  """Unpacks and converts from argspec to paramflags and argtypes.
57
76
 
58
77
  - paramflags is a sequence of `(pflags: int, argname: str, | None[, defval: Any])`.
59
- - argtypes is a sequence of `type[_CData]`.
78
+ - argtypes is a sequence of `type[_CDataType]`.
60
79
  """
61
80
  from comtypes.automation import VARIANT
62
81
 
@@ -83,14 +102,23 @@ def _resolve_argspec(
83
102
  return tuple(paramflags), tuple(argtypes)
84
103
 
85
104
 
105
+ if TYPE_CHECKING:
106
+ _VarFlags = Tuple[str, ...]
107
+ _VarFlagsWithDispIdHelpstr = Tuple["dispid", "helpstring", hints.Unpack[_VarFlags]]
108
+ _VarFlagsWithDispId = Tuple["dispid", hints.Unpack[_VarFlags]]
109
+ _VarFlagsWithHelpstr = Tuple["helpstring", hints.Unpack[_VarFlags]]
110
+ _DispIdlFlags = _UnionT[_VarFlagsWithDispIdHelpstr, _VarFlagsWithDispId]
111
+ _ComIdlFlags = _UnionT[_VarFlags, _VarFlagsWithHelpstr]
112
+
113
+
86
114
  class _ComMemberSpec(NamedTuple):
87
115
  """Specifier for a slot of COM method or property."""
88
116
 
89
- restype: Optional[Type[_CData]]
117
+ restype: Optional[Type["_CDataType"]]
90
118
  name: str
91
- argtypes: Tuple[Type[_CData], ...]
92
- paramflags: Optional[Tuple[_ParamFlagType, ...]]
93
- idlflags: Tuple[_UnionT[str, int], ...]
119
+ argtypes: Tuple[Type["_CDataType"], ...]
120
+ paramflags: Optional[Tuple["hints.ParamFlagType", ...]]
121
+ idlflags: _UnionT["_ComIdlFlags", "_DispIdlFlags"]
94
122
  doc: Optional[str]
95
123
 
96
124
  def is_prop(self) -> bool:
@@ -102,9 +130,9 @@ class _DispMemberSpec(NamedTuple):
102
130
 
103
131
  what: Literal["DISPMETHOD", "DISPPROPERTY"]
104
132
  name: str
105
- idlflags: Tuple[_UnionT[str, int], ...]
106
- restype: Optional[Type[_CData]]
107
- argspec: Tuple[_ArgSpecElmType, ...]
133
+ idlflags: "_DispIdlFlags"
134
+ restype: Optional[Type["_CDataType"]]
135
+ argspec: Tuple["hints.ArgSpecElmType", ...]
108
136
 
109
137
  @property
110
138
  def memid(self) -> int:
@@ -197,15 +225,32 @@ def COMMETHOD(idlflags, restype, methodname, *argspec) -> _ComMemberSpec:
197
225
 
198
226
 
199
227
  ################################################################
200
-
201
- _PropFunc = Optional[Callable[..., Any]]
202
- _DocType = Optional[str]
228
+ # workarounds for ctypes functions and parameters
229
+
230
+
231
+ def _prepare_parameter(value: Any, atyp: Type["_CDataType"]) -> "_CDataType":
232
+ # parameter was passed, call `from_param()` to
233
+ # convert it to a `ctypes` type.
234
+ if getattr(value, "_type_", None) is atyp:
235
+ # Array of or pointer to type `atyp` was passed,
236
+ # pointer to `atyp` expected.
237
+ v = value
238
+ elif type(atyp) is _PyCSimpleType: # type: ignore
239
+ # The `from_param` method of simple types
240
+ # (`c_int`, `c_double`, ...) returns a `byref` object which
241
+ # we cannot use since later it will be wrapped in a pointer.
242
+ # Simply call the constructor with the argument in that case.
243
+ v = atyp(value)
244
+ else:
245
+ v = atyp.from_param(value)
246
+ assert not isinstance(v, _CArgObject) # type: ignore
247
+ return v
203
248
 
204
249
 
205
250
  def _fix_inout_args(
206
251
  func: Callable[..., Any],
207
- argtypes: Tuple[Type[_CData], ...],
208
- paramflags: Tuple[_ParamFlagType, ...],
252
+ argtypes: Tuple[Type["_CDataType"], ...],
253
+ paramflags: Tuple["hints.ParamFlagType", ...],
209
254
  ) -> Callable[..., Any]:
210
255
  """This function provides a workaround for a bug in `ctypes`.
211
256
 
@@ -217,13 +262,11 @@ def _fix_inout_args(
217
262
  #
218
263
  # TODO: The workaround should be disabled when a ctypes
219
264
  # version is used where the bug is fixed.
220
- SIMPLETYPE = type(ctypes.c_int)
221
- BYREFTYPE = type(ctypes.byref(ctypes.c_int()))
222
265
 
223
266
  def call_with_inout(self, *args, **kw):
224
267
  args = list(args)
225
268
  # Indexed by order in the output
226
- outargs: Dict[int, _UnionT[_CData, "ctypes._CArgObject"]] = {}
269
+ outargs: Dict[int, "_CDataType"] = {}
227
270
  outnum = 0
228
271
  param_index = 0
229
272
  # Go through all expected arguments and match them to the provided arguments.
@@ -231,8 +274,8 @@ def _fix_inout_args(
231
274
  # through the keyword arguments.
232
275
  for i, info in enumerate(paramflags):
233
276
  direction = info[0]
234
- dir_in = direction & 1 == 1
235
- dir_out = direction & 2 == 2
277
+ dir_in = bool(direction & PARAMFLAG_FIN)
278
+ dir_out = bool(direction & PARAMFLAG_FOUT)
236
279
  is_positional = param_index < len(args)
237
280
  if not (dir_in or dir_out):
238
281
  # The original code here did not check for this special case and
@@ -249,34 +292,16 @@ def _fix_inout_args(
249
292
  name = info[1]
250
293
  # [in, out] parameters are passed as pointers,
251
294
  # this is the pointed-to type:
252
- atyp: Type[_CData] = getattr(argtypes[i], "_type_")
295
+ atyp: Type["_CDataType"] = getattr(argtypes[i], "_type_")
253
296
 
254
297
  # Get the actual parameter, either as positional or
255
298
  # keyword arg.
256
299
 
257
- def prepare_parameter(v):
258
- # parameter was passed, call `from_param()` to
259
- # convert it to a `ctypes` type.
260
- if getattr(v, "_type_", None) is atyp:
261
- # Array of or pointer to type `atyp` was passed,
262
- # pointer to `atyp` expected.
263
- pass
264
- elif type(atyp) is SIMPLETYPE:
265
- # The `from_param` method of simple types
266
- # (`c_int`, `c_double`, ...) returns a `byref` object which
267
- # we cannot use since later it will be wrapped in a pointer.
268
- # Simply call the constructor with the argument in that case.
269
- v = atyp(v)
270
- else:
271
- v = atyp.from_param(v)
272
- assert not isinstance(v, BYREFTYPE)
273
- return v
274
-
275
300
  if is_positional:
276
- v = prepare_parameter(args[param_index])
301
+ v = _prepare_parameter(args[param_index], atyp)
277
302
  args[param_index] = v
278
303
  elif name in kw:
279
- v = prepare_parameter(kw[name])
304
+ v = _prepare_parameter(kw[name], atyp)
280
305
  kw[name] = v
281
306
  else:
282
307
  # no parameter was passed, make an empty one of the required type
@@ -321,6 +346,13 @@ def _fix_inout_args(
321
346
  return call_with_inout
322
347
 
323
348
 
349
+ ################################################################
350
+
351
+
352
+ _PropFunc = Optional[Callable[..., Any]]
353
+ _DocType = Optional[str]
354
+
355
+
324
356
  class PropertyMapping(object):
325
357
  def __init__(self):
326
358
  self._data: Dict[Tuple[str, _DocType, int], List[_PropFunc]] = {}
@@ -472,8 +504,8 @@ class ComMemberGenerator(object):
472
504
  ) -> Callable[..., Any]:
473
505
  """This is a workaround. See `_fix_inout_args` docstring and comments."""
474
506
  if m.paramflags:
475
- dirflags = [(p[0] & 3) for p in m.paramflags]
476
- if 3 in dirflags:
507
+ dirflags = [(p[0] & (PARAMFLAG_FIN | PARAMFLAG_FOUT)) for p in m.paramflags]
508
+ if (PARAMFLAG_FIN | PARAMFLAG_FOUT) in dirflags:
477
509
  return _fix_inout_args(func, m.argtypes, m.paramflags)
478
510
  return func
479
511
 
@@ -510,15 +542,15 @@ class DispMemberGenerator(object):
510
542
  memid = m.memid
511
543
 
512
544
  def fget(obj):
513
- return obj.Invoke(memid, _invkind=2) # DISPATCH_PROPERTYGET
545
+ return obj.Invoke(memid, _invkind=DISPATCH_PROPERTYGET)
514
546
 
515
547
  if "readonly" in m.idlflags:
516
548
  return property(fget)
517
549
 
518
550
  def fset(obj, value):
519
- # Detect whether to use DISPATCH_PROPERTYPUT or
520
- # DISPATCH_PROPERTYPUTREF
521
- invkind = 8 if comtypes._is_object(value) else 4
551
+ # Detect whether to use PUT or PUTREF
552
+ is_ref = comtypes._is_object(value)
553
+ invkind = DISPATCH_PROPERTYPUTREF if is_ref else DISPATCH_PROPERTYPUT
522
554
  return obj.Invoke(memid, value, _invkind=invkind)
523
555
 
524
556
  return property(fget, fset)
@@ -529,25 +561,19 @@ class DispMemberGenerator(object):
529
561
  if "propget" in m.idlflags:
530
562
 
531
563
  def getfunc(obj, *args, **kw):
532
- return obj.Invoke(
533
- memid, _invkind=2, *args, **kw
534
- ) # DISPATCH_PROPERTYGET
564
+ return obj.Invoke(memid, _invkind=DISPATCH_PROPERTYGET, *args, **kw)
535
565
 
536
566
  return getfunc
537
567
  elif "propput" in m.idlflags:
538
568
 
539
569
  def putfunc(obj, *args, **kw):
540
- return obj.Invoke(
541
- memid, _invkind=4, *args, **kw
542
- ) # DISPATCH_PROPERTYPUT
570
+ return obj.Invoke(memid, _invkind=DISPATCH_PROPERTYPUT, *args, **kw)
543
571
 
544
572
  return putfunc
545
573
  elif "propputref" in m.idlflags:
546
574
 
547
575
  def putreffunc(obj, *args, **kw):
548
- return obj.Invoke(
549
- memid, _invkind=8, *args, **kw
550
- ) # DISPATCH_PROPERTYPUTREF
576
+ return obj.Invoke(memid, _invkind=DISPATCH_PROPERTYPUTREF, *args, **kw)
551
577
 
552
578
  return putreffunc
553
579
  # a first attempt to make use of the restype. Still, support for
@@ -556,7 +582,7 @@ class DispMemberGenerator(object):
556
582
  interface = m.restype.__com_interface__ # type: ignore
557
583
 
558
584
  def comitffunc(obj, *args, **kw):
559
- result = obj.Invoke(memid, _invkind=1, *args, **kw)
585
+ result = obj.Invoke(memid, _invkind=DISPATCH_METHOD, *args, **kw)
560
586
  if result is None:
561
587
  return
562
588
  return result.QueryInterface(interface)
@@ -564,7 +590,7 @@ class DispMemberGenerator(object):
564
590
  return comitffunc
565
591
 
566
592
  def func(obj, *args, **kw):
567
- return obj.Invoke(memid, _invkind=1, *args, **kw) # DISPATCH_METHOD
593
+ return obj.Invoke(memid, _invkind=DISPATCH_METHOD, *args, **kw)
568
594
 
569
595
  return func
570
596
 
@@ -61,7 +61,7 @@ class _coclass_meta(type):
61
61
  # XXX We should insist that a _reg_clsid_ is present.
62
62
  if "_reg_clsid_" in namespace:
63
63
  clsid = namespace["_reg_clsid_"]
64
- comtypes.com_coclass_registry[str(clsid)] = self
64
+ comtypes.com_coclass_registry[str(clsid)] = self # type: ignore
65
65
 
66
66
  # `_coclass_pointer_meta` is a subclass inherited from `_coclass_meta`.
67
67
  # In other words, when the `__new__` method of this metaclass is called, an
@@ -2,7 +2,7 @@ import types
2
2
  from _ctypes import COMError
3
3
  from typing import Type
4
4
 
5
- from comtypes import patcher
5
+ from comtypes import hresult, patcher
6
6
 
7
7
  _all_slice = slice(None, None, None)
8
8
 
@@ -96,8 +96,7 @@ def callable_and_subscriptable(itf: Type) -> None:
96
96
  try:
97
97
  result = self.Item(*args)
98
98
  except COMError as err:
99
- (hresult, text, details) = err.args
100
- if hresult == -2147352565: # DISP_E_BADINDEX
99
+ if err.hresult == hresult.DISP_E_BADINDEX:
101
100
  raise IndexError("invalid index")
102
101
  else:
103
102
  raise
@@ -115,8 +114,7 @@ def callable_and_subscriptable(itf: Type) -> None:
115
114
  try:
116
115
  self.Item[index] = value
117
116
  except COMError as err:
118
- (hresult, text, details) = err.args
119
- if hresult == -2147352565: # DISP_E_BADINDEX
117
+ if err.hresult == hresult.DISP_E_BADINDEX:
120
118
  raise IndexError("invalid index")
121
119
  else:
122
120
  raise