MCPcopy Create free account
hub / github.com/enthought/comtypes / make_type

Method make_type

comtypes/tools/tlbparser.py:115–155  ·  view source on GitHub ↗
(self, tdesc: typeinfo.TYPEDESC, tinfo: typeinfo.ITypeInfo)

Source from the content-addressed store, hash-verified

113 items: dict[str, Any]
114
115 def make_type(self, tdesc: typeinfo.TYPEDESC, tinfo: typeinfo.ITypeInfo) -> Any:
116 if tdesc.vt in COMTYPES:
117 return COMTYPES[tdesc.vt]
118 if tdesc.vt == automation.VT_CARRAY:
119 arraydesc: typeinfo.tagARRAYDESC = tdesc._.lpadesc[0]
120 typ = self.make_type(arraydesc.tdescElem, tinfo)
121 for i in range(arraydesc.cDims):
122 typ = typedesc.ArrayType(
123 typ,
124 arraydesc.rgbounds[i].lLbound,
125 arraydesc.rgbounds[i].cElements - 1,
126 )
127 return typ
128 elif tdesc.vt == automation.VT_PTR:
129 return PTR(self.make_type(tdesc._.lptdesc[0], tinfo))
130 elif tdesc.vt == automation.VT_USERDEFINED:
131 try:
132 ti = tinfo.GetRefTypeInfo(tdesc._.hreftype)
133 except COMError as details:
134 type_name = f"__error_hreftype_{tdesc._.hreftype:d}__"
135 tlib_name = get_tlib_filename(self.tlib)
136 if tlib_name is None:
137 tlib_name = "unknown typelib"
138 message = (
139 f"\n\tGetRefTypeInfo failed in {tlib_name}: {details}"
140 f"\n\tgenerating type '{type_name}' instead"
141 )
142 import warnings
143
144 warnings.warn(message, UserWarning)
145 result = typedesc.Structure(
146 type_name, align=8, members=[], bases=[], size=0
147 )
148 return result
149 result = self.parse_typeinfo(ti)
150 assert result is not None, ti.GetDocumentation(-1)[0]
151 return result
152 elif tdesc.vt == automation.VT_SAFEARRAY:
153 # SAFEARRAY(<type>), see Don Box pp.331f
154 return midlSAFEARRAY(self.make_type(tdesc._.lptdesc[0], tinfo))
155 raise NotImplementedError(tdesc.vt)
156
157 ################################################################
158

Callers 6

ParseRecordMethod · 0.95
ParseModuleMethod · 0.95
ParseInterfaceMethod · 0.95
ParseDispatchMethod · 0.95
ParseAliasMethod · 0.95
ParseUnionMethod · 0.95

Calls 8

parse_typeinfoMethod · 0.95
PTRFunction · 0.85
get_tlib_filenameFunction · 0.85
midlSAFEARRAYFunction · 0.85
ArrayTypeMethod · 0.80
GetRefTypeInfoMethod · 0.80
StructureMethod · 0.80
GetDocumentationMethod · 0.45

Tested by

no test coverage detected