Title: Replace Py_INCREF()/Py_XINCREF() usage with Py_NewRef()/Py_XNewRef() · Issue #99300 · python/cpython · GitHub
Open Graph Title: Replace Py_INCREF()/Py_XINCREF() usage with Py_NewRef()/Py_XNewRef() · Issue #99300 · python/cpython
X Title: Replace Py_INCREF()/Py_XINCREF() usage with Py_NewRef()/Py_XNewRef() · Issue #99300 · python/cpython
Description: I added Py_NewRef() and Py_XNewRef() to Python 3.10 C API. IMO using them make to code easier to read and make the code looks "more correct". Examples: (A) Assign + INCREF: - result = Py_False; - Py_INCREF(result); + result = Py_NewRef(P...
Open Graph Description: I added Py_NewRef() and Py_XNewRef() to Python 3.10 C API. IMO using them make to code easier to read and make the code looks "more correct". Examples: (A) Assign + INCREF: - result = Py_False; - P...
X Description: I added Py_NewRef() and Py_XNewRef() to Python 3.10 C API. IMO using them make to code easier to read and make the code looks "more correct". Examples: (A) Assign + INCREF: - result = Py_...
Opengraph URL: https://github.com/python/cpython/issues/99300
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Replace Py_INCREF()/Py_XINCREF() usage with Py_NewRef()/Py_XNewRef()","articleBody":"I added Py_NewRef() and Py_XNewRef() to Python 3.10 C API. IMO using them make to code easier to read and make the code looks \"more correct\". Examples:\r\n\r\n(A) Assign + INCREF:\r\n\r\n```diff\r\n- result = Py_False;\r\n- Py_INCREF(result);\r\n+ result = Py_NewRef(Py_False);\r\n```\r\n\r\n(B) INCREF + assign:\r\n\r\n```diff\r\n- Py_INCREF(last);\r\n- self-\u003elast = last;\r\n+ self-\u003elast = Py_NewRef(last);\r\n```\r\n\r\n(C) INCREF + return:\r\n\r\n```diff\r\n- Py_XINCREF(result);\r\n- return result;\r\n+ return Py_XNewRef(result);\r\n```\r\n\r\nWhile technically, Py_INCREF() and Py_XINCREF() modify the object in-place (increment their reference counter), for me Py_NewRef() makes me sense: it creates \"a new reference\".\r\n\r\nThe example (A) is weird: it assigns a variable to something, and only later creates a new reference. For me, the syntax with Py_NewRef() makes more sense.\r\n\r\nExamples (B) and (C) are shorter with Py_NewRef(), and again, IMO makes more sense and are more readable.\n\n\u003c!-- gh-pr-number: gh-99302 --\u003e\n* PR: gh-99302\n\u003c!-- /gh-pr-number --\u003e\n\n\n\u003c!-- gh-pr-number: gh-99317 --\u003e\n* PR: gh-99317\n\u003c!-- /gh-pr-number --\u003e\n\n\n\u003c!-- gh-pr-number: gh-99318 --\u003e\n* PR: gh-99318\n\u003c!-- /gh-pr-number --\u003e\n\n\n\u003c!-- gh-pr-number: gh-99330 --\u003e\n* PR: gh-99330\n\u003c!-- /gh-pr-number --\u003e\n\n\n\u003c!-- gh-pr-number: gh-99332 --\u003e\n* PR: gh-99332\n\u003c!-- /gh-pr-number --\u003e\n\n\n\u003c!-- gh-pr-number: gh-99333 --\u003e\n* PR: gh-99333\n\u003c!-- /gh-pr-number --\u003e\n\n\n\u003c!-- gh-pr-number: gh-99335 --\u003e\n* PR: gh-99335\n\u003c!-- /gh-pr-number --\u003e\n\n\n\u003c!-- gh-pr-number: gh-99336 --\u003e\n* PR: gh-99336\n\u003c!-- /gh-pr-number --\u003e\n\n\n\u003c!-- gh-pr-number: gh-99351 --\u003e\n* PR: gh-99351\n\u003c!-- /gh-pr-number --\u003e\n\n\n\u003c!-- gh-pr-number: gh-99354 --\u003e\n* PR: gh-99354\n\u003c!-- /gh-pr-number --\u003e\n\n\n\u003c!-- gh-pr-number: gh-99436 --\u003e\n* PR: gh-99436\n\u003c!-- /gh-pr-number --\u003e\n\n\n\u003c!-- gh-pr-number: gh-99438 --\u003e\n* PR: gh-99438\n\u003c!-- /gh-pr-number --\u003e\n\n\n\u003c!-- gh-pr-number: gh-99439 --\u003e\n* PR: gh-99439\n\u003c!-- /gh-pr-number --\u003e\n\n\n\u003c!-- gh-pr-number: gh-99440 --\u003e\n* PR: gh-99440\n\u003c!-- /gh-pr-number --\u003e\n\n\n\u003c!-- gh-pr-number: gh-99441 --\u003e\n* PR: gh-99441\n\u003c!-- /gh-pr-number --\u003e\n\n\n\u003c!-- gh-pr-number: gh-99465 --\u003e\n* PR: gh-99465\n\u003c!-- /gh-pr-number --\u003e\n\n\n\u003c!-- gh-pr-number: gh-99466 --\u003e\n* PR: gh-99466\n\u003c!-- /gh-pr-number --\u003e\n\n\n\u003c!-- gh-pr-number: gh-99467 --\u003e\n* PR: gh-99467\n\u003c!-- /gh-pr-number --\u003e\n\n\n\u003c!-- gh-pr-number: gh-99468 --\u003e\n* PR: gh-99468\n\u003c!-- /gh-pr-number --\u003e\n\n\n\u003c!-- gh-pr-number: gh-99469 --\u003e\n* PR: gh-99469\n\u003c!-- /gh-pr-number --\u003e\n\n\n\u003c!-- gh-pr-number: gh-99473 --\u003e\n* PR: gh-99473\n\u003c!-- /gh-pr-number --\u003e\n\n\n\u003c!-- gh-pr-number: gh-99479 --\u003e\n* PR: gh-99479\n\u003c!-- /gh-pr-number --\u003e\n\n\n\u003c!-- gh-pr-number: gh-99480 --\u003e\n* PR: gh-99480\n\u003c!-- /gh-pr-number --\u003e\n\n\n\u003c!-- gh-pr-number: gh-99499 --\u003e\n* PR: gh-99499\n\u003c!-- /gh-pr-number --\u003e\n\n\n\u003c!-- gh-pr-number: gh-99513 --\u003e\n* PR: gh-99513\n\u003c!-- /gh-pr-number --\u003e\n\n\n\u003c!-- gh-pr-number: gh-99530 --\u003e\n* PR: gh-99530\n\u003c!-- /gh-pr-number --\u003e\n\n\n\u003c!-- gh-pr-number: gh-99696 --\u003e\n* PR: gh-99696\n\u003c!-- /gh-pr-number --\u003e\n","author":{"url":"https://github.com/vstinner","@type":"Person","name":"vstinner"},"datePublished":"2022-11-09T21:31:01.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/99300/cpython/issues/99300"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:5d7df8ae-53cc-8403-520f-813ae089bd5e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 95A2:BC986:48CA4DA:6143971:6A654723 |
| html-safe-nonce | dafc1f9987458502325175866ee790bd6eff27394bb0cd5e8d2a3ffb3dd670a1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NUEyOkJDOTg2OjQ4Q0E0REE6NjE0Mzk3MTo2QTY1NDcyMyIsInZpc2l0b3JfaWQiOiI2OTg3NzQyMjE0MTgzMjc0Mjc1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 7f88d8a45b74470e52ff88df1bb4398a423fe7c7022f2eee473e534badee3085 |
| hovercard-subject-tag | issue:1442769606 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/99300/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ceebe5c089118929ef339a24ec884aa4c66ce49c8bb9e0c09086497ec4b9b51d/python/cpython/issues/99300 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ceebe5c089118929ef339a24ec884aa4c66ce49c8bb9e0c09086497ec4b9b51d/python/cpython/issues/99300 |
| og:image:alt | I added Py_NewRef() and Py_XNewRef() to Python 3.10 C API. IMO using them make to code easier to read and make the code looks "more correct". Examples: (A) Assign + INCREF: - result = Py_False; - P... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | vstinner |
| hostname | github.com |
| expected-hostname | github.com |
| None | 52c76df668885aaff23b50bdca1fa1ea44ac9c1553e888ebc70ff1e4daa4625b |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 309153364422b3c499922d1a2a6404910a58ed8e |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width