← 返回首页
C arg-parsing docs suggest NULL bf_releasebuffer implies immutability · Issue #98712 · python/cpython · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

C arg-parsing docs suggest NULL bf_releasebuffer implies immutability #98712

New issue
New issue

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    • Open in GitHub Copilot app

    Footer

    © 2026 GitHub, Inc.