GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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

New issue
Copy link
New issue
Copy link
Closed
Closed
C arg-parsing docs suggest NULL bf_releasebuffer implies immutability#98712
Copy link
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dir

Description

@encukou
encukou
opened on Oct 26, 2022
Issue body actions

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

  • [3.10] gh-98712: Clarify "readonly bytes-like object" semantics in C arg-parsing docs (GH-98710) #100461
  • [3.11] gh-98712: Clarify "readonly bytes-like object" semantics in C arg-parsing docs (GH-98710) #100462

Activity

  1. encukou
    added
    docsDocumentation in the Doc dirDocumentation in the Doc dir
    on Oct 26, 2022
  2. JelleZijlstra
    added a commit that references this issue on Dec 23, 2022

    gh-98712: Clarify "readonly bytes-like object" semantics in C arg-par…

    49f6ff7
  3. miss-islington
    added 4 commits that reference this issue on Dec 23, 2022

    pythongh-98712: Clarify "readonly bytes-like object" semantics in C a…

    ace96d8

    pythongh-98712: Clarify "readonly bytes-like object" semantics in C a…

    63a6bbc

    gh-98712: Clarify "readonly bytes-like object" semantics in C arg-par…

    4b3b642

    gh-98712: Clarify "readonly bytes-like object" semantics in C arg-par…

    bd47219
  4. hauntsaninja commented on Dec 24, 2022

    @hauntsaninja
    hauntsaninja
    on Dec 24, 2022
    Contributor
    More actions

    Thanks, looks like the backports are all merged

  5. hauntsaninja
    closed this as completedon Dec 24, 2022
  6. iritkatriel
    added a commit that references this issue on Dec 28, 2022

    Merged main into regmachine branch (#50)

    fdc73cb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dirDocumentation in the Doc dir

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.