X Tutup
Skip to content

Deprecate public access to XMLWriter; simplify some attribute settings#31143

Merged
QuLogic merged 1 commit intomatplotlib:mainfrom
anntzer:svgattrib
Mar 9, 2026
Merged

Deprecate public access to XMLWriter; simplify some attribute settings#31143
QuLogic merged 1 commit intomatplotlib:mainfrom
anntzer:svgattrib

Conversation

@anntzer
Copy link
Contributor

@anntzer anntzer commented Feb 12, 2026

It is not necessary to put the attributes into a dict just to pass the dict to start() later; rather the attributes can be passed directly as kwargs to element(). Even in the case where the attributes are not valid identifiers one can use dict-unpacking to pass them.

This also allows removing the awkward attrib={} mutable default on XMLWriter (#31141), and the (theoretical) impossibility of passing an attribute named "attrib" to start(). As this changes the API of XMLWriter, take that opportunity to make that helper class private (with deprecation).

PR summary

PR checklist

@timhoffm
Copy link
Member

The existing signature matches

https://docs.python.org/3/library/xml.etree.elementtree.html#xml.etree.ElementTree.Element

I think there is value in keeping that.

@anntzer
Copy link
Contributor Author

anntzer commented Feb 20, 2026

I can choose to keep the old signature if you prefer, but what do you think about the call sites? (essentially, is element(..., attrib=...) really better than element(..., **...))?

@timhoffm
Copy link
Member

I think attrib= is more readable. The advantage of kwargs is that you can specify them directly, e.g. …, id=…, but that doesn’t work for keys containing non-identifier chars. So we are left with {“some-key”: … }. Normally, passing a dict through via ** is ok, but since the API of ElementTree provides the attribute arg and we have the choice, I’d stick with that.

Note: I assume that’s the intention of the ElementTree design: use attrib for more complex configuration and direct keywords as a convenience for very simple cases like (…, id=…).

@anntzer
Copy link
Contributor Author

anntzer commented Feb 23, 2026

Do you want to just close this, or are there still parts that you think are worth keeping? I'm fine either way.

@timhoffm
Copy link
Member

Making XMLWriter private is still reasonable. Choose yourself, whether closing+separate PR or force-pushing is simpler.

@anntzer
Copy link
Contributor Author

anntzer commented Mar 6, 2026

Kept only the "Make XMLWriter private" part, plus converting a few attributes into direct kwargs (the hopefully uncontroversial ones, with no dict unpacking).

@QuLogic QuLogic modified the milestone: v3.11.0 Mar 6, 2026
@QuLogic
Copy link
Member

QuLogic commented Mar 6, 2026

Doc failure appears related:

/home/circleci/project/lib/matplotlib/backends/backend_svg.py:docstring of matplotlib.backends.backend_svg.XMLWriter:1: WARNING: py:class reference target not found: matplotlib.backends.backend_svg._XMLWriter [ref.class]

@anntzer
Copy link
Contributor Author

anntzer commented Mar 8, 2026

Hopefully fixed now.

@QuLogic QuLogic changed the title Inline the definition of some SVG attributes. Deprecate public access to XMLWriter; simplify some attribute settings Mar 9, 2026
@QuLogic
Copy link
Member

QuLogic commented Mar 9, 2026

Sadly not, it seems.

@QuLogic QuLogic merged commit d5f597d into matplotlib:main Mar 9, 2026
39 of 40 checks passed
@anntzer anntzer deleted the svgattrib branch March 10, 2026 09:04
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.

3 participants

X Tutup