Skip to content

Commit

Permalink
Deprecates core_loaders.etree_loader
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Wagner committed Oct 28, 2024
1 parent 3489c05 commit 138f2e6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 9 additions & 0 deletions _delb/plugins/core_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from io import IOBase, UnsupportedOperation
from pathlib import Path
from typing import TYPE_CHECKING, cast, Any
from warnings import warn

from lxml import etree

Expand Down Expand Up @@ -60,8 +61,16 @@ def etree_loader(data: Any, config: SimpleNamespace) -> LoaderResult:
:class:`lxml.etree._ElementTree` instances.
"""
if isinstance(data, etree._ElementTree):
warn(
"lxml's etree models will not be usable inputs with the contributed core loaders.",
category=DeprecationWarning,
)
return deepcopy(data)
if isinstance(data, etree._Element):
warn(
"lxml's etree models will not be usable inputs with the contributed core loaders.",
category=DeprecationWarning,
)
return etree.ElementTree(
element=deepcopy(data), parser=config.parser_options._make_parser()
)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def test_etree_loader():
tree = etree.parse(str(TEST_FILE))
root = tree.getroot()

document = Document(root)
with pytest.deprecated_call():
document = Document(root)
assert document.root._etree_obj is not root
assert document.source_url is None

Expand Down

0 comments on commit 138f2e6

Please sign in to comment.