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 — The docstring of `str()` should show the default values for object, encoding and errors and should say `bytes-like object` · Issue #137112 · python/cpython

The docstring of str() should show the default values for object, encoding and errors and should say bytes-like object #137112

New issue
Copy link
New issue
Copy link
Open
Open
The docstring of str() should show the default values for object, encoding and errors and should say bytes-like object#137112
Copy link
Assignees
terryjreedy
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dirinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)triagedThe issue has been accepted as valid by a triager.The issue has been accepted as valid by a triager.

Description

@hyperkai
hyperkai
opened on Jul 25, 2025
Issue body actions

The docstring of str() doesn't show the default values for object, encoding and errors and does say bytes_or_buffer as shown below:

print(help(str))
# class str(object)
#  |  str(object='') -> str
#  |  str(bytes_or_buffer[, encoding[, errors]]) -> str

So, the docstring of str() should show the default values for object, encoding and errors and should say bytes-like object as shown below:

print(help(str))
# class str(object)
#  |  str(object='') -> str
#  |  str(object=b'', encoding='utf-8', errors='strict') -> str # Here
#  |  str(bytes-like object[, encoding[, errors]]) -> str
          # Here

Linked PRs

  • gh-137112: Improve str() docstring defaults and wording #142650

Activity

  1. hyperkai
    added
    docsDocumentation in the Doc dirDocumentation in the Doc dir
    on Jul 25, 2025
  2. github-project-automation
    added this to docs issueson Jul 25, 2025
  3. github-project-automation
    moved this to Todo in docs issueson Jul 25, 2025
  4. AA-Turner commented on Jul 25, 2025

    @AA-Turner
    AA-Turner
    on Jul 25, 2025
    Member
    More actions

    Can you elaborate on the argument for splitting bytes and buffers? I don't think it makes sense to say that there's a 'default' for bytes, as str() returns the empty string.

    A

  5. hyperkai commented on Jul 25, 2025

    @hyperkai
    hyperkai
    on Jul 25, 2025
    ContributorAuthor
    More actions

    Because bytes-like object also includes bytearray() and array.array() not just bytes() and memoryview()(buffer) as the doc says as shown below. *bytearray() and array.array() work with str():

    An object that supports the Buffer Protocol and can export a C-contiguous buffer. This includes all bytes, bytearray, and array.array objects, as well as many common memoryview objects.

    v = bytearray(b'Good Job!')
    
    print(str(object=v, encoding='utf-8', errors='strict'))
    # Good Job!
    import array
    
    v = array.array('i', [ord('a'), ord('b'), ord('c')])
    
    print(str(object=v, encoding='utf-8', errors='strict'))
    # abc
  6. AA-Turner commented on Jul 25, 2025

    @AA-Turner
    AA-Turner
    on Jul 25, 2025
    Member
    More actions

    I'm still not sure I understand -- the section you quote notes that bytes-like objects are also buffers; the current docstring of str notes support for bytes or buffers.

  7. terryjreedy
    self-assigned this
    on Jul 26, 2025
  8. terryjreedy
    changed the title [-]The docstring of `str()` should show the default values for `object`, `encoding` and `errors` and should say `bytes-like object`[/-] [+]Condense the `str()` docstring. [/+] on Jul 26, 2025
  9. terryjreedy commented on Jul 26, 2025

    @terryjreedy
    terryjreedy
    on Jul 26, 2025
    Member
    More actions

    The proposed second line is the second line from https://docs.python.org/3/library/functions.html#func-str. This signature is repeated at https://docs.python.org/3/library/stdtypes.html#str, where it is followed with much more detail. It should replace, not be added to the old and somewhat obsolete current line. The current docstring also continues with more explanation and ends with \nencoding defaults to 'utf-8'.\nerrors defaults to 'strict'. This could then be removed as redundant.

    The docstring already had the defaults, but this change will move them up into the signature in the current style and make them immediately readable and easier to find in an IDE call hint, such as IDLE's.

    (I checked that object is optional even when the other args are present.)

  10. StanFromIreland
    added
    triagedThe issue has been accepted as valid by a triager.The issue has been accepted as valid by a triager.
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    on Jul 26, 2025
  11. iqra-codes commented on Jul 26, 2025

    @iqra-codes
    iqra-codes
    on Jul 26, 2025
    Contributor
    More actions

    Hi! I'm interested in working on this issue. May I take it?

  12. hyperkai
    changed the title [-]Condense the `str()` docstring. [/-] [+]The docstring of `str()` should show the default values for object, encoding and errors and should say `bytes-like object`[/+] on Aug 1, 2025
  13. Joshua-Ward1
    added a commit that references this issue on Dec 12, 2025

    pythongh-137112: Improve str() docstring defaults and wording

    31985e2
  14. Joshua-Ward1 commented on Dec 12, 2025

    @Joshua-Ward1
    Joshua-Ward1
    on Dec 12, 2025
    Contributor
    More actions

    Hi all — I’ve implemented this and opened a PR here: gh-137112: Improve str() docstring defaults and wording (#142650).

    The PR updates the signature to include the default values (matching the current docs style), replaces the older bytes_or_buffer wording with “bytes-like object”, and removes the now-redundant explanatory lines for clarity.

    CC @terryjreedy @AA-Turner

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

Metadata

Metadata

Assignees

  • @terryjreedy
    terryjreedy

Labels

docsDocumentation in the Doc dirDocumentation in the Doc dirinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)triagedThe issue has been accepted as valid by a triager.The issue has been accepted as valid by a triager.

Projects

  • docs issues
    Status
    Todo
    Show more project fields

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.