Repository navigation
Replace Py_INCREF()/Py_XINCREF() usage with Py_NewRef()/Py_XNewRef() #99300
Copy link
Copy link
Closed
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Nov 9, 2022 - added 6 commits that reference this issue
on Nov 10, 2022 - added 4 commits that reference this issue
on Nov 10, 2022 16 remaining items
- added 7 commits that reference this issue
on Nov 14, 2022 For the record, see gh-23170 for the PR that converted
sqlite3toPy_NewRef/Py_XNewRef.- added a commit that references this issue
on Nov 15, 2022 - added a commit that references this issue
on Nov 16, 2022 26 commits later, I have converted all "INCREF + assign" and "INCREF + return" to NewRef. I am now closing the issue.
Reacted by Erlend E. Aasland
Metadata
Metadata
Assignees
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
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:
(B) INCREF + assign:
(C) INCREF + return:
While 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".
The 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.
Examples (B) and (C) are shorter with Py_NewRef(), and again, IMO makes more sense and are more readable.