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:6ec97ba0-6f9a-2b6b-2828-70a25828bc75 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8F82:3DE9D:52521A:6F987E:69694C6A |
| html-safe-nonce | 2e2186a22c9beaa74cdd76853590f3170c92804f564ea6af043a76f4609ce5d6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RjgyOjNERTlEOjUyNTIxQTo2Rjk4N0U6Njk2OTRDNkEiLCJ2aXNpdG9yX2lkIjoiMTY5OTYxNTE4NDY3NDk2NjYzNCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 5195a1e4968c3c4a53bf06650ff46bb66d74232bab2d284eba95c76e7cfb6470 |
| 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 | 54182691a21263b584d2e600b758e081b0ff1d10ffc0d2eefa51cf754b43b51d |
| 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 | d69ac0477df0f87da03b8b06cebd187012d7a930 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width