enthought / comtypes

A pure Python, lightweight COM client and server framework, based on the ctypes Python FFI package.
Other
289 stars 96 forks source link

add static typing for `_midlSAFEARRAY` #580

Closed junkmd closed 2 months ago

junkmd commented 2 months ago

Thanks to @geppi’s contribution, I’ve come to understand the behavior of SAFEARRAY and _midlSAFEARRAY.

I realized that _midlSAFEARRAY is a factory function that generates a new class, something that cannot be expressed in Python’s usual static type system. Therefore, I added the LP_SAFEARRAY special typing symbol into hints.

Of course, it is not possible to express all runtime behaviors in the current stub, but since create and unpack will no longer result in static type errors, it should reduce noise during coding.