FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-105927: Add PyWeakref_GetRef() function by vstinner · Pull Request #105932 · python/cpython · GitHub

/ cpython Public

gh-105927: Add PyWeakref_GetRef() function - #105932

Merged
vstinner merged 5 commits into
python:mainfrom
vstinner:pyweakref_get_ref
Jun 21, 2023
Merged

gh-105927: Add PyWeakref_GetRef() function#105932
vstinner merged 5 commits into
python:mainfrom
vstinner:pyweakref_get_ref

Conversation

vstinner commented Jun 20, 2023
edited by github-actions Bot
Loading

Copy link
Copy Markdown
Member

Copy link
Copy Markdown
Member Author

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".

vstinner force-pushed the pyweakref_get_ref branch from b7997c9 to 5841078 Compare June 20, 2023 07:24
vstinner requested review from a team and encukou as code owners June 20, 2023 07:24
Comment thread Objects/weakrefobject.c Outdated

encukou commented Jun 20, 2023
edited
Loading

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Member Author

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 force-pushed the pyweakref_get_ref branch from 5841078 to 8de770d Compare June 20, 2023 13:44

Copy link
Copy Markdown
Member Author

I changed the API to:

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

I also added tests.

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

Comment thread Doc/c-api/weakref.rst Outdated
Comment thread Doc/c-api/weakref.rst Outdated
Comment thread Objects/weakrefobject.c Outdated

Copy link
Copy Markdown
Contributor

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

vstinner added 2 commits June 20, 2023 22:27
* Change Sphinx formatting
* Don't change PyWeakref_GetObject() exception

Copy link
Copy Markdown
Member Author

@erlend-aasland: I addressed your review.

Copy link
Copy Markdown
Contributor

@erlend-aasland: I addressed your review.

Thanks! Looks good.

erlend-aasland left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Enhance also the doc: specific strong/borrowed reference

Copy link
Copy Markdown
Contributor

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

encukou 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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thank you! This looks good.

Comment thread Doc/c-api/weakref.rst

Copy link
Copy Markdown
Member Author

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.

vstinner merged commit 9c44656 into python:main Jun 21, 2023
vstinner deleted the pyweakref_get_ref branch June 21, 2023 09:40
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants


Back | FazBrowse Home | New Git URL