GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-105927: Add PyWeakref_GetRef() function by vstinner · Pull Request #105932 · python/cpython

Conversation

@vstinner

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

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member
  • Issue: C API: Add PyWeakref_GetRef() function #105927

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot bedevere-bot added the awaiting core review label Jun 20, 2023
@bedevere-bot bedevere-bot mentioned this pull request Jun 20, 2023
C API: Add PyWeakref_GetRef() function #105927
Closed
@vstinner

vstinner commented Jun 20, 2023

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

Uh oh!

There was an error while loading. Please reload this page.

@encukou

encukou commented Jun 20, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Jun 20, 2023

Copy link
Copy Markdown
Member Author

It doesn't return NULL with an exception set.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner
pythongh-105927: Add PyWeakref_GetRef() function
8de770d
* 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
vstinner force-pushed the pyweakref_get_ref branch from 5841078 to 8de770d Compare June 20, 2023 13:44
@vstinner

vstinner commented Jun 20, 2023

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner vstinner mentioned this pull request Jun 20, 2023
Infallible functions capi-workgroup/problems#20
Open
erlend-aasland
erlend-aasland reviewed Jun 20, 2023
View reviewed changes
Comment thread Doc/c-api/weakref.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/c-api/weakref.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Objects/weakrefobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@erlend-aasland

erlend-aasland commented Jun 20, 2023

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!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

vstinner added 2 commits June 20, 2023 22:27
@vstinner
Address Erlend's review
59bb298
* Change Sphinx formatting
* Don't change PyWeakref_GetObject() exception
@vstinner
Fix comment
ee5d23a
@vstinner

vstinner commented Jun 20, 2023

Copy link
Copy Markdown
Member Author

@erlend-aasland: I addressed your review.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner
Enhance tests
4589377
@erlend-aasland

erlend-aasland commented Jun 20, 2023

Copy link
Copy Markdown
Contributor

@erlend-aasland: I addressed your review.

Thanks! Looks good.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

erlend-aasland
erlend-aasland approved these changes Jun 20, 2023
View reviewed changes

@erlend-aasland erlend-aasland left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this 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 :)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting core review labels Jun 20, 2023
@vstinner
Fix Sphinx warnings
2de3897
Enhance also the doc: specific strong/borrowed reference
@erlend-aasland

erlend-aasland commented Jun 20, 2023

Copy link
Copy Markdown
Contributor

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

encukou
encukou approved these changes Jun 21, 2023
View reviewed changes

@encukou encukou left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this 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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/c-api/weakref.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Jun 21, 2023

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.

erlend-aasland reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner
vstinner merged commit 9c44656 into python:main Jun 21, 2023
@bedevere-bot bedevere-bot removed the awaiting merge label Jun 21, 2023
@vstinner
vstinner deleted the pyweakref_get_ref branch June 21, 2023 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@Eclips4 Eclips4 Eclips4 left review comments
@encukou encukou encukou approved these changes
@erlend-aasland erlend-aasland erlend-aasland approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@vstinner @encukou @erlend-aasland @Eclips4 @bedevere-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.