comtypes 1.4.4__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 (133) hide show
  1. {comtypes-1.4.4 → comtypes-1.4.6}/CHANGES.txt +24 -0
  2. {comtypes-1.4.4/comtypes.egg-info → comtypes-1.4.6}/PKG-INFO +1 -1
  3. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/GUID.py +24 -24
  4. comtypes-1.4.6/comtypes/__init__.py +268 -0
  5. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/_comobject.py +2 -1
  6. comtypes-1.4.6/comtypes/_idl_stuff.py +67 -0
  7. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/_memberspec.py +4 -12
  8. comtypes-1.4.6/comtypes/_post_coinit/__init__.py +15 -0
  9. comtypes-1.4.6/comtypes/_post_coinit/bstr.py +30 -0
  10. comtypes-1.4.6/comtypes/_post_coinit/misc.py +385 -0
  11. comtypes-1.4.6/comtypes/_post_coinit/unknwn.py +537 -0
  12. comtypes-1.4.6/comtypes/_py_instance_method.py +13 -0
  13. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/_safearray.py +3 -2
  14. comtypes-1.4.6/comtypes/_tlib_version_checker.py +18 -0
  15. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/automation.py +34 -45
  16. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/client/__init__.py +2 -9
  17. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/client/_code_cache.py +2 -2
  18. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/client/_generate.py +2 -1
  19. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/hints.pyi +38 -16
  20. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/safearray.py +11 -4
  21. comtypes-1.4.6/comtypes/stream.py +65 -0
  22. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_client.py +11 -0
  23. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_dispifc_records.py +1 -1
  24. comtypes-1.4.6/comtypes/test/test_dispifc_safearrays.py +89 -0
  25. comtypes-1.4.6/comtypes/test/test_istream.py +53 -0
  26. comtypes-1.4.6/comtypes/test/test_midl_safearray_create.py +100 -0
  27. comtypes-1.4.6/comtypes/test/test_recordinfo.py +79 -0
  28. comtypes-1.4.6/comtypes/test/test_typeannotator.py +127 -0
  29. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_wmi.py +11 -18
  30. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/tools/codegenerator/codegenerator.py +0 -1
  31. comtypes-1.4.6/comtypes/tools/codegenerator/modulenamer.py +23 -0
  32. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/tools/codegenerator/typeannotator.py +27 -22
  33. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/tools/tlbparser.py +22 -24
  34. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/tools/typedesc_base.py +2 -8
  35. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/typeinfo.py +33 -35
  36. {comtypes-1.4.4 → comtypes-1.4.6/comtypes.egg-info}/PKG-INFO +1 -1
  37. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes.egg-info/SOURCES.txt +13 -0
  38. {comtypes-1.4.4 → comtypes-1.4.6}/setup.cfg +1 -0
  39. comtypes-1.4.4/comtypes/__init__.py +0 -1229
  40. comtypes-1.4.4/comtypes/tools/codegenerator/modulenamer.py +0 -24
  41. {comtypes-1.4.4 → comtypes-1.4.6}/LICENSE.txt +0 -0
  42. {comtypes-1.4.4 → comtypes-1.4.6}/MANIFEST.in +0 -0
  43. {comtypes-1.4.4 → comtypes-1.4.6}/README.md +0 -0
  44. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/_meta.py +0 -0
  45. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/_npsupport.py +0 -0
  46. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/clear_cache.py +0 -0
  47. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/client/_constants.py +0 -0
  48. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/client/_events.py +0 -0
  49. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/client/dynamic.py +0 -0
  50. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/client/lazybind.py +0 -0
  51. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/connectionpoints.py +0 -0
  52. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/errorinfo.py +0 -0
  53. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/git.py +0 -0
  54. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/hresult.py +0 -0
  55. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/logutil.py +0 -0
  56. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/messageloop.py +0 -0
  57. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/patcher.py +0 -0
  58. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/persist.py +0 -0
  59. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/server/__init__.py +0 -0
  60. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/server/automation.py +0 -0
  61. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/server/connectionpoints.py +0 -0
  62. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/server/inprocserver.py +0 -0
  63. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/server/localserver.py +0 -0
  64. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/server/register.py +0 -0
  65. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/server/w_getopt.py +0 -0
  66. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/shelllink.py +0 -0
  67. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/TestComServer.idl +0 -0
  68. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/TestComServer.py +0 -0
  69. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/TestComServer.tlb +0 -0
  70. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/TestDispServer.idl +0 -0
  71. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/TestDispServer.py +0 -0
  72. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/TestDispServer.tlb +0 -0
  73. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/__init__.py +0 -0
  74. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/find_memleak.py +0 -0
  75. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/mylib.idl +0 -0
  76. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/mylib.tlb +0 -0
  77. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/mytypelib.idl +0 -0
  78. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/runtests.py +0 -0
  79. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/setup.py +0 -0
  80. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_BSTR.py +0 -0
  81. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_DISPPARAMS.py +0 -0
  82. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_GUID.py +0 -0
  83. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_QueryService.py +0 -0
  84. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_agilent.py +0 -0
  85. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_avmc.py +0 -0
  86. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_basic.py +0 -0
  87. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_casesensitivity.py +0 -0
  88. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_clear_cache.py +0 -0
  89. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_client_dynamic.py +0 -0
  90. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_client_regenerate_modules.py +0 -0
  91. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_collections.py +0 -0
  92. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_comserver.py +0 -0
  93. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_createwrappers.py +0 -0
  94. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_dict.py +0 -0
  95. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_dispinterface.py +0 -0
  96. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_dyndispatch.py +0 -0
  97. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_excel.py +0 -0
  98. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_findgendir.py +0 -0
  99. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_getactiveobj.py +0 -0
  100. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_ie.py +0 -0
  101. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_ienum.py +0 -0
  102. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_imfattributes.py +0 -0
  103. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_inout_args.py +0 -0
  104. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_jscript.js +0 -0
  105. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_msscript.py +0 -0
  106. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_npsupport.py +0 -0
  107. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_outparam.py +0 -0
  108. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_propputref.py +0 -0
  109. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_pump_events.py +0 -0
  110. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_safearray.py +0 -0
  111. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_sapi.py +0 -0
  112. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_server.py +0 -0
  113. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_showevents.py +0 -0
  114. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_subinterface.py +0 -0
  115. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_typeinfo.py +0 -0
  116. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_urlhistory.py +0 -0
  117. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_variant.py +0 -0
  118. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_win32com_interop.py +0 -0
  119. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_word.py +0 -0
  120. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/urlhist.tlb +0 -0
  121. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/tools/__init__.py +0 -0
  122. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/tools/codegenerator/__init__.py +0 -0
  123. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/tools/codegenerator/helpers.py +0 -0
  124. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/tools/codegenerator/namespaces.py +0 -0
  125. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/tools/codegenerator/packing.py +0 -0
  126. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/tools/typedesc.py +0 -0
  127. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/util.py +0 -0
  128. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/viewobject.py +0 -0
  129. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes.egg-info/dependency_links.txt +0 -0
  130. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes.egg-info/entry_points.txt +0 -0
  131. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes.egg-info/top_level.txt +0 -0
  132. {comtypes-1.4.4 → comtypes-1.4.6}/pyproject.toml +0 -0
  133. {comtypes-1.4.4 → comtypes-1.4.6}/setup.py +0 -0
