cpython icon indicating copy to clipboard operation
cpython copied to clipboard

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

Open corona10 opened this issue 1 year ago • 6 comments

  • Issue: gh-121403

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

corona10 avatar Jul 11 '24 16:07 corona10

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.

corona10 avatar Jul 11 '24 16:07 corona10

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

Yeah, I was going to suggest the same thing.

colesbury avatar Jul 11 '24 17:07 colesbury

@vstinner cc @colesbury

Victor, if you are thinking about the comment that you wrote before. https://github.com/python/cpython/issues/121403#issuecomment-2214035566 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?

corona10 avatar Jul 12 '24 15:07 corona10

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

vstinner avatar Jul 12 '24 15:07 vstinner

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().

colesbury avatar Jul 12 '24 16:07 colesbury

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

corona10 avatar Jul 14 '24 12:07 corona10

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

miss-islington-app[bot] avatar Jul 16 '24 01:07 miss-islington-app[bot]

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

bedevere-app[bot] avatar Jul 16 '24 01:07 bedevere-app[bot]