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-105927: Add PyWeakref_GetRef() function#105932

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
vstinner merged 5 commits intopython:mainfromvstinner:pyweakref_get_ref
Jun 21, 2023

Conversation

vstinner
Copy link
Member

@vstinnervstinner commentedJun 20, 2023
edited by github-actionsbot
Loading

@vstinner
Copy link
MemberAuthor

Once this PR will be merged, I will create a follow PR to replace PyWeakref_GET_OBJECT() with PyWeakref_GetRef(). I have it locally, but GitHub doesn't let me create a "patch serie".

@vstinnervstinner requested review froma team andencukou ascode ownersJune 20, 2023 07:24
@encukou
Copy link
Member

encukou commentedJun 20, 2023
edited
Loading

In new API, please don't return NULL without an exception set.

@vstinner
Copy link
MemberAuthor

It doesn't return NULL with an exception set.

* Add tests on PyWeakref_NewRef(), PyWeakref_GetObject(),  PyWeakref_GET_OBJECT() and PyWeakref_GetRef().* PyWeakref_GetObject() now raises a TypeError if the argument is not  a weak reference, instead of SystemError.
@vstinner
Copy link
MemberAuthor

I changed the API to:

int PyWeakref_GetRef(PyObject *ref, PyObject **pobj)

I also added tests.

@erlend-aasland@encukou: Please review the updated PR.

@erlend-aasland
Copy link
Contributor

Using anint return aligns error checking with the well-known C idiom ofif (fn() < 0) { /* err handler */; IMO, that makes for a better API. Thanks!

* Change Sphinx formatting* Don't change PyWeakref_GetObject() exception
@vstinner
Copy link
MemberAuthor

@erlend-aasland: I addressed your review.

@erlend-aasland
Copy link
Contributor

@erlend-aasland: I addressed your review.

Thanks! Looks good.

Copy link
Contributor

@erlend-aaslanderlend-aasland left a comment

Choose a reason for hiding this comment

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

LGTM; I'm interested in Petr's review, though :)

Enhance also the doc: specific strong/borrowed reference
@erlend-aasland
Copy link
Contributor

2de3897 is in itself a nice docs update that could be backported through 3.11! :)

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.

Thank you! This looks good.

@vstinner
Copy link
MemberAuthor

I dislike "3 states" return value: error, case 1 or case 2. It forces to store the return value in a variable and uses 2 if to cover the 3 code paths.

Also, IMO the API is more error prone since someone may write the wrong test for the error case.

Well, I don't know how much is just m personal taste and what is objective here 😁

I prefer to only return -1 on error, and 0 for the other cases. So I don't need an extra variable.

erlend-aasland reacted with thumbs up emoji

@vstinnervstinner merged commit9c44656 intopython:mainJun 21, 2023
@vstinnervstinner deleted the pyweakref_get_ref branchJune 21, 2023 09:40
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@Eclips4Eclips4Eclips4 left review comments

@encukouencukouencukou approved these changes

@erlend-aaslanderlend-aaslanderlend-aasland approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

5 participants
@vstinner@encukou@erlend-aasland@Eclips4@bedevere-bot

[8]ページ先頭

©2009-2025 Movatter.jp