@@ -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
+ )
@@ -1,17 +1,10 @@
1
- import sys
2
1
  import unittest as ut
3
- from ctypes import POINTER
2
+
4
3
  from comtypes.client import CoGetObject
5
4
  from comtypes.test import requires
6
5
 
7
6
  requires("time")
8
7
 
9
- if sys.version_info >= (3, 0):
10
- base_text_type = str
11
- text_type = str
12
- else:
13
- base_text_type = basestring
14
- text_type = unicode
15
8
 
16
9
  # WMI has dual interfaces.
17
10
  # Some methods/properties have "[out] POINTER(VARIANT)" parameters.
@@ -19,7 +12,7 @@ else:
19
12
  # that's what VARIANT.__ctypes_from_outparam__ does.
20
13
  class Test(ut.TestCase):
21
14
  def test_wmi(self):
22
- wmi = CoGetObject("winmgmts:")
15
+ wmi: "WbemScripting.ISWbemServices" = CoGetObject("winmgmts:")
23
16
  disks = wmi.InstancesOf("Win32_LogicalDisk")
24
17
 
25
18
  # There are different typelibs installed for WMI on win2k and winXP.
@@ -28,8 +21,8 @@ class Test(ut.TestCase):
28
21
  # import comtypes.gen._565783C6_CB41_11D1_8B02_00600806D9B6_0_1_1 as mod
