Skip to content

Commit

Permalink
Move defusedxml import into the function using it
Browse files Browse the repository at this point in the history
Import `defusedxml` inside the `etree_parse()` function rather than
in global scope of `sphinx.testing.util`.  This makes it possible
for reverse dependencies (such as `breathe`) to use this module without
adding an unnecessary transitive dependency on `defusedxml` when it's
not actually used.

See also issue #12339.
  • Loading branch information
mgorny committed May 8, 2024
1 parent 98f953e commit 12f63b3
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion sphinx/testing/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from types import MappingProxyType
from typing import TYPE_CHECKING

from defusedxml.ElementTree import parse as xml_parse
from docutils import nodes
from docutils.parsers.rst import directives, roles

Expand Down Expand Up @@ -73,6 +72,8 @@ def assert_node(node: Node, cls: Any = None, xpath: str = "", **kwargs: Any) ->
# keep this to restrict the API usage and to have a correct return type
def etree_parse(path: str | os.PathLike[str]) -> ElementTree:
"""Parse a file into a (safe) XML element tree."""
from defusedxml.ElementTree import parse as xml_parse

return xml_parse(path)


Expand Down

0 comments on commit 12f63b3

Please sign in to comment.