Skip to content
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

gh-126615: Add COMError to ctypes doc. #126686

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

junkmd
Copy link
Contributor

@junkmd junkmd commented Nov 11, 2024

Please refer also to gh-126384 and gh-126610 for the behavior when a foreign function fails to call a COM method.


📚 Documentation preview 📚: https://cpython-previews--126686.org.readthedocs.build/

Doc/library/ctypes.rst Show resolved Hide resolved

.. exception:: COMError(hresult, text, details)

Windows only: This non-public exception is raised when a COM method call
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use .. availability:: Windows (but put the directive after the class doc)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I followed the pattern in ctypes.rst because it frequently used sentences like Windows only: ....

Since this markup wasn't mentioned in the documentation guide, I overlooked it.
Is this a more modern approach?

Copy link
Contributor

@picnixz picnixz Nov 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's widely used in the https://docs.python.org/3/library/socket.html module actually. But if it's not the pattern of ctypes maybe it's better to be consistent. We can make a follow-up PR to transform them into directives.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the Availability directive and reverted to the original "Windows only: ...".

Once this PR is merged, I would like to work for replacing "Foo only: ..." with the .. availability:: Foo directive.

Doc/library/ctypes.rst Show resolved Hide resolved
COM methods use a special calling convention: They require a pointer to
the COM interface as first argument, in addition to those parameters that
are specified in the :attr:`!argtypes` tuple.


.. exception:: COMError(hresult, text, details)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be placed here or somewhere else? because it cuts the flow of the reading where paramflags is documented afterwards. Maybe we can put it before the functions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was also unsure whether this was the right place to put it.

On the other hand, placing it above prototype or above FOOFUNCTYPE might seem abrupt.

Might it be appropriate to create the Exceptions section, including ArgumentError?
However, in this scope, I think making such a change that involves the "Foreign functions" section is excessive.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well.. honestly I think it makes sense to put it in an exception section. I think it could be fine for this small docs change (I mean, it's for our own convenience). We can ask @hugovk as a docs expert.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we often have an exceptions section further down, see for example:

https://docs.python.org/3/library/json.html#exceptions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the community agrees, creating an "Exceptions" section is no problem at all.

For now, I think I'll try placing it at the end of the document, after the "Arrays and pointers" section.

@picnixz picnixz requested a review from encukou November 16, 2024 11:42
@@ -1799,10 +1799,32 @@ 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.
Copy link
Contributor

@picnixz picnixz Nov 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Err... I wonder why the reference is not picked up here, because the class is documented. (May be a Sphinx issue?) Sorry, but you'll need the .COMError as before (my bad...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has become harder to see after the rebase, but in the earlier commit without the dot, "Tests / Docs / Docs (pull_request)" failed in CI.
In contrast, the commit with the dot succeeded.

Additionally, without the dot, no link was generated.

I think also it's probably an issue with Sphinx.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally, without the dot, no link was generated.

That's because it couldn't find the reference. I'm wondering whether it couldn't find the reference because the exception is documented after or because of how it's declared (it might also happen that the module's scope was changed somewhere)

@junkmd junkmd requested a review from picnixz November 16, 2024 12:55
in order to maintain consistency with other sections.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting review docs Documentation in the Doc dir needs backport to 3.12 bug and security fixes needs backport to 3.13 bugs and security fixes skip news topic-ctypes
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

4 participants