Skip to content

Commit

Permalink
fix: Another round of str collection fix
Browse files Browse the repository at this point in the history
Fix inclusive_ns_prefixes parameter in C14N writing, partially addresses #64
  • Loading branch information
abelcheung committed Nov 7, 2024
1 parent 3a3ee9b commit 06f868b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
13 changes: 10 additions & 3 deletions lxml-stubs/etree/_element.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,17 @@ class _ElementTree(Generic[_t._ET_co]):
@deprecated('Since v3.8.0; use "doctype" parameter instead')
def write(
self,
file: Any,
*,
*args: Any,
docstring: str,
__kw: Any,
**kw: Any,
) -> None: ...
@overload # warn if inclusive_ns_prefixes is not collection
@deprecated("'inclusive_ns_prefixes' should be collection, otherwise will either search for wrong NS prefix or raise exception")
def write(
self,
*args: Any,
inclusive_ns_prefixes: _t._AnyStr,
**kw: Any,
) -> None: ...
@overload # method=c14n
def write(
Expand Down
24 changes: 16 additions & 8 deletions lxml-stubs/etree/_module_func.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sys
from typing import Any, Iterable, Literal, final, overload
from typing import Any, Collection, Iterable, Literal, final, overload

if sys.version_info >= (3, 11):
from typing import Never
Expand Down Expand Up @@ -140,15 +140,14 @@ def fromstringlist(

# Under XML Canonicalization (C14N) mode, most arguments are ignored,
# some arguments would even raise exception outright if specified.
@overload # method="c14n"
@overload # warn if inclusive_ns_prefixes is not collection
@deprecated("'inclusive_ns_prefixes' should be collection, otherwise will either search for wrong NS prefix or raise exception")
def tostring(
element_or_tree: _ElementOrTree,
element_or_tree: Any,
*,
method: Literal["c14n"],
exclusive: bool = False,
inclusive_ns_prefixes: Iterable[_AnyStr] | None = None,
with_comments: bool = True,
) -> bytes:
inclusive_ns_prefixes: _AnyStr,
**_kw: Any,
) -> Never:
"""Serialize an element to an encoded string representation of its XML tree.
Annotation
Expand Down Expand Up @@ -202,6 +201,15 @@ def tostring(
on the tail text of children, which will always be serialised.
"""

@overload # method="c14n"
def tostring(
element_or_tree: _ElementOrTree,
*,
method: Literal["c14n"],
exclusive: bool = False,
inclusive_ns_prefixes: Collection[_AnyStr] | None = None,
with_comments: bool = True,
) -> bytes: ...
@overload # method="c14n2"
def tostring(
element_or_tree: _ElementOrTree,
Expand Down

0 comments on commit 06f868b

Please sign in to comment.