Skip to content

Commit

Permalink
fix(stub): Guard against str usage in XPath Extension function
Browse files Browse the repository at this point in the history
Closes #64
  • Loading branch information
abelcheung committed Dec 13, 2024
1 parent 116376d commit ff2fde8
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions src/lxml-stubs/etree/_xpath.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,20 @@
import sys
from abc import abstractmethod
from types import ModuleType
from typing import Any, Callable, Collection, Generic, Protocol, final, overload
from typing import (
Any,
Callable,
Generic,
Iterable,
Protocol,
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 warnings import deprecated
Expand Down Expand Up @@ -142,17 +155,26 @@ class _ElementUnicodeResult(str, Generic[_ET]):
def attrname(self) -> str | None: ...
def getparent(self: _ElementUnicodeResult[_ET]) -> _ET | None: ...

@overload # guard against str
@deprecated(
"Use Iterable even when only one function is specified in function_mapping argument"
)
def Extension(
module: object | ModuleType,
function_mapping: str,
**kw: Any,
) -> Never: ...
@overload # no namespace
def Extension(
module: object | ModuleType,
function_mapping: dict[str, str] | Collection[str] | None = None,
function_mapping: dict[str, str] | Iterable[str] | None = None,
*,
ns: None = None,
) -> dict[tuple[None, str], Callable[..., Any]]: ...
@overload # namespace present
def Extension(
module: object | ModuleType,
function_mapping: dict[str, str] | Collection[str] | None = None,
function_mapping: dict[str, str] | Iterable[str] | None = None,
*,
ns: str,
) -> dict[tuple[str, str], Callable[..., Any]]:
Expand Down

0 comments on commit ff2fde8

Please sign in to comment.