From 31b0ec378fb10729b16fd4ad8b542c81b84cdba6 Mon Sep 17 00:00:00 2001 From: dispread <107815346+dispread@users.noreply.github.com> Date: Fri, 12 Apr 2024 13:54:04 +0200 Subject: [PATCH 1/9] Added findtext() and xpath() --- lxml-stubs/html/_element.pyi | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lxml-stubs/html/_element.pyi b/lxml-stubs/html/_element.pyi index ee87cf9..3b8a21e 100644 --- a/lxml-stubs/html/_element.pyi +++ b/lxml-stubs/html/_element.pyi @@ -195,12 +195,18 @@ class HtmlElement(etree.ElementBase): def find( self, path: _ElemPathArg, namespaces: _NSMapArg | None = None ) -> HtmlElement | None: ... + def findtext( + self, path, default=None, namespaces=None + ) -> str: ... def findall( self, path: _ElemPathArg, namespaces: _NSMapArg | None = None ) -> list[HtmlElement]: ... def iterfind( self, path: _ElemPathArg, namespaces: _NSMapArg | None = None ) -> Iterator[HtmlElement]: ... + def xpath( + self, _path, *, namespaces=None, extensions=None, smart_strings=True, **_variables + ) -> list[HTMLElement]: ... def cssselect( self, expr: str, From 4a4c76e5fb8cd0c0caa0c50c15807c027a97c19a Mon Sep 17 00:00:00 2001 From: dispread <107815346+dispread@users.noreply.github.com> Date: Fri, 12 Apr 2024 14:28:25 +0200 Subject: [PATCH 2/9] Specify arg types --- lxml-stubs/html/_element.pyi | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lxml-stubs/html/_element.pyi b/lxml-stubs/html/_element.pyi index 3b8a21e..141c783 100644 --- a/lxml-stubs/html/_element.pyi +++ b/lxml-stubs/html/_element.pyi @@ -196,8 +196,11 @@ class HtmlElement(etree.ElementBase): self, path: _ElemPathArg, namespaces: _NSMapArg | None = None ) -> HtmlElement | None: ... def findtext( - self, path, default=None, namespaces=None - ) -> str: ... + self, + path: _ElemPathArg, + default: _T | None = None, + namespaces: _NSMapArg | None = None, + ) -> str | _T: ... def findall( self, path: _ElemPathArg, namespaces: _NSMapArg | None = None ) -> list[HtmlElement]: ... @@ -205,7 +208,13 @@ class HtmlElement(etree.ElementBase): self, path: _ElemPathArg, namespaces: _NSMapArg | None = None ) -> Iterator[HtmlElement]: ... def xpath( - self, _path, *, namespaces=None, extensions=None, smart_strings=True, **_variables + self, + _path: _AnyStr, + *, + namespaces: _NonDefaultNSMapArg | None = None, + extensions: _XPathExtFuncArg | None = None, + smart_strings: bool = True, + **_variables: _XPathVarArg ) -> list[HTMLElement]: ... def cssselect( self, From 86324794cb60fc9a05d26c8e13f10eaa611d17ee Mon Sep 17 00:00:00 2001 From: dispread <107815346+dispread@users.noreply.github.com> Date: Fri, 12 Apr 2024 14:47:36 +0200 Subject: [PATCH 3/9] Fixed some stuff --- lxml-stubs/html/_element.pyi | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lxml-stubs/html/_element.pyi b/lxml-stubs/html/_element.pyi index 141c783..c661d13 100644 --- a/lxml-stubs/html/_element.pyi +++ b/lxml-stubs/html/_element.pyi @@ -17,6 +17,8 @@ from .._types import ( _NSMapArg, _TagName, _TagSelector, + _XPathExtFuncArg, + _XPathVarArg, ) from ..cssselect import _CSSTransArg from ._form import FormElement, LabelElement @@ -211,7 +213,7 @@ class HtmlElement(etree.ElementBase): self, _path: _AnyStr, *, - namespaces: _NonDefaultNSMapArg | None = None, + namespaces: _NSMapArg | None = None, extensions: _XPathExtFuncArg | None = None, smart_strings: bool = True, **_variables: _XPathVarArg From 76e546f5e438db45bc91cf7c7087166a98162f92 Mon Sep 17 00:00:00 2001 From: dispread <107815346+dispread@users.noreply.github.com> Date: Fri, 12 Apr 2024 14:53:37 +0200 Subject: [PATCH 4/9] Updated stuff Silly mistakes --- lxml-stubs/html/_element.pyi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lxml-stubs/html/_element.pyi b/lxml-stubs/html/_element.pyi index c661d13..fdf6690 100644 --- a/lxml-stubs/html/_element.pyi +++ b/lxml-stubs/html/_element.pyi @@ -213,17 +213,17 @@ class HtmlElement(etree.ElementBase): self, _path: _AnyStr, *, - namespaces: _NSMapArg | None = None, + namespaces: _NonDefaultNSMapArg | None = None, extensions: _XPathExtFuncArg | None = None, smart_strings: bool = True, **_variables: _XPathVarArg - ) -> list[HTMLElement]: ... + ) -> list[HtmlElement]: ... def cssselect( self, expr: str, *, translator: _CSSTransArg = "xml", - ) -> list[HtmlElement]: ... + ) -> _XPathObject: ... # # HTML element class attribute From 38543c9102e89a19b40314d896ad3b1b5da85025 Mon Sep 17 00:00:00 2001 From: dispread <107815346+dispread@users.noreply.github.com> Date: Fri, 12 Apr 2024 14:57:37 +0200 Subject: [PATCH 5/9] Update _element.pyi Hopefully works now --- lxml-stubs/html/_element.pyi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lxml-stubs/html/_element.pyi b/lxml-stubs/html/_element.pyi index fdf6690..b637f1c 100644 --- a/lxml-stubs/html/_element.pyi +++ b/lxml-stubs/html/_element.pyi @@ -14,6 +14,7 @@ from .._types import ( _AttrName, _AttrVal, _ElemPathArg, + _NonDefaultNSMapArg, _NSMapArg, _TagName, _TagSelector, @@ -200,7 +201,7 @@ class HtmlElement(etree.ElementBase): def findtext( self, path: _ElemPathArg, - default: _T | None = None, + default: _T, namespaces: _NSMapArg | None = None, ) -> str | _T: ... def findall( From ed2cd1b60dca9f43290b28822fcc3f5185f1565f Mon Sep 17 00:00:00 2001 From: dispread <107815346+dispread@users.noreply.github.com> Date: Fri, 12 Apr 2024 15:03:55 +0200 Subject: [PATCH 6/9] added overload to findtext so thats why it didnt work --- lxml-stubs/html/_element.pyi | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lxml-stubs/html/_element.pyi b/lxml-stubs/html/_element.pyi index b637f1c..bf2bfb9 100644 --- a/lxml-stubs/html/_element.pyi +++ b/lxml-stubs/html/_element.pyi @@ -198,6 +198,14 @@ class HtmlElement(etree.ElementBase): def find( self, path: _ElemPathArg, namespaces: _NSMapArg | None = None ) -> HtmlElement | None: ... + @overload + def findtext( + self, + path: _ElemPathArg, + *, + namespaces: _NSMapArg | None = None, + ) -> str | None: ... + @overload def findtext( self, path: _ElemPathArg, From 423234f258afb9cb46a531d5b2519a67e812e8f8 Mon Sep 17 00:00:00 2001 From: dispread <107815346+dispread@users.noreply.github.com> Date: Fri, 12 Apr 2024 15:05:24 +0200 Subject: [PATCH 7/9] Update _element.pyi --- lxml-stubs/html/_element.pyi | 1 + 1 file changed, 1 insertion(+) diff --git a/lxml-stubs/html/_element.pyi b/lxml-stubs/html/_element.pyi index bf2bfb9..55a11f1 100644 --- a/lxml-stubs/html/_element.pyi +++ b/lxml-stubs/html/_element.pyi @@ -19,6 +19,7 @@ from .._types import ( _TagName, _TagSelector, _XPathExtFuncArg, + _XPathObject, _XPathVarArg, ) from ..cssselect import _CSSTransArg From a5b5443fae143ee6cee1405804d2d2f867dea0e3 Mon Sep 17 00:00:00 2001 From: dispread <107815346+dispread@users.noreply.github.com> Date: Fri, 12 Apr 2024 15:08:57 +0200 Subject: [PATCH 8/9] Update _element.pyi I swear I'm not retarded, just tired --- lxml-stubs/html/_element.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lxml-stubs/html/_element.pyi b/lxml-stubs/html/_element.pyi index 55a11f1..e8dad48 100644 --- a/lxml-stubs/html/_element.pyi +++ b/lxml-stubs/html/_element.pyi @@ -227,13 +227,13 @@ class HtmlElement(etree.ElementBase): extensions: _XPathExtFuncArg | None = None, smart_strings: bool = True, **_variables: _XPathVarArg - ) -> list[HtmlElement]: ... + ) -> _XPathObject: ... def cssselect( self, expr: str, *, translator: _CSSTransArg = "xml", - ) -> _XPathObject: ... + ) -> list[HtmlElement]: ... # # HTML element class attribute From b596b7ce7bd702da26c7c0b65e7d006c934fbb52 Mon Sep 17 00:00:00 2001 From: dispread <107815346+dispread@users.noreply.github.com> Date: Fri, 12 Apr 2024 15:10:22 +0200 Subject: [PATCH 9/9] Update _element.pyi --- lxml-stubs/html/_element.pyi | 1 + 1 file changed, 1 insertion(+) diff --git a/lxml-stubs/html/_element.pyi b/lxml-stubs/html/_element.pyi index e8dad48..3697d76 100644 --- a/lxml-stubs/html/_element.pyi +++ b/lxml-stubs/html/_element.pyi @@ -222,6 +222,7 @@ class HtmlElement(etree.ElementBase): def xpath( self, _path: _AnyStr, + /, *, namespaces: _NonDefaultNSMapArg | None = None, extensions: _XPathExtFuncArg | None = None,