Skip to content

Commit

Permalink
fix: Disallow single string as etree.fromstringlist() input
Browse files Browse the repository at this point in the history
(Ab)use warnings.deprecated to provide warning when single string is supplied as input data. Lxml specifically handle this case as exception.
  • Loading branch information
abelcheung committed Oct 22, 2024
1 parent ca789c5 commit bc8798b
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions lxml-stubs/etree/_module_func.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import sys
from typing import Any, Iterable, Literal, final, overload

if sys.version_info >= (3, 11):
from typing import Never
else:
from typing_extensions import Never

if sys.version_info >= (3, 13):
from typing import TypeIs
from warnings import deprecated
Expand Down Expand Up @@ -109,17 +114,24 @@ def fromstring(
base_url: _AnyStr | None = None,
) -> _Element: ...
@overload
@deprecated("Raises exception if input is a single string")
def fromstringlist(
strings: Iterable[_AnyStr],
parser: _DefEtreeParsers[_ET_co],
) -> _ET_co:
strings: _AnyStr,
*args: Any,
**kw: Any,
) -> Never:
"""Parses an XML document from a sequence of strings. Returns the
root node (or the result returned by a parser target).
To override the default parser with a different parser you can pass it to
the ``parser`` keyword argument.
"""

@overload
def fromstringlist(
strings: Iterable[_AnyStr],
parser: _DefEtreeParsers[_ET_co],
) -> _ET_co: ...
@overload
def fromstringlist(
strings: Iterable[_AnyStr],
Expand Down

0 comments on commit bc8798b

Please sign in to comment.