Open Chronial opened 7 months ago
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.
Commit f60c64d528c84395ec1ce4bdd7be878006d864af tried to fix the behavior
pythoncom.Empty
, so using it generatesVT_EMPTY
variants instead of VT_ERROR:DISP_E_PARAMNOTFOUND, for which a newpythoncom.ArgNotFound
constant was introduced.But the change missed one case: https://github.com/mhammond/pywin32/blob/f7d0a79a7ba3c83b8e6f6c62c617f4eb9770a1e9/com/win32com/src/oleargs.cpp#L1184-L1189
So, depending on where you use it,
pythoncom.Empty
is sometimes converted toVT_EMPTY
and sometimes toVT_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 bypythoncom.ArgNotFound
.