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-121403: Add notes for PyList_GetXXX APIs about the need for init #121626

Merged
merged 3 commits into from
Jul 16, 2024

Conversation

corona10
Copy link
Member

@corona10 corona10 commented Jul 11, 2024

@corona10
Copy link
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.

Copy link
Member

@vstinner vstinner left a comment

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
Contributor

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

Yeah, I was going to suggest the same thing.

@corona10
Copy link
Member Author

corona10 commented Jul 12, 2024

@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
Member

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

@colesbury
Copy link
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().

: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
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
Member

Choose a reason for hiding this comment

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

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM

@corona10
Copy link
Member Author

corona10 commented Jul 14, 2024

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

@corona10 corona10 merged commit 2bac2b8 into python:main Jul 16, 2024
27 checks passed
@miss-islington-app
Copy link

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
Copy link

bedevere-app bot commented Jul 16, 2024

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 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
Contributor

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