FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-90756: Fix ElementTree.write XML prolog for encoding 'utf-8-sig' by pepr · Pull Request #31043 · python/cpython · GitHub

Repository navigation

gh-90756: Fix ElementTree.write XML prolog for encoding 'utf-8-sig' - #31043

Merged
serhiy-storchaka merged 3 commits into
python:mainfrom
pepr:main
Aug 13, 2026
Merged

serhiy-storchaka merged 3 commits into
python:mainfrom
pepr:main

Conversation

pepr commented Feb 1, 2022 •
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Contributor

bpo-46598: Fix ElementTree.write XML prolog for encoding 'utf-8-sig'

When ElementTree object is to be written to the file, and when BOM
is needed, the 'utf-8-sig' can be used for the purpose.
However, the XML prolog then looks like...

<?xml version='1.0' encoding='utf-8-sig'?>

... and that encoding in the prolog makes no sense. Therefore,
the utf-8-sig is changed to utf-8 for the purpose.

https://bugs.python.org/issue46598

When ElementTree object is to be written to the file, and when BOM
is needed, the 'utf-8-sig' can be used for the purpose.
However, the XML prolog then looks like...

<?xml version='1.0' encoding='utf-8-sig'?>

... and that encoding in the prolog makes no sense. Therefore,
the utf-8-sig is changed to utf-8 for the purpose.

Copy link
Copy Markdown

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

Recognized GitHub username

We couldn't find a bugs.python.org (b.p.o) account corresponding to the following GitHub usernames:

@pepr

This might be simply due to a missing "GitHub Name" entry in one's b.p.o account settings. This is necessary for legal reasons before we can look at this contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

pepr commented Feb 1, 2022 •
edited
Loading

Copy link
Copy Markdown
Contributor Author

Hello all,

Finally, I have found how to add my GitHub name to the b.p.o. Done. I have also signed the PSF contributor agreement.

The bpo-46598 was created, and the PR at b.p.o linked was added to point here.

The pull-request changes should be easily understandable, and I have tried it on my local computer.

Have a nice day,
Petr

corona10 changed the title Fix ElementTree.write XML prolog for encoding 'utf-8-sig' bpo-46598: Fix ElementTree.write XML prolog for encoding 'utf-8-sig' Feb 2, 2022

corona10 left a comment

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Please add the NEW.d for behavior changing

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

pepr commented Feb 2, 2022

Copy link
Copy Markdown
Contributor Author

@corona10: Sorry, I am new in this workflow. What does it mean the "add the NEW.d for behavior changing"? Is it expected from me?

scoder commented Feb 2, 2022

Copy link
Copy Markdown
Contributor

Thanks. You need to include a NEWS entry to describe the change.
https://devguide.python.org/committing/#updating-news-and-what-s-new-in-python

Also, this needs a test. See the ElementTree tests under Lib/test/ There are already some that deal with encodings and the XML prologue.

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 10, 2026
serhiy-storchaka changed the title bpo-46598: Fix ElementTree.write XML prolog for encoding 'utf-8-sig' gh-90756: Fix ElementTree.write XML prolog for encoding 'utf-8-sig' May 7, 2026
github-actions Bot removed the stale Stale PR or inactive for long period of time. label May 11, 2026
# Conflicts:
#	Lib/xml/etree/ElementTree.py

bedevere-app Bot commented Aug 11, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

Normalize the declared encoding before deciding whether to write the
declaration, so that utf-8-sig is treated as utf-8: the BOM already
determines the encoding.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

serhiy-storchaka left a comment

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Added tests and NEWS. Moved normalization so that the XML declaration is not written when xml_declaration is None (but BOM is). LGTM now.

serhiy-storchaka enabled auto-merge (squash) August 12, 2026 19:31
serhiy-storchaka merged commit 8420052 into python:main Aug 13, 2026
100 of 104 checks passed
mbeijen pushed a commit to mbeijen/cpython that referenced this pull request Aug 14, 2026
…thonGH-31043)

The BOM already determines the encoding, so the declaration is now
omitted by default, and declares utf-8 if requested explicitly.

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants


Back | FazBrowse Home | New Git URL