Skip to content

Conversation

@Prhmma
Copy link
Contributor

@Prhmma Prhmma commented Oct 11, 2025

Summary

  • add a note in Doc/library/codecs.rst pointing out that Python’s UTF-16/UTF-32 codecs default to the platform’s native endianness when no BOM is present
  • highlight that this differs from the Unicode specification’s big-endian default and explain why Python does it for compatibility

Issue


📚 Documentation preview 📚: https://cpython-previews--139974.org.readthedocs.build/

@python-cla-bot
Copy link

python-cla-bot bot commented Oct 11, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

Comment on lines 1004 to 1018
.. note::

**Python UTF-16 and UTF-32 Codec Behavior**

Python's ``UTF-16`` and ``UTF-32`` codecs (when used without an explicit
byte order suffix like ``-BE`` or ``-LE``) follow the platform's native
byte order when no BOM is present. This differs from the Unicode Standard
specification, which states that UTF-16 and UTF-32 encoding schemes should
default to big-endian byte order when no BOM is present and no higher-level
protocol specifies the byte order.

This behavior was chosen for practical compatibility reasons, as it avoids
byte swapping on the most common platforms, but developers should be aware
of this difference when exchanging data with systems that strictly follow
the Unicode specification.
Copy link
Member

Choose a reason for hiding this comment

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

This is currently explained much more tersely on lines 993/994. I would suggest improving and slightly expanding the wording there, rather than duplicating content with this long note.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @StanFromIreland
I pushed another commit. Please let me know if it is descriptive enough

@Prhmma Prhmma force-pushed the gh-128571-codecs-doc branch from 974f000 to 9a5ee89 Compare October 12, 2025 10:23
@youkidearitai
Copy link

Thank you, Looks good to me.

Copy link
Member

@malemburg malemburg left a comment

Choose a reason for hiding this comment

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

LGTM.

Copy link
Member

@StanFromIreland StanFromIreland left a comment

Choose a reason for hiding this comment

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

Some little formalisation suggestions.

Prhmma and others added 8 commits October 17, 2025 11:09
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
@StanFromIreland
Copy link
Member

Please do not use the Update Branch button unless necessary (e.g. fixing conflicts, jogging the CI, or very old PRs) as it uses valuable resources. For more information see the devguide.

@StanFromIreland StanFromIreland self-requested a review October 18, 2025 11:16
Copy link
Member

@StanFromIreland StanFromIreland left a comment

Choose a reason for hiding this comment

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

LGTM (I left a minor suggestion to deduplicate two sentences), Marc, please merge this when you have a chance.

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
@malemburg malemburg merged commit 920de7c into python:main Oct 18, 2025
27 checks passed
@github-project-automation github-project-automation bot moved this from Todo to Done in Docs PRs Oct 18, 2025
@malemburg
Copy link
Member

Should we try a backport of this ?

@StanFromIreland
Copy link
Member

Sounds good to me, I think this paragraph is the same on all branches (and it's not like the specification has changed in the meantime :-), if there are conflicts I can fix.

@StanFromIreland StanFromIreland added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Oct 18, 2025
@miss-islington-app
Copy link

Thanks @Prhmma for the PR, and @malemburg for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

@miss-islington-app
Copy link

Thanks @Prhmma for the PR, and @malemburg for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 18, 2025
Closes pythonGH-128571
(cherry picked from commit 920de7c)

Co-authored-by: Parham MohammadAlizadeh <prhmma@gmail.com>
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 18, 2025
Closes pythonGH-128571
(cherry picked from commit 920de7c)

Co-authored-by: Parham MohammadAlizadeh <prhmma@gmail.com>
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
@bedevere-app
Copy link

bedevere-app bot commented Oct 18, 2025

GH-140308 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Oct 18, 2025
@bedevere-app
Copy link

bedevere-app bot commented Oct 18, 2025

GH-140309 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Oct 18, 2025
malemburg pushed a commit that referenced this pull request Oct 18, 2025
…140309)

Closes GH-128571
(cherry picked from commit 920de7c)

Co-authored-by: Parham MohammadAlizadeh <prhmma@gmail.com>
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
malemburg pushed a commit that referenced this pull request Oct 18, 2025
…140308)

Closes GH-128571
(cherry picked from commit 920de7c)

Co-authored-by: Parham MohammadAlizadeh <prhmma@gmail.com>
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
@malemburg
Copy link
Member

Thanks, both.

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

Labels

docs Documentation in the Doc dir skip news

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants