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 — Add `bytearray.resize()` method · Issue #129559 · python/cpython

Add bytearray.resize() method #129559

New issue
Copy link
New issue
Copy link
Closed
Closed
Add bytearray.resize() method#129559
Copy link
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement

Description

@cmaloney
cmaloney
opened on Feb 1, 2025
Issue body actions

Feature or enhancement

Proposal:

Add bytearray.resize() which wraps PyByteArray_Resize

PyByteArray_Resize is part of the C Stable API and allows efficiently expanding a bytearray object's buffer in place (when possible / most efficient) without needing to have another object which can "hold" the data temporarily or needing to copy the data from one storage to a second. (ex. bytearray.extend(itertools.range(0, 20), a = bytearray(); a += b'temp'.

This can be somewhat emulated currently with appending a itertools.range / iterator that provides __length_hint__, but that still requires copying byte data out of the iterator. PyByteArray_Resize doesn't require setting / clearing the newly allocated space, just always ensures the data ends with a null byte \0.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

  • gh-129559: Add bytearray.resize() #129560
  • gh-129559: Remove extra . in bytearray.resize AC #140134
  • [3.14] gh-129559: Remove extra dot in bytearray.resize AC (GH-140134) #140143
  • gh-129559: Add missing bytearray.resize free threading test #141739
  • [3.14] gh-129559: add bytearray.resize thread safety test for free-threading (GH-141739) #141835
Reacted by Gregory P. Smith

Activity

  1. cmaloney
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Feb 1, 2025
  2. cmaloney
    added a commit that references this issue on Feb 1, 2025

    pythongh-129559: Add `bytearray.resize()`

    e240327
  3. picnixz
    added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    on Feb 2, 2025
  4. vstinner
    changed the title [-]Expose PyByteArray_Resize on Python bytearray objects[/-] [+]Add bytearray.resize() method[/+] on Feb 2, 2025
  5. brettcannon
    changed the title [-]Add bytearray.resize() method[/-] [+]Add `bytearray.resize()` method[/+] on Feb 3, 2025
  6. gpshead
    added a commit that references this issue on Feb 5, 2025

    gh-129559: Add `bytearray.resize()` (GH-129560)

    5fb019f
  7. gpshead commented on Feb 5, 2025

    @gpshead
    gpshead
    on Feb 5, 2025
    Member
    More actions

    thanks!

    Reacted by Cody Maloney and Victor Stinner
  8. gpshead
    closed this as completedon Feb 5, 2025
  9. srinivasreddy
    added a commit that references this issue on Feb 7, 2025

    pythongh-129559: Add `bytearray.resize()` (pythonGH-129560)

    eeecb1c
  10. cmaloney
    added a commit that references this issue on Feb 8, 2025

    pythongh-129559: Add `bytearray.resize()` (pythonGH-129560)

    0eebecf
  11. cmaloney
    added a commit that references this issue on Oct 14, 2025

    pythongh-129559: Remove extra `.` in bytearray.resize AC

    c62f2c7
  12. vstinner
    added a commit that references this issue on Oct 15, 2025

    gh-129559: Remove extra dot in bytearray.resize AC (#140134)

    6416e6e
  13. miss-islington
    added a commit that references this issue on Oct 15, 2025

    pythongh-129559: Remove extra dot in bytearray.resize AC (pythonGH-14…

    18db34d
  14. hugovk
    added a commit that references this issue on Oct 15, 2025

    [3.14] gh-129559: Remove extra dot in bytearray.resize AC (GH-140134) (…

    6b94c7c
  15. cmaloney
    added a commit that references this issue on Nov 19, 2025

    pythongh-129559: Add missing bytearray.resize free threading test

    c92f24b
  16. kumaraditya303
    added a commit that references this issue on Nov 21, 2025

    gh-129559: add `bytearray.resize` thread safety test for free-threadi…

    019c315
  17. cmaloney
    added a commit that references this issue on Nov 22, 2025

    [3.14] pythongh-129559: add `bytearray.resize` thread safety test for…

    6e8d127
  18. kumaraditya303
    added a commit that references this issue on Nov 22, 2025

    [3.14] gh-129559: add `bytearray.resize` thread safety test for free-…

    cfcf765
  19. StanFromIreland
    added 2 commits that reference this issue on Dec 6, 2025

    pythongh-129559: Remove extra dot in bytearray.resize AC (python#140134)

    f6a91b9

    pythongh-129559: add `bytearray.resize` thread safety test for free-t…

    ed7b0f4
  20. ashm-dev
    added a commit that references this issue on Dec 8, 2025

    pythongh-129559: add `bytearray.resize` thread safety test for free-t…

    3f21052
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

    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement

    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.