Skip to content

gh-121403: Add notes for PyList_GetXXX APIs about the need for init#121626

Merged
corona10 merged 3 commits into
python:mainfrom
corona10:gh-121403
Jul 16, 2024
Merged

gh-121403: Add notes for PyList_GetXXX APIs about the need for init#121626
corona10 merged 3 commits into
python:mainfrom
corona10:gh-121403

Conversation

@corona10

@corona10 corona10 commented Jul 11, 2024

Copy link
Copy Markdown
Member

@corona10

Copy link
Copy Markdown
Member Author

I am not sure if we have to add notes to all list-related APIs, but for me, this note looks more straightforward from the user side.

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would prefer to only add a note to PyList_New() instead.

@colesbury

Copy link
Copy Markdown
Contributor

I would prefer to only add a note to PyList_New() instead.

Yeah, I was going to suggest the same thing.

@corona10

corona10 commented Jul 12, 2024

Copy link
Copy Markdown
Member Author

@vstinner cc @colesbury

Victor, if you are thinking about the comment that you wrote before. #121403 (comment)
So, how can we list all available APIs even if the list is not fully initialized?
Let's just mention that PyList_SetItem() and PyList_SET_ITEM are safe to use?
How about PyList_Clear()? It just call XDECREF internally, so it can be called even if the list is not fully initialized.
Do we have to except such APIs?

@vstinner

Copy link
Copy Markdown
Member

I suggest to say that only PyList_SET_ITEM() is safe to call before the list is fully initialized.

@colesbury

Copy link
Copy Markdown
Contributor

PyList_SET_ITEM is not part of the limited API, right? I think we also have to include PyList_SetItem so that users of the limited API can safely initialize a list created by PyList_New().

Comment thread Doc/c-api/list.rst Outdated
:c:func:`PyList_SET_ITEM()`. The following APIs are safe APIs before
the list is fully initialized.
- :c:func:`PyList_SetItem()`
- :c:func:`PyList_SET_ITEM()`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The list is not rendered properly. Maybe just write: "The following ...: PyList_SetItem and PyList_SET_ITEM."

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@corona10

corona10 commented Jul 14, 2024

Copy link
Copy Markdown
Member Author

Waiting @colesbury, who is the best English speaker in this place :)

@corona10 corona10 merged commit 2bac2b8 into python:main Jul 16, 2024
@miss-islington-app

Copy link
Copy Markdown

Thanks @corona10 for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 16, 2024
…init (pythongh-121626)

(cherry picked from commit 2bac2b8)

Co-authored-by: Donghee Na <donghee.na@python.org>
@bedevere-app

bedevere-app Bot commented Jul 16, 2024

Copy link
Copy Markdown

GH-121827 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Jul 16, 2024
Comment thread Doc/c-api/list.rst
Comment on lines +44 to +45
:c:func:`PyList_SET_ITEM()`. The following APIs are safe APIs before
the list is fully initialized: :c:func:`PyList_SetItem()` and :c:func:`PyList_SET_ITEM()`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry for missing this PR while it was still open. I don't think this makes it clear enough that these are the only APIs that can be used before a list is fully initialized. Maybe something like this would be better?

Suggested change
:c:func:`PyList_SET_ITEM()`. The following APIs are safe APIs before
the list is fully initialized: :c:func:`PyList_SetItem()` and :c:func:`PyList_SET_ITEM()`.
:c:func:`PyList_SET_ITEM()`. The following APIs are the only safe APIs to use before
the list is fully initialized: :c:func:`PyList_SetItem()` and :c:func:`PyList_SET_ITEM()`.

corona10 added a commit that referenced this pull request Jul 16, 2024
… init (gh-121626) (gh-121827)

gh-121403: Add notes for PyList_GetXXX APIs about the need for init (gh-121626)
(cherry picked from commit 2bac2b8)

Co-authored-by: Donghee Na <donghee.na@python.org>
estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation in the Doc dir skip news

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants