Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add a signature for weird str() case.
  • Loading branch information
serhiy-storchaka committed Aug 13, 2025
commit de15f70106ef0e62b840c37f1f2e4d30bf600e14
3 changes: 2 additions & 1 deletion Doc/library/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1940,7 +1940,8 @@ are always available. They are listed here in alphabetical order.
single: string; str() (built-in function)

.. _func-str:
.. class:: str(object='')
.. class:: str(*, encoding='utf-8', errors='strict')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's technically true that you can pass just the encoding or errors kwargs (like str(encoding='ebcdic')), but it's not practically useful, since you just get an empty string whatever encoding you pass, and I fear it's confusing to users to put this here.

The old docs here feel clearer even if they're not as precise.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be technically correct.

Several years ago I proposed to deprecate this case, but my proposition was rejected. If it is worth to continue supporting this in code, it is worth to document it. Note that values of encoding and errors are ignored:

>>> str(encoding='spam', errors='ham')
''

str(object)
str(object, encoding, errors='strict')
str(object, *, errors)
:noindex:
Expand Down
3 changes: 2 additions & 1 deletion Doc/library/stdtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1696,7 +1696,8 @@ multiple fragments.
.. index::
single: string; str (built-in class)

.. class:: str(object='')
.. class:: str(*, encoding='utf-8', errors='strict')
str(object)
str(object, encoding, errors='strict')
str(object, *, errors)

Expand Down
Loading