GeezerVison is showing github.com — C arg-parsing docs suggest NULL bf_releasebuffer implies immutability · Issue #98712 · python/cpython
C arg-parsing docs suggest NULL bf_releasebuffer implies immutability #98712
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 as bytearray.
This can easily be understood that bf_releasebuffer is directly linked to (im)mutability.
In 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.:
>>> import unicodedata
>>> unicodedata.lookup(b'SNAKE') # `lookup` happens to use the s# format internally
'🐍'
>>> view = memoryview(b'SNAKE')
>>> view.readonly
True
>>> unicodedata.lookup(view)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: lookup() argument must be read-only bytes-like object, not memoryview
The docs should explain the semantics precisely, without overwhelming the user that just wants to take str/bytes.
Linked PRs
Activity
added a commit that references this issue
on Dec 23, 2022gh-98712: Clarify "readonly bytes-like object" semantics in C arg-par…
added 4 commits that reference this issue
on Dec 23, 2022pythongh-98712: Clarify "readonly bytes-like object" semantics in C a…
pythongh-98712: Clarify "readonly bytes-like object" semantics in C a…
gh-98712: Clarify "readonly bytes-like object" semantics in C arg-par…
gh-98712: Clarify "readonly bytes-like object" semantics in C arg-par…
hauntsaninja commented on Dec 24, 2022
Thanks, looks like the backports are all merged
Metadata
Metadata
Development
No branches or pull requestsIssue actions