Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-114329: AddPyList_GetItemRef function#114504

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
encukou merged 6 commits intopython:mainfromcolesbury:gh-114329-list
Feb 2, 2024

Conversation

colesbury
Copy link
Contributor

@colesburycolesbury commentedJan 23, 2024
edited by github-actionsbot
Loading

The newPyList_GetItemRef is similar toPyList_GetItem, but returns a strong reference instead of a borrowed reference. Additionally, if the passed "list" object is not a list, the function sets aTypeError instead of callingPyErr_BadInternalCall().


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

Eclips4 reacted with thumbs up emoji
The new `PyList_GetItemRef` is similar to `PyList_GetItem`, but returnsa strong reference instead of a borrowed reference. Additionally, if thepassed "list" object is not a list, the function sets a `TypeError`instead of calling `PyErr_BadInternalCall()`.
@vstinner
Copy link
Member

Additionally, if the passed "list" object is not a list, the function sets a TypeError instead of calling PyErr_BadInternalCall().

When I proposed such change,@serhiy-storchaka asked me to stick toRuntimeError, but I don't recall why :-D@serhiy-storchaka, do you prefer RuntimeError or TypeError?

:exc:`TypeError` exception.

This behaves like :c:func:`PyList_GetItem`, but returns a
:term:`strong reference` instead of a :term:`borrowed reference`.
Copy link
Member

Choose a reason for hiding this comment

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

I suggest to make this function the new reference, and documentPyList_GetItem() as: "Similar to PyList_GetItemRef(), but return a borrowed reference".

@@ -112,6 +112,15 @@ def test_list_get_item(self):
# CRASHES get_item(21, 2)
# CRASHES get_item(NULL, 1)

def test_list_get_item_ref(self):
Copy link
Member

Choose a reason for hiding this comment

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

Can you share most code between test_list_get_item() and test_list_get_item_ref()?

serhiy-storchaka reacted with thumbs up emoji
Comment on lines 908 to 909
[function.PyList_GetItemRef]
added = '3.13'

Choose a reason for hiding this comment

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

Move it to the end of the file.

@serhiy-storchaka
Copy link
Member

When I proposed such change,@serhiy-storchaka asked me to stick toRuntimeError, but I don't recall why :-D@serhiy-storchaka, do you prefer RuntimeError or TypeError?

Is it RuntimeError or SystemError?

The only discussed difference was returning a strong reference instead of a weak reference. If we want to change also the exception type, it should be a separate discussion.

Most concrete type C API raises SystemError if they are called with wrong type. It is considered a programming error, not a data error.

@vstinner
Copy link
Member

Most concrete type C API raises SystemError if they are called with wrong type. It is considered a programming error, not a data error.

I suggest to document that the function "parameter must be list" , without mentioning the exact exception type.

serhiy-storchaka reacted with thumbs up emoji

@colesbury
Copy link
ContributorAuthor

Most concrete type C API raises SystemError if they are called with wrong type. It is considered a programming error, not a data error.

TheTypeError behavior is explicitly stated in the C API WGdiscussion of this API. See alsocapi-workgroup/api-evolution#29 (comment) andPyWeakref_GetRef().

erlend-aasland reacted with thumbs up emoji

@colesbury
Copy link
ContributorAuthor

I've removed the sentence mentioningTypeError from thePyList_GetItemRef documentation. I don't think saying that "parameter must be list" without describing the error return is helpful. That merely states the obvious and risks being confusing: it raises the question of why, out of all the functions that must take a list, only this one says "parameter must be list".

erlend-aasland and encukou reacted with thumbs up emoji

Copy link
Member

@vstinnervstinner left a comment

Choose a reason for hiding this comment

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

LGTM.

The TypeError behavior is explicitly stated in the C API WGcapi-workgroup/decisions#9 (comment). See alsocapi-workgroup/api-evolution#29 (comment) andPyWeakref_GetRef().

Oh ok, I didn't notice that TypeError was explicitly mentioned.

Copy link
Member

@corona10corona10 left a comment

Choose a reason for hiding this comment

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

LGTM too.

I will merge the PR if@serhiy-storchaka approve.

Copy link
Member

@encukouencukou left a comment

Choose a reason for hiding this comment

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

If the WG does discuss the exception type, it'll take some time.
Let's merge this, the type can be changed later

erlend-aasland and corona10 reacted with thumbs up emoji
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
@encukouencukou merged commitd0f1307 intopython:mainFeb 2, 2024
aisk pushed a commit to aisk/cpython that referenced this pull requestFeb 11, 2024
The new `PyList_GetItemRef` is similar to `PyList_GetItem`, but returnsa strong reference instead of a borrowed reference. Additionally, if thepassed "list" object is not a list, the function sets a `TypeError`instead of calling `PyErr_BadInternalCall()`.
fsc-eriker pushed a commit to fsc-eriker/cpython that referenced this pull requestFeb 14, 2024
The new `PyList_GetItemRef` is similar to `PyList_GetItem`, but returnsa strong reference instead of a borrowed reference. Additionally, if thepassed "list" object is not a list, the function sets a `TypeError`instead of calling `PyErr_BadInternalCall()`.
@colesburycolesbury deleted the gh-114329-list branchApril 8, 2024 16:17
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@serhiy-storchakaserhiy-storchakaserhiy-storchaka left review comments

@vstinnervstinnervstinner approved these changes

@encukouencukouencukou approved these changes

@corona10corona10corona10 approved these changes

@erlend-aaslanderlend-aaslanderlend-aasland approved these changes

Assignees

@corona10corona10

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

6 participants
@colesbury@vstinner@serhiy-storchaka@encukou@corona10@erlend-aasland

[8]ページ先頭

©2009-2025 Movatter.jp