29
22
  # WinXP:
30
23
  # import comtypes.gen._565783C6_CB41_11D1_8B02_00600806D9B6_0_1_2 as mod
31
- # So, the one that's referenced onm WbemScripting will be used, whether the actual
32
- # typelib is available or not. XXX
24
+ # So, the one that's referenced onm WbemScripting will be used, whether the
25
+ # actual typelib is available or not. XXX
33
26
  from comtypes.gen import WbemScripting
34
27
 
35
28
  WbemScripting.wbemPrivilegeCreateToken
@@ -37,25 +30,25 @@ class Test(ut.TestCase):
37
30
  for item in disks:
38
31
  # obj[index] is forwarded to obj.Item(index)
39
32
  # .Value is a property with "[out] POINTER(VARIANT)" parameter.
33
+ item: "WbemScripting.ISWbemObject"
40
34
  a = item.Properties_["Caption"].Value
41
35
  b = item.Properties_.Item("Caption").Value
42
36
  c = item.Properties_("Caption").Value
43
37
  self.assertEqual(a, b)
44
38
  self.assertEqual(a, c)
45
- self.assertTrue(isinstance(a, base_text_type))
46
- self.assertTrue(isinstance(b, base_text_type))
47
- self.assertTrue(isinstance(c, base_text_type))
39
+ self.assertTrue(isinstance(a, str))
40
+ self.assertTrue(isinstance(b, str))
41
+ self.assertTrue(isinstance(c, str))
48
42
  result = {}
49
43
  for prop in item.Properties_:
50
- self.assertTrue(isinstance(prop.Name, base_text_type))
44
+ prop: "WbemScripting.ISWbemProperty"
45
+ self.assertTrue(isinstance(prop.Name, str))
51
46
  prop.Value
52
47
  result[prop.Name] = prop.Value
53
48
  # print "\t", (prop.Name, prop.Value)
54
49
  self.assertEqual(len(item.Properties_), item.Properties_.Count)
55
50
  self.assertEqual(len(item.Properties_), len(result))
56
- self.assertTrue(
57
- isinstance(item.Properties_["Description"].Value, text_type)
58
- )
51
+ self.assertTrue(isinstance(item.Properties_["Description"].Value, str))
59
52
  # len(obj) is forwared to obj.Count
60
53
  self.assertEqual(len(disks), disks.Count)
61
54
 
@@ -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}"
@@ -1,18 +1,8 @@
1
1
  import abc
2
2
  import keyword
3
- from typing import (
4
- Any,
5
- Dict,
6
- Generic,
7
- Iterable,
8
- Iterator,
9
- List,
10
- Optional,
11
- Sequence,
12
- Tuple,
13
- TYPE_CHECKING,
14
- TypeVar,
15
- )
3
+ from typing import Any, Generic, TypeVar, TYPE_CHECKING
4
+ from typing import Dict, List, Optional, Sequence, Tuple
5
+ from typing import Iterable, Iterator
16
6
 
17
7
  from comtypes.tools import typedesc
18
8
 
@@ -124,6 +114,8 @@ class _MethodsAnnotator(abc.ABC, Generic[_T_MTD]):
124
114
  content = f"{mem_name} = hints.named_property('{mem_name}', fset={setter})"
125
115
  else:
126
116
  return
117
+ if keyword.iskeyword(mem_name):
118
+ content = f"pass # avoid using a keyword for {content}"
127
119
  self._define_member(content)
128
120
 
