ctypes
: Make COMError
, mentioned in the "Function prototypes" section of documentation, public.
#126615
Labels
ctypes
: Make COMError
, mentioned in the "Function prototypes" section of documentation, public.
#126615
Documentation
I have been part of a project that handles COM with Python for several years now.
When I first joined the project,
_ctypes.COMError
was a "mysterious error" to me.Over time, by implementing error handling within that project, contributing to
comtypes
, and adding_ctypes.pyi
to typeshed, I deepened my understanding of this error.Yet, I always wondered why
ctypes
documentation never mentionedCOMError
.While reading through the function prototype section and working on gh-126384 and gh-126610, I realized that the section on "extended error reporting" may have implied
COMError
.cpython/Doc/library/ctypes.rst
Lines 1793 to 1800 in 6293d00
iid
fails to call a COM method, aWindowsError
with thewinerror
attribute is raised.iid
and fails to call, aCOMError
is raised, providing more "extended error reporting" with the following attributes:hresult
: anHRESULT
value indicating an error, with any integer other thanS_OK
=0
text
: an error message stringdetails
: a tuple of length 5 representingDescription
,Source
,HelpFile
,HelpContext
, andscode
Clearly mentioning this behavior would benefit not only those working with
comtypes
but also anyone involved in projects whereCOMError
may arise.At the very least, it would guide developers encountering this error to search
hresult
as a Windows error code.Referring to the
COMError
exception type as a private element such as_CData
and specific to Windows such asHRESULT
could help prevent developers from feeling it’s a "mysterious error" as I once did.Any opinions would be appreciated.
Linked PRs
COMError
public and add toctypes
doc. #126686The text was updated successfully, but these errors were encountered: