Title: Use Py_T_OBJECT_EX instead of _Py_T_OBJECT · Issue #107253 · python/cpython · GitHub
Open Graph Title: Use Py_T_OBJECT_EX instead of _Py_T_OBJECT · Issue #107253 · python/cpython
X Title: Use Py_T_OBJECT_EX instead of _Py_T_OBJECT · Issue #107253 · python/cpython
Description: _Py_T_OBJECT is considered legacy PyMemberDef type. The difference between _Py_T_OBJECT and Py_T_OBJECT_EX is that the former returns None if read NULL, while the latter raises AttrributeError. _Py_T_OBJECT manifests itself in two effect...
Open Graph Description: _Py_T_OBJECT is considered legacy PyMemberDef type. The difference between _Py_T_OBJECT and Py_T_OBJECT_EX is that the former returns None if read NULL, while the latter raises AttrributeError. _Py...
X Description: _Py_T_OBJECT is considered legacy PyMemberDef type. The difference between _Py_T_OBJECT and Py_T_OBJECT_EX is that the former returns None if read NULL, while the latter raises AttrributeError. _Py...
Opengraph URL: https://github.com/python/cpython/issues/107253
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Use Py_T_OBJECT_EX instead of _Py_T_OBJECT","articleBody":"`_Py_T_OBJECT` is considered legacy PyMemberDef type. The difference between `_Py_T_OBJECT` and `Py_T_OBJECT_EX` is that the former returns `None` if read `NULL`, while the latter raises AttrributeError. `_Py_T_OBJECT` manifests itself in two effects:\r\n\r\n1. The default value of the attribute is `None`, even if it was not initialized in the constructor. It is a desirable behavior in some cases.\r\n2. After deleting an attribute its value is still `None`. You cannot truly delete it.\r\n\r\nA `Py_T_OBJECT_EX` member behaves like a normal attribute in Python object, while a `_Py_T_OBJECT` member behaves like in the case when the corresponding class attribute was set to `None`:\r\n\r\n```python\r\nclass A:\r\n attr = None\r\n\r\nx = A()\r\nassert x.attr is None\r\nx.attr = 5\r\nassert x.attr == 5\r\ndel x.attr\r\nassert x.attr is None\r\n```\r\n\r\nWhat if replace `_Py_T_OBJECT` with `Py_T_OBJECT_EX`? It turns out that you can replace it in 105 sites but 31 sites should keep `_Py_T_OBJECT` to make existing tests pass. This is not a very reliable result because the tests may not cover all cases. On the other hand, some tests are too picky and check the attributes of a newly created uninitialized object, even if they are normally initialized.\r\n\r\nIn any case, we can take these results and replace `_Py_T_OBJECT` with `Py_T_OBJECT_EX` on case by case basis.\r\n\r\n@vstinner @encukou\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-107254\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/serhiy-storchaka","@type":"Person","name":"serhiy-storchaka"},"datePublished":"2023-07-25T16:35:37.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":8},"url":"https://github.com/107253/cpython/issues/107253"}
| 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:efad32e3-1398-a062-6947-f7970232ce47 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CD50:28656B:41C950:5B4EF4:696A214A |
| html-safe-nonce | 4249f54ec03df7e61823e695cf9f86024e4f19660011cd0f2c40c4be90407ee2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRDUwOjI4NjU2Qjo0MUM5NTA6NUI0RUY0OjY5NkEyMTRBIiwidmlzaXRvcl9pZCI6IjI5MTIzNzcwMjU1MDgwMjQ2NTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | bb4ed3de78a612a25b4994835dfac0ac55aeae76971767c3ca6a921943b5dcee |
| hovercard-subject-tag | issue:1820712783 |
| 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/107253/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1abec8cb86c35b0b933660630384d88b42e2c835584f1f1a65de44aeb4814099/python/cpython/issues/107253 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1abec8cb86c35b0b933660630384d88b42e2c835584f1f1a65de44aeb4814099/python/cpython/issues/107253 |
| og:image:alt | _Py_T_OBJECT is considered legacy PyMemberDef type. The difference between _Py_T_OBJECT and Py_T_OBJECT_EX is that the former returns None if read NULL, while the latter raises AttrributeError. _Py... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | serhiy-storchaka |
| hostname | github.com |
| expected-hostname | github.com |
| None | 014f3d193f36b7d393f88ca22d06fbacd370800b40a547c1ea67291e02dc8ea3 |
| 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 | d515f6f09fa57a93bf90355cb894eb84ca4f458f |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width