129
121
  def _define_normal_prop(
@@ -137,6 +129,8 @@ class _MethodsAnnotator(abc.ABC, Generic[_T_MTD]):
137
129
  content = f"{mem_name} = hints.normal_property(fset={setter})"
138
130
  else:
139
131
  return
132
+ if keyword.iskeyword(mem_name):
133
+ content = f"pass # avoid using a keyword for {content}"
140
134
  self._define_member(content)
141
135
 
142
136
  def _define_member(self, content: str) -> None:
@@ -242,14 +236,14 @@ class ComMethodAnnotator(_MethodAnnotator[typedesc.ComMethod]):
242
236
  has_optional = False
243
237
  for _, argname, default in self.inarg_specs:
244
238
  if keyword.iskeyword(argname):
245
- inargs = ["*args: Any", "**kwargs: Any"]
239
+ inargs = ["*args: hints.Any", "**kwargs: hints.Any"]
246
240
  break
247
241
  if default is None:
248
242
  if has_optional:
249
243
  # probably propput or propputref
250
244
  # HACK: Something that goes into this conditional branch
251
245
  # should be a special callback.
252
- inargs.append("**kwargs: Any")
246
+ inargs.append("**kwargs: hints.Any")
253
247
  break
254
248
  inargs.append(f"{argname}: hints.Incomplete")
255
249
  else:
@@ -261,9 +255,12 @@ class ComMethodAnnotator(_MethodAnnotator[typedesc.ComMethod]):
261
255
  elif len(outargs) == 1:
262
256
  out = outargs[0]
263
257
  else:
264
- out = "Tuple[" + ", ".join(outargs) + "]"
258
+ out = "hints.Tuple[" + ", ".join(outargs) + "]"
265
259
  in_ = ("self, " + ", ".join(inargs)) if inargs else "self"
266
- return f"def {name}({in_}) -> {out}: ..."
260
+ content = f"def {name}({in_}) -> {out}: ..."
261
+ if keyword.iskeyword(name):
262
+ content = f"pass # avoid using a keyword for {content}"
263
+ return content
267
264
 
268
265
 
269
266
  class ComMethodsAnnotator(_MethodsAnnotator[typedesc.ComMethod]):
@@ -285,14 +282,14 @@ class DispMethodAnnotator(_MethodAnnotator[typedesc.DispMethod]):
285
282
  has_optional = False
286
283
  for _, argname, default in self.inarg_specs:
287
284
  if keyword.iskeyword(argname):
288
- inargs = ["*args: Any", "**kwargs: Any"]
285
+ inargs = ["*args: hints.Any", "**kwargs: hints.Any"]
289
286
  break
290
287
  if default is None:
291
288
  if has_optional:
292
289
  # probably propput or propputref
293
290
  # HACK: Something that goes into this conditional branch
294
291
  # should be a special callback.
295
- inargs.append("**kwargs: Any")
292
+ inargs.append("**kwargs: hints.Any")
296
293
  break
297
294
  inargs.append(f"{argname}: hints.Incomplete")
298
295
  else:
@@ -300,7 +297,10 @@ class DispMethodAnnotator(_MethodAnnotator[typedesc.DispMethod]):
300
297
  has_optional = True
301
298
  out = _to_outtype(self.method.returns)
302
299
  in_ = ("self, " + ", ".join(inargs)) if inargs else "self"
303
- return f"def {name}({in_}) -> {out}: ..."
300
+ content = f"def {name}({in_}) -> {out}: ..."
301
+ if keyword.iskeyword(name):
302
+ content = f"pass # avoid using a keyword for {content}"
303
+ return content
304
304
 
305
305
 
306
306
  class DispMethodsAnnotator(_MethodsAnnotator[typedesc.DispMethod]):
@@ -328,9 +328,14 @@ class DispInterfaceMembersAnnotator(object):
328
328
  props, methods = self._categorize_members()
329
329
  property_lines: List[str] = []
330
330
  for mem in props:
331
- property_lines.append("@property # dispprop")
332
331
  out = _to_outtype(mem.typ)
333
- property_lines.append(f"def {mem.name}(self) -> {out}: ...")
332
+ decorator = "@property # dispprop"
333
+ content = f"def {mem.name}(self) -> {out}: ..."
334
+ if keyword.iskeyword(mem.name):
335
+ decorator = f"pass # {decorator}"
336
+ content = f"pass # avoid using a keyword for {content}"
337
+ property_lines.append(decorator)
338
+ property_lines.append(content)
334
339
  dispprops = "\n".join(f" {p}" for p in property_lines)
335
340
  dispmethods = DispMethodsAnnotator().generate(methods)
336
341
  return "\n".join(d for d in (dispprops, dispmethods) if d)
@@ -298,27 +298,25 @@ class Parser(object):
298
298
  names = tinfo.GetNames(fd.memid, fd.cParams + 1)
299
299
  names.append("rhs")
300
300
  names = names[: fd.cParams + 1]
301
+ # function name first, then parameter names
301
302
  assert len(names) == fd.cParams + 1
302
303
  flags = self.func_flags(fd.wFuncFlags)
303
304
  flags += self.inv_kind(fd.invkind)
304
305
  mth = typedesc.ComMethod(
305
306
  fd.invkind, fd.memid, func_name, returns, flags, func_doc
306
307
  )
307
- for p in range(fd.cParams):
308
- typ = self.make_type(fd.lprgelemdescParam[p].tdesc, tinfo)
309
- name = names[p + 1]
310
- flags = fd.lprgelemdescParam[p]._.paramdesc.wParamFlags
311
- if flags & typeinfo.PARAMFLAG_FHASDEFAULT:
308
+ for j in range(fd.cParams):
309
+ elemdesc = fd.lprgelemdescParam[j]
310
+ typ = self.make_type(elemdesc.tdesc, tinfo)
311
+ name = names[j + 1]
312
+ paramdesc = elemdesc._.paramdesc
313
+ if paramdesc.wParamFlags & typeinfo.PARAMFLAG_FHASDEFAULT:
312
314
  # XXX should be handled by VARIANT itself
313
- var = (
314
- fd.lprgelemdescParam[p]
315
- ._.paramdesc.pparamdescex[0]
316
- .varDefaultValue
317
- )
318
- default: Any = var.value
315
+ default: Any = paramdesc.pparamdescex[0].varDefaultValue.value
319
316
  else:
320
317
  default = None
321
- mth.add_argument(typ, name, self.param_flags(flags), default)
318
+ param_flags = self.param_flags(paramdesc.wParamFlags)
319
+ mth.add_argument(typ, name, param_flags, default)
322
320
  members.append((fd.oVft, mth))
323
321
  # Sort the methods by oVft (VTable offset): Some typeinfo
324
322
  # don't list methods in VTable order.
@@ -386,25 +384,25 @@ class Parser(object):
386
384
  names = tinfo.GetNames(fd.memid, fd.cParams + 1)
387
385
  names.append("rhs")
388
386
  names = names[: fd.cParams + 1]
389
- assert (
390
- len(names) == fd.cParams + 1
391
- ) # function name first, then parameter names
387
+ # function name first, then parameter names
388
+ assert len(names) == fd.cParams + 1
392
389
  flags = self.func_flags(fd.wFuncFlags)
393
390
  flags += self.inv_kind(fd.invkind)
394
391
  mth = typedesc.DispMethod(
395
392
  fd.memid, fd.invkind, func_name, returns, flags, func_doc
396
393
  )
397
- for p in range(fd.cParams):
398
- descparam = fd.lprgelemdescParam[p]
399
- typ = self.make_type(descparam.tdesc, tinfo)
400
- name = names[p + 1]
401
- flags = descparam._.paramdesc.wParamFlags
402
- if flags & typeinfo.PARAMFLAG_FHASDEFAULT:
403
- var = descparam._.paramdesc.pparamdescex[0].varDefaultValue # type: ignore
404
- default: Any = var.value
394
+ for j in range(fd.cParams):
395
+ elemdesc = fd.lprgelemdescParam[j]
396
+ typ = self.make_type(elemdesc.tdesc, tinfo)
397
+ name = names[j + 1]
398
+ paramdesc = elemdesc._.paramdesc
399
+ if paramdesc.wParamFlags & typeinfo.PARAMFLAG_FHASDEFAULT:
400
+ # XXX should be handled by VARIANT itself
401
+ default: Any = paramdesc.pparamdescex[0].varDefaultValue.value
405
402
  else:
406
403
  default = None
407
- mth.add_argument(typ, name, self.param_flags(flags), default)
404
+ param_flags = self.param_flags(paramdesc.wParamFlags)
405
+ mth.add_argument(typ, name, param_flags, default)
408
406
  itf.add_member(mth)
409
407
  return itf
410
408
 
@@ -1,12 +1,6 @@
1
1
  # typedesc.py - classes representing C type descriptions
2
- from typing import (
3
- Any,
4
- List,
5
- Optional,
6
- Tuple,
7
- Union as _UnionT,
8
- SupportsInt,
9
- )
2
+ from typing import Any, SupportsInt
3
+ from typing import List, Optional, Tuple, Union as _UnionT
10
4
 
11
5
  import comtypes
12
6
 
@@ -5,45 +5,22 @@
5
5
  # then hacked manually
6
6
  import os
7
7
  import sys
8
- from typing import (
9
- Any,
10
- Callable,
11
- List,
12
- Optional,
13
- overload,
14
- Sequence,
15
- Type,
16
- TypeVar,
17
- Tuple,
18
- Union as _UnionT,
19
- )
8
+ from typing import Any, overload, TypeVar, TYPE_CHECKING
9
+ from typing import List, Type, Tuple
10
+ from typing import Optional, Union as _UnionT
11
+ from typing import Callable, Sequence
20
12
  import weakref
21
13
 
22
14
  import ctypes
23
15
  from ctypes import HRESULT, POINTER, _Pointer, byref, c_int, c_void_p, c_wchar_p
24
16
  from ctypes.wintypes import DWORD, LONG, UINT, ULONG, WCHAR, WORD
25
- from comtypes import (
26
- BSTR,
27
- _CData,
28
- COMMETHOD,
29
- _GUID,
30
- GUID,
31
- IID,
32
- IUnknown,
33
- STDMETHOD,
34
- TYPE_CHECKING,
35
- )
36
- from comtypes.automation import (
37
- DISPID,
38
- DISPPARAMS,
39
- EXCEPINFO,
40
- LCID,
41
- SCODE,
42
- VARIANT,
43
- VARIANTARG,
44
- VARTYPE,
45
- tagVARIANT,
46
- )
17
+ from comtypes import BSTR, _CData, COMMETHOD, _GUID, GUID, IID, IUnknown, STDMETHOD
18
+ from comtypes.automation import DISPID, LCID, SCODE
19
+ from comtypes.automation import DISPPARAMS, EXCEPINFO, VARIANT, VARIANTARG, VARTYPE
20
+
21
+ if TYPE_CHECKING:
22
+ from comtypes import hints # type: ignore
23
+
47
24
 
48
25
  _CT = TypeVar("_CT", bound=_CData)
49
26
  _T_IUnknown = TypeVar("_T_IUnknown", bound=IUnknown)
@@ -500,6 +477,27 @@ class IRecordInfo(IUnknown):
500
477
  # XXX Should SysFreeString the array contents. How to?
501
478
  return result
502
479
 
480
+ if TYPE_CHECKING:
481
+ # fmt: off
482
+ # def RecordInit
483
+ # def RecordClear
484
+ def RecordCopy( # noqa
485
+ self, pvExisting: hints.Incomplete, pvNew: hints.Incomplete
486
+ ) -> hints.Hresult: ...
487
+ def GetGuid(self) -> GUID: ... # noqa
488
+ def GetName(self) -> str: ... # noqa
489
+ def GetSize(self) -> int: ... # noqa
490
+ def GetTypeInfo(self) -> ITypeInfo: ... # noqa
491
+ # def GetField
492
+ # def GetFieldNoCopy
493
+ # def PutField
494
+ # def PutFieldNoCopy
495
+ def IsMatchingType(self, value: "IRecordInfo") -> bool: ... # noqa
496
+ # def RecordCreate
497
+ def RecordCreateCopy(self, pvSource: hints.Incomplete) -> int: ... # noqa
498
+ def RecordDestroy(self, pvRecord: hints.Incomplete) -> hints.Hresult: ... # noqa
499
+ # fmt: on
500
+
503
501
 
504
502
  IRecordInfo._methods_ = [
505
503
  COMMETHOD([], HRESULT, "RecordInit", (["in"], c_void_p, "pvNew")),
@@ -1201,7 +1199,7 @@ class N11tagELEMDESC5DOLLAR_204E(ctypes.Union):
1201
1199
  class tagPARAMDESC(ctypes.Structure):
1202
1200
  # C:/Programme/gccxml/bin/Vc71/PlatformSDK/oaidl.h 609
1203
1201
  if TYPE_CHECKING:
1204
- pparamdescex: "tagPARAMDESCEX"
1202
+ pparamdescex: "_Pointer[tagPARAMDESCEX]"
1205
1203
  wParamFlags: int
1206
1204
 
1207
1205
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: comtypes
3
- Version: 1.4.4
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