Skip to content

gh-95472: [xml.etree.ElementTree] Add fine-grained formatting classes #95476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

ctrlcctrlv
Copy link

@ctrlcctrlv ctrlcctrlv commented Jul 30, 2022

  • ShortEmptyElements — make it possible to remove space between end of
    tag and slash, also make it possible to turn this on and off based on
    tag being processed via defaultdict.
  • XMLDeclarationQuotes — change quote char used in XML declaration from
    ' to ".

Closes #95472.

@ghost
Copy link

ghost commented Jul 30, 2022

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-bot
Copy link

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

* ShortEmptyElements — make it possible to remove space between end of
  tag and slash, also make it possible to turn this on and off based on
  tag being processed via `defaultdict`.
* XMLDeclarationQuotes — change quote char used in XML declaration from
  `'` to `"`.
@ctrlcctrlv ctrlcctrlv force-pushed the Issue№95472_MergeMain branch from fc3ba6b to 5c159e1 Compare July 30, 2022 19:40
@bedevere-bot
Copy link

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

Co-Authored-By: Fredrick Brennan <copypaste@kittens.ph>
@ctrlcctrlv ctrlcctrlv force-pushed the Issue№95472_MergeMain branch from c857de4 to fb47e0d Compare July 30, 2022 19:44
@tirkarthi tirkarthi requested a review from scoder July 31, 2022 17:18
Comment on lines +557 to +559
if not isinstance(short_empty_elements, collections.defaultdict):
if isinstance(short_empty_elements, ShortEmptyElements):
return collections.defaultdict(lambda: short_empty_elements)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would also allow mappings that implement __missing__. Therefore, I suggest checking for everything else and assuming that what remains is probably some kind of acceptable dict. Or check for collections.abc.Mapping instead.

Copy link
Author

Choose a reason for hiding this comment

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

Sorry I don't quite understand. Should I just check for hasattr('__missing__') and then try to call it and make sure its result is a ShortEmptyElements?

Copy link
Contributor

@scoder scoder Aug 6, 2022

Choose a reason for hiding this comment

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

I suggested to accept any Mapping, basically. You can either check isinstance(..., collections.abc.Mapping), or you could also ducktypingly check for the enums first and simply assume that, otherwise, users probably passed some kind of acceptable mapping, and will have to live with a runtime error if the object they provided misbehaves somehow.

There are really different ways for users to make an item lookup (subscripting) return a reasonable value that we can use for our processing here. A defaultdict is just one in many.

@scoder
Copy link
Contributor

scoder commented Aug 3, 2022

The feature seems good in general.

ctrlcctrlv added a commit to ctrlcctrlv/Besley that referenced this pull request Aug 6, 2022
Note: Uses a different xml.etree.ElementTree than is normal for the
utility file, but this should not be a big deal.

See <python/cpython#95476>.
ctrlcctrlv and others added 3 commits August 6, 2022 15:43
Co-authored-by: scoder <stefan_ml@behnel.de>
Co-authored-by: scoder <stefan_ml@behnel.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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