python / python/cpython

`xml.etree.ElementTree` — doesn't allow specifying fine-grained formatting controls

Open
#95,472 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

topic-XML type-feature
Dominant language
Python
Stars
77.2k
Forks
36k
PR merge metrics
PR metrics pending

Description

(Note: I already have a PR and this is a tracking issue.)

Enhancement

XML is maddening from a Git perspective, as if multiple tools will edit it, you'll get lots of lines in the diff that aren't needed.

For example:

diff --git a/sources/designspace/Besley.designspace b/sources/designspace/Besley.designspace
index d247944..eecb985 100644
--- a/sources/designspace/Besley.designspace
+++ b/sources/designspace/Besley.designspace
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="UTF-8"?>
+<?xml version='1.0' encoding='UTF-8'?>

And:

diff --git a/sources/designspace/Besley.designspace b/sources/designspace/Besley.designspace
index d247944..9d570dd 100644
--- a/sources/designspace/Besley.designspace
+++ b/sources/designspace/Besley.designspace
@@ -10,15 +10,15 @@
       <map input="800" output="766"/>
       <map input="900" output="900"/>
     </axis>
-    <axis tag="wdth" name="Width" minimum="75" maximum="100" default="100"></axis>
+    <axis tag="wdth" name="Width" minimum="75" maximum="100" default="100" />
   </axes>
 
   <sources>
 
     <source filename="../ufo/Besley-Book.ufo" name="Besley Regular" familyname="Besley" stylename="Regular">
       <location>
-        <dimension name="Weight" xvalue="400"/>
-        <dimension name="Width" xvalue="100"/>
+        <dimension name="Weight" xvalue="400" />
+        <dimension name="Width" xvalue="100" />
       </location>
     </source>
 

There are likely other issues, but I only needed to solve these two.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the existing pull request mentioned in the issue and the xml.etree.ElementTree formatting behavior it changes. The work is complete when callers can control the XML declaration quoting and empty-element formatting independently, with coverage for both examples shown.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
15/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.