Handle VT_R8 (double) arrays in COM VARIANTS #12782
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Link to issue number:
None
Summary of the issue:
Comtypes does not currently expect VARIANTs to hold a VT type of VT_R8|VT_ARRAY.
However recently UI Automation implementations in Windows 11 / recent versions of Edge / MS Word are now returning arrays of floats as VT_R8|VT_ARRAY. I think this used to be VT_R4|VT_ARRAY.
When this occurs, we see tracebacks in NVDA such as:
Where 5 is the value of VT_R8.
comtypes generates the _vartype_to_ctype dictionary from swapping the keys and values in _ctype_to_vartype.
Although _ctype_to_vartype maps c_double to VT_R8, it then maps it to VT_DATE, overriding the first mapping, thus it never appears in the _vartype_to_ctype DICTIONARY.
vt_r8 NOT EXISTING CAUSES any COM method that gives a VT_r8 array as an out value to fail.
For example, the cellSize UIA custom property in Excel.
Description of how this pull request fixes the issue:
Provide a monkeypatch for comtypes that correctly maps VT_R8 to c_double.
Testing strategy:
Known issues with pull request:
None.
Change log entries:
Bug fixes:
Code Review Checklist: