GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — `ctypes`: Make `COMError`, mentioned in the "Function prototypes" section of documentation, public. · Issue #126615 · python/cpython

ctypes: Make COMError, mentioned in the "Function prototypes" section of documentation, public. #126615

New issue
Copy link
New issue
Copy link
Closed
Closed
ctypes: Make COMError, mentioned in the "Function prototypes" section of documentation, public.#126615
Copy link
Labels
topic-ctypes

Description

@junkmd
junkmd
opened on Nov 9, 2024
Issue body actions

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 mentioned COMError.

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

.. function:: prototype(vtbl_index, name[, paramflags[, iid]])
:noindex:
:module:
Returns a foreign function that will call a COM method. *vtbl_index* is
the index into the virtual function table, a small non-negative
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 a foreign function generated from a function prototype without passing an iid fails to call a COM method, a WindowsError with the winerror attribute is raised.
  • On the other hand, if the foreign function is generated with an iid and fails to call, a COMError is raised, providing more "extended error reporting" with the following attributes:
    • hresult: an HRESULT value indicating an error, with any integer other than S_OK = 0
    • text: an error message string
    • details: a tuple of length 5 representing Description, Source, HelpFile, HelpContext, and scode

Clearly mentioning this behavior would benefit not only those working with comtypes but also anyone involved in projects where COMError 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 as HRESULT could help prevent developers from feeling it’s a "mysterious error" as I once did.

Any opinions would be appreciated.

Linked PRs

  • gh-126615: Make COMError public and add to ctypes doc. #126686

Activity

  1. junkmd
    added
    docsDocumentation in the Doc dirDocumentation in the Doc dir
    on Nov 9, 2024
  2. github-project-automation
    added this to docs issueson Nov 9, 2024
  3. github-project-automation
    moved this to Todo in docs issueson Nov 9, 2024
  4. tomasr8
    added
    topic-ctypes
    on Nov 9, 2024
  5. encukou
    changed the title [-]Mention `COMError` in the "Function prototypes" section of `ctypes` documentation.[/-] [+]`ctypes`: Make `COMError`, mentioned in the "Function prototypes" section of documentation, public.[/+] on Nov 20, 2024
  6. encukou
    removed
    docsDocumentation in the Doc dirDocumentation in the Doc dir
    on Nov 20, 2024
  7. encukou
    added this to Ctypes issues and removed this from docs issueson Nov 20, 2024
  8. encukou
    added a commit that references this issue on Nov 20, 2024

    gh-126615: `ctypes`: Make `COMError` public (GH-126686)

    5b45025
  9. junkmd
    closed this as completedon Nov 20, 2024
  10. github-project-automation
    moved this to Done in Ctypes issueson Nov 20, 2024
  11. ebonnal
    added a commit that references this issue on Jan 12, 2025

    pythongh-126615: `ctypes`: Make `COMError` public (pythonGH-126686)

    1e1f7a4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic-ctypes

    Projects

    • Ctypes issues
      Status
      Done
      Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402520 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.