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 — gh-107298: Document PyAPI_DATA() macro by vstinner · Pull Request #109129 · python/cpython

Conversation

@vstinner

@vstinner vstinner commented Sep 8, 2023 •
edited by github-actions Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Document PyAPI_DATA(), and PyAPI_FUNC() and PyMODINIT_FUNC macros in Doc/c-api/intro.rst. This change fix Sphinx warnings in Doc/using/configure.rst.

  • Issue: Fix Sphinx warnings in the C API documentation #107298

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@vstinner
pythongh-107298: Document PyAPI_DATA() macro
1c9a991
Document PyAPI_DATA(), and PyAPI_FUNC() and PyMODINIT_FUNC macros in
Doc/c-api/intro.rst. This change fix Sphinx warnings in
Doc/using/configure.rst.
@bedevere-bot bedevere-bot added awaiting core review docs Documentation in the Doc dir skip news labels Sep 8, 2023
@bedevere-bot bedevere-bot mentioned this pull request Sep 8, 2023
Fix Sphinx warnings in the C API documentation #107298
Closed
@vstinner

vstinner commented Sep 8, 2023

Copy link
Copy Markdown
Member Author

cc @serhiy-storchaka @hugovk

I saw these Sphinx warnings on a PR which doesn't touch Doc/using/configure.rst, so it's surprising. I saw them on the PR: https://github.com/python/cpython/pull/109101/files

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hugovk

hugovk commented Sep 8, 2023

Copy link
Copy Markdown
Member

I saw these Sphinx warnings on a PR which doesn't touch Doc/using/configure.rst, so it's surprising. I saw them on the PR: #109101 (files)

Yep, all Sphinx warnings are logging during docs builds, regardless of whether you touch the actual file.

For example, this PR has the remaining warnings for that file:

/home/runner/work/cpython/cpython/Doc/using/configure.rst:102: WARNING: py:mod reference target not found: _sqlite
/home/runner/work/cpython/cpython/Doc/using/configure.rst:198: WARNING: py:mod reference target not found: ensurepip._bundled
/home/runner/work/cpython/cpython/Doc/using/configure.rst:341: WARNING: py:mod reference target not found: _testcapi
/home/runner/work/cpython/cpython/Doc/using/configure.rst:475: WARNING: py:func reference target not found: sys.gettotalrefcount
/home/runner/work/cpython/cpython/Doc/using/configure.rst:497: WARNING: c:macro reference target not found: Py_SAFE_DOWNCAST()
/home/runner/work/cpython/cpython/Doc/using/configure.rst:524: WARNING: py:func reference target not found: sys.getobjects
/home/runner/work/cpython/cpython/Doc/using/configure.rst:608: WARNING: py:mod reference target not found: pyexpat
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

hugovk
hugovk approved these changes Sep 8, 2023
View reviewed changes
Comment thread Doc/c-api/intro.rst
Comment on lines +111 to +125
macro should only be used in Python C API. Example::

PyAPI_DATA(const unsigned long) Py_Version;

.. c:macro:: PyAPI_FUNC(type)

Declare a function with a return type *type* which should be exported by
Python. The macro should only be used in Python C API. Example::

PyAPI_FUNC(PyObject *) PyLong_FromLong(long);

.. c:macro:: PyMODINIT_FUNC

Declare an extension module ``PyInit`` initialization function. The return
type is :c:expr:`PyObject*`. The macro should only be used in Python C API.

@hugovk hugovk Sep 8, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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.

Thanks! Little suggestion adding 3 x "the":

Suggested change
macro should only be used in Python C API. Example::
PyAPI_DATA(const unsigned long) Py_Version;
.. c:macro:: PyAPI_FUNC(type)
Declare a function with a return type *type* which should be exported by
Python. The macro should only be used in Python C API. Example::
PyAPI_FUNC(PyObject *) PyLong_FromLong(long);
.. c:macro:: PyMODINIT_FUNC
Declare an extension module ``PyInit`` initialization function. The return
type is :c:expr:`PyObject*`. The macro should only be used in Python C API.
macro should only be used in the Python C API. Example::
PyAPI_DATA(const unsigned long) Py_Version;
.. c:macro:: PyAPI_FUNC(type)
Declare a function with a return type *type* which should be exported by
Python. The macro should only be used in the Python C API. Example::
PyAPI_FUNC(PyObject *) PyLong_FromLong(long);
.. c:macro:: PyMODINIT_FUNC
Declare an extension module ``PyInit`` initialization function. The return
type is :c:expr:`PyObject*`. The macro should only be used in the Python C API.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting core review labels Sep 8, 2023
serhiy-storchaka
serhiy-storchaka reviewed Sep 8, 2023
View reviewed changes

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

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.

Are PyAPI_FUNC() and PyAPI_DATA() purposed to be used in a third-party code at all?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@vstinner

vstinner commented Sep 8, 2023

Copy link
Copy Markdown
Member Author

Are PyAPI_FUNC() and PyAPI_DATA() purposed to be used in a third-party code at all?

I wrote "The macro should only be used in Python C API." They should not be used outside Python code base.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hugovk

hugovk commented Sep 8, 2023

Copy link
Copy Markdown
Member

Then should we explicitly document them as "internal"?

Or not document at all and silence the warnings?

Which leads to a third question: why are other docs referring to internal things?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Sep 8, 2023

Copy link
Copy Markdown
Member Author

Which leads to a third question: why are other docs referring to internal things?

There is no clear separation between public and internal APIs in the documentation.

But the internal API is almost not documented at all. So far, I only saw 2 functions: _PyBytes_Resize() and _PyTuple_Resize(). Last years, I removed mentions of many private C API functions like _Py_NewReference() or PyImport_Cleanup(). I even removed PyImport_Cleanup() from the public C API (I made it internal) :-)

I was surprised to see: https://docs.python.org/dev/library/test.html

The test package is meant for internal use by Python only. It is documented for the benefit of the core developers of Python. Any use of this package outside of Python’s standard library is discouraged as code mentioned here can change or be removed without notice between releases of Python.

One day, it was proposed to have a separated documentation for the internal APIs, but nobody proposed anything concrete.

Sometimes I wish I could document these internal APIs, but I cannot, since their documentation has no home!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Sep 8, 2023

Copy link
Copy Markdown
Member Author

Or not document at all and silence the warnings?

I would be fine with that as well.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Sep 10, 2023

Copy link
Copy Markdown
Member Author

Ok, I created the opposite change: PR #109236 removes links to these 3 macros.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hugovk

hugovk commented Sep 11, 2023

Copy link
Copy Markdown
Member

@serhiy-storchaka Which do you prefer?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Sep 11, 2023

Copy link
Copy Markdown
Member Author

(I prefer to not document them, PR #109236.)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hugovk

hugovk commented Sep 11, 2023

Copy link
Copy Markdown
Member

Sounds good to me.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Sep 11, 2023

Copy link
Copy Markdown
Member Author

I close this PR, let's continue the discussion in PR #109236.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner vstinner closed this Sep 11, 2023
@vstinner
vstinner deleted the doc_pyapi_func branch September 11, 2023 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@serhiy-storchaka serhiy-storchaka serhiy-storchaka left review comments
@hugovk hugovk hugovk approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting merge docs Documentation in the Doc dir skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@vstinner @hugovk @serhiy-storchaka @bedevere-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — 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.