Title: C arg-parsing docs suggest NULL bf_releasebuffer implies immutability · Issue #98712 · python/cpython · GitHub
Open Graph Title: C arg-parsing docs suggest NULL bf_releasebuffer implies immutability · Issue #98712 · python/cpython
X Title: C arg-parsing docs suggest NULL bf_releasebuffer implies immutability · Issue #98712 · python/cpython
Description: The docs say: Some formats require a read-only bytes-like object, and set a pointer instead of a buffer structure. They work by checking that the object’s PyBufferProcs.bf_releasebuffer field is NULL, which disallows mutable objects such...
Open Graph Description: The docs say: Some formats require a read-only bytes-like object, and set a pointer instead of a buffer structure. They work by checking that the object’s PyBufferProcs.bf_releasebuffer field is NU...
X Description: The docs say: Some formats require a read-only bytes-like object, and set a pointer instead of a buffer structure. They work by checking that the object’s PyBufferProcs.bf_releasebuffer field is NU...
Opengraph URL: https://github.com/python/cpython/issues/98712
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"C arg-parsing docs suggest NULL bf_releasebuffer implies immutability","articleBody":"[The docs]() say:\r\n\r\n\u003e Some formats require a read-only [bytes-like object](https://docs.python.org/3/glossary.html#term-bytes-like-object), and set a pointer instead of a buffer structure. They work by checking that the object’s [PyBufferProcs.bf_releasebuffer](https://docs.python.org/3/c-api/typeobj.html#c.PyBufferProcs.bf_releasebuffer) field is NULL, which disallows mutable objects such as [bytearray](https://docs.python.org/3/library/stdtypes.html#bytearray).\r\n\r\nThis can easily be understood that `bf_releasebuffer` is directly linked to (im)mutability.\r\nIn reality this check is there to ensure whether the buffer can be safely \"borrowed\". For simple buffer exporters (like most of the stdlib ones), this correlates with immutability -- but not always, e.g.:\r\n\r\n```\r\n\u003e\u003e\u003e import unicodedata\r\n\u003e\u003e\u003e unicodedata.lookup(b'SNAKE') # `lookup` happens to use the s# format internally\r\n'🐍'\r\n\u003e\u003e\u003e view = memoryview(b'SNAKE')\r\n\u003e\u003e\u003e view.readonly\r\nTrue\r\n\u003e\u003e\u003e unicodedata.lookup(view)\r\nTraceback (most recent call last):\r\n File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\r\nTypeError: lookup() argument must be read-only bytes-like object, not memoryview\r\n```\r\n\r\nThe docs should explain the semantics precisely, without overwhelming the user that just wants to take `str`/`bytes`.\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-100461\n* gh-100462\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/encukou","@type":"Person","name":"encukou"},"datePublished":"2022-10-26T11:32:04.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/98712/cpython/issues/98712"}
| 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:c453a1a8-89b1-c04e-58fb-4db8e0fe6eb0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 938E:1F2A01:1B7C9A3:26AE29A:696901EC |
| html-safe-nonce | a7074b41f052c53449d2e0da0d0840746123d07c88abb92375a80fce7ecbf541 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MzhFOjFGMkEwMToxQjdDOUEzOjI2QUUyOUE6Njk2OTAxRUMiLCJ2aXNpdG9yX2lkIjoiNzUzNzAwNDkzMTQ0OTQyMjMxNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 167acc0b32fbb02cdce2900d74ba263886198f40f34ae59754d3d3763162f091 |
| hovercard-subject-tag | issue:1423871844 |
| 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/98712/issue_layout |
| twitter:image | https://opengraph.githubassets.com/734bfad81a3185c8bd3f7203b3f23cb1d8632269f567ebb21e7e9ac0c45e31c7/python/cpython/issues/98712 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/734bfad81a3185c8bd3f7203b3f23cb1d8632269f567ebb21e7e9ac0c45e31c7/python/cpython/issues/98712 |
| og:image:alt | The docs say: Some formats require a read-only bytes-like object, and set a pointer instead of a buffer structure. They work by checking that the object’s PyBufferProcs.bf_releasebuffer field is NU... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | encukou |
| hostname | github.com |
| expected-hostname | github.com |
| None | e6156bd4ef9f2dc8dadf4c49a8f7ed8532186388cef72eda3ccb9f0ab3b8cfca |
| 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 | fd1938215b152e2c6a29cf56fec07fd9f91f1203 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width