-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
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
base: main
Are you sure you want to change the base?
The head ref may contain hidden characters: "Issue\u211695472_MergeMain"
Conversation
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 `"`.
fc3ba6b
to
5c159e1
Compare
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>
c857de4
to
fb47e0d
Compare
if not isinstance(short_empty_elements, collections.defaultdict): | ||
if isinstance(short_empty_elements, ShortEmptyElements): | ||
return collections.defaultdict(lambda: short_empty_elements) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
The feature seems good in general. |
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>.
Co-authored-by: scoder <stefan_ml@behnel.de>
Co-authored-by: scoder <stefan_ml@behnel.de>
tag and slash, also make it possible to turn this on and off based on
tag being processed via
defaultdict
.'
to"
.Closes #95472.
xml.etree.ElementTree
— doesn't allow specifying fine-grained formatting controls #95472