Skip to content

Commit

Permalink
fix: Guard against using simple str in etree.cleanup_namespaces()
Browse files Browse the repository at this point in the history
Supplying str in keep_ns_prefixes argument passes type check but causes subtle bug in code. Partially addresses #64.
  • Loading branch information
abelcheung committed Nov 25, 2024
1 parent e89f509 commit d0c43e8
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/lxml-stubs/etree/_cleanup.pyi
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
import sys
from typing import Collection, Iterable, overload

from .._types import _AnyStr, _ElementOrTree, _NSMapArg, _TagSelector
if sys.version_info >= (3, 13):
from warnings import deprecated
else:
from typing_extensions import deprecated

from .._types import _ElementOrTree, _NSMapArg, _TagSelector

@overload
@deprecated("Supply an iterator or collection of namespace prefixes instead.")
def cleanup_namespaces(
tree_or_element: _ElementOrTree,
top_nsmap: _NSMapArg | None = None,
keep_ns_prefixes: str | bytes | bytearray | None = None,
) -> None: ...
@overload
def cleanup_namespaces(
tree_or_element: _ElementOrTree,
top_nsmap: _NSMapArg | None = None,
keep_ns_prefixes: Iterable[_AnyStr] | None = None,
keep_ns_prefixes: Iterable[str | bytes | bytearray] | None = None,
) -> None: ...

# For functions below, the first `tree_or_element` argument
Expand Down

0 comments on commit d0c43e8

Please sign in to comment.