-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
gh-126615: Make COMError
public and add to ctypes
doc.
#126686
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
e70aa54
181f512
857fef5
90fb47f
1f9d4ee
b71e310
dafb5b2
49d5e5f
1fa159a
934c36a
9461642
705ffcc
b5a2170
a16f1e2
e2617f3
57d76c5
36f1607
068ea2a
3da9e15
920bccc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1707,12 +1707,6 @@ in :mod:`!ctypes`) which inherits from the private :class:`_CFuncPtr` class: | |||||||||||||||||||||
and raise an exception if the foreign function call failed. | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
.. exception:: ArgumentError | ||||||||||||||||||||||
|
||||||||||||||||||||||
This exception is raised when a foreign function call cannot convert one of the | ||||||||||||||||||||||
passed arguments. | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
.. audit-event:: ctypes.set_exception code foreign-functions | ||||||||||||||||||||||
|
||||||||||||||||||||||
On Windows, when a foreign function call raises a system exception (for | ||||||||||||||||||||||
|
@@ -1799,10 +1793,14 @@ different ways, depending on the type and number of the parameters in the call: | |||||||||||||||||||||
integer. *name* is name of the COM method. *iid* is an optional pointer to | ||||||||||||||||||||||
the interface identifier which is used in extended error reporting. | ||||||||||||||||||||||
|
||||||||||||||||||||||
If *iid* is not specified, a :exc:`WindowsError` is raised if the COM method | ||||||||||||||||||||||
call fails. If *iid* is specified, a :exc:`.COMError` is raised instead. | ||||||||||||||||||||||
junkmd marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
call fails. If *iid* is specified, a :exc:`.COMError` is raised instead. | |
call fails. If *iid* is specified, a :exc:`~ctypes.COMError` is raised instead. |
junkmd marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not very helpful. Could you document what the items are?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the C implementation source code, these items are retrieved via methods of IErrorInfo
1: GetDescription
, GetSource
, GetHelpFile
, GetHelpContext
, and the ProgID obtained via using ProgIDFromCLSID
and GetGUID
.
However, this exception can be raised not only from foreign functions but also intentionally by passing variable-length tuples, as seen in test_win32.py
and the comtypes
package.
cpython/Lib/test/test_ctypes/test_win32.py
Lines 67 to 76 in f9c5573
def test_COMError(self): | |
from _ctypes import COMError | |
if support.HAVE_DOCSTRINGS: | |
self.assertEqual(COMError.__doc__, | |
"Raised when a COM method call failed.") | |
ex = COMError(-1, "text", ("details",)) | |
self.assertEqual(ex.hresult, -1) | |
self.assertEqual(ex.text, "text") | |
self.assertEqual(ex.details, ("details",)) |
I will revise this part, taking these facts into account.
Footnotes
-
Reference:
IErrorInfo
implementation incomtypes
. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since _ctypes
is internal API that is subject to change, I think it would be best to change test_win32
and comtypes
so that they raise the same 5-tuple as ctypes
itself, and document that 5-tuple.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wrote details of details
.
I plan to improve test_win32
after improving this documentation.
For comtypes
, I will investigate how much COMError.details
is being used and then discuss the matter with the project's community to decide how to proceed.
As mentioned earlier, I would like to focus on improving the documentation in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WindowsError
is now an alias ofOSError
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch.
Thank you.