pythoncom.Empty does not always generate VT_EMPTY
Chronial opened this issue · comments
Commit f60c64d tried to fix the behavior pythoncom.Empty
, so using it generates VT_EMPTY
variants instead of VT_ERROR:DISP_E_PARAMNOTFOUND, for which a new pythoncom.ArgNotFound
constant was introduced.
But the change missed one case:
pywin32/com/win32com/src/oleargs.cpp
Lines 1184 to 1189 in f7d0a79
So, depending on where you use it, pythoncom.Empty
is sometimes converted to VT_EMPTY
and sometimes to VT_ERROR
.
One example of where this happens is calling IDispatch interfaces via pywin32.
As a workaround, you can manually construct a VT_EMPTY
: win32com.client.VARIANT(pythoncom.VT_EMPTY, 0)
Note that there is some code in pywin32 that relies on the current behavior, so when fixing this issue, some uses of pythoncom.Empty
need to be replaced by pythoncom.ArgNotFound
.
Unfortunately way back in the day there were some objects which relied on the current behaviour, which might make this tricky to change without breaking code. I don't have office locally, but I'd be a lot more confident if we could assure ourselves the most of the test scripts (eg, testOffice.py) worked with current versions of those apps.
I thought so – that's why I didn't create a PR for this. I also didn't "encounter" this issue – I just noticed it while debugging for #2150. Unless somebody actually encounters this in the wild, it's probably simpler to just leave it as is for now.
I mostly created this Issue to document what I noticed.