fix: moving types to use Union again
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
from collections.abc import Mapping
|
from collections.abc import Mapping
|
||||||
from types import MappingProxyType
|
from types import MappingProxyType
|
||||||
from re import compile as re_compile, sub, UNICODE, IGNORECASE
|
from re import compile as re_compile, UNICODE, IGNORECASE
|
||||||
|
|
||||||
from orjson import dumps, loads
|
from orjson import dumps, loads
|
||||||
|
|
||||||
@@ -165,7 +165,7 @@ class TextHandler(str):
|
|||||||
clean_match: bool = False,
|
clean_match: bool = False,
|
||||||
case_sensitive: bool = True,
|
case_sensitive: bool = True,
|
||||||
check_match: bool = False,
|
check_match: bool = False,
|
||||||
) -> "TextHandlers" | bool:
|
) -> Union["TextHandlers", bool]:
|
||||||
"""Apply the given regex to the current text and return a list of strings with the matches.
|
"""Apply the given regex to the current text and return a list of strings with the matches.
|
||||||
|
|
||||||
:param regex: Can be either a compiled regular expression or a string.
|
:param regex: Can be either a compiled regular expression or a string.
|
||||||
@@ -244,7 +244,9 @@ class TextHandlers(List[TextHandler]):
|
|||||||
def __getitem__(self, pos: slice) -> "TextHandlers":
|
def __getitem__(self, pos: slice) -> "TextHandlers":
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def __getitem__(self, pos: SupportsIndex | slice) -> TextHandler | "TextHandlers":
|
def __getitem__(
|
||||||
|
self, pos: SupportsIndex | slice
|
||||||
|
) -> Union[TextHandler, "TextHandlers"]:
|
||||||
lst = super().__getitem__(pos)
|
lst = super().__getitem__(pos)
|
||||||
if isinstance(pos, slice):
|
if isinstance(pos, slice):
|
||||||
lst = [TextHandler(s) for s in lst]
|
lst = [TextHandler(s) for s in lst]
|
||||||
|
|||||||
+8
-8
@@ -236,7 +236,7 @@ class Selector(SelectorsGeneration):
|
|||||||
|
|
||||||
def __handle_element(
|
def __handle_element(
|
||||||
self, element: HtmlElement | _ElementUnicodeResult
|
self, element: HtmlElement | _ElementUnicodeResult
|
||||||
) -> Optional[TextHandler | "Selector"]:
|
) -> Optional[Union[TextHandler, "Selector"]]:
|
||||||
"""Used internally in all functions to convert a single element to type (Selector|TextHandler) when possible"""
|
"""Used internally in all functions to convert a single element to type (Selector|TextHandler) when possible"""
|
||||||
if element is None:
|
if element is None:
|
||||||
return None
|
return None
|
||||||
@@ -468,10 +468,10 @@ class Selector(SelectorsGeneration):
|
|||||||
# From here we start with the selecting functions
|
# From here we start with the selecting functions
|
||||||
def relocate(
|
def relocate(
|
||||||
self,
|
self,
|
||||||
element: Dict | HtmlElement | "Selector",
|
element: Union[Dict, HtmlElement, "Selector"],
|
||||||
percentage: int = 0,
|
percentage: int = 0,
|
||||||
selector_type: bool = False,
|
selector_type: bool = False,
|
||||||
) -> List[HtmlElement] | "Selectors":
|
) -> Union[List[HtmlElement], "Selectors"]:
|
||||||
"""This function will search again for the element in the page tree, used automatically on page structure change
|
"""This function will search again for the element in the page tree, used automatically on page structure change
|
||||||
|
|
||||||
:param element: The element we want to relocate in the tree
|
:param element: The element we want to relocate in the tree
|
||||||
@@ -579,7 +579,7 @@ class Selector(SelectorsGeneration):
|
|||||||
adaptive: bool = False,
|
adaptive: bool = False,
|
||||||
auto_save: bool = False,
|
auto_save: bool = False,
|
||||||
percentage: int = 0,
|
percentage: int = 0,
|
||||||
) -> "Selectors" | List | "TextHandlers":
|
) -> Union["Selectors", List, "TextHandlers"]:
|
||||||
"""Search the current tree with CSS3 selectors
|
"""Search the current tree with CSS3 selectors
|
||||||
|
|
||||||
**Important:
|
**Important:
|
||||||
@@ -642,7 +642,7 @@ class Selector(SelectorsGeneration):
|
|||||||
auto_save: bool = False,
|
auto_save: bool = False,
|
||||||
percentage: int = 0,
|
percentage: int = 0,
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> "Selectors" | List | "TextHandlers":
|
) -> Union["Selectors", List, "TextHandlers"]:
|
||||||
"""Search the current tree with XPath selectors
|
"""Search the current tree with XPath selectors
|
||||||
|
|
||||||
**Important:
|
**Important:
|
||||||
@@ -927,7 +927,7 @@ class Selector(SelectorsGeneration):
|
|||||||
)
|
)
|
||||||
return score
|
return score
|
||||||
|
|
||||||
def save(self, element: "Selector" | HtmlElement, identifier: str) -> None:
|
def save(self, element: Union["Selector", HtmlElement], identifier: str) -> None:
|
||||||
"""Saves the element's unique properties to the storage for retrieval and relocation later
|
"""Saves the element's unique properties to the storage for retrieval and relocation later
|
||||||
|
|
||||||
:param element: The element itself that we want to save to storage, it can be a ` Selector ` or pure ` HtmlElement `
|
:param element: The element itself that we want to save to storage, it can be a ` Selector ` or pure ` HtmlElement `
|
||||||
@@ -1061,7 +1061,7 @@ class Selector(SelectorsGeneration):
|
|||||||
"src",
|
"src",
|
||||||
),
|
),
|
||||||
match_text: bool = False,
|
match_text: bool = False,
|
||||||
) -> "Selectors" | List:
|
) -> Union["Selectors", List]:
|
||||||
"""Find elements that are in the same tree depth in the page with the same tag name and same parent tag etc...
|
"""Find elements that are in the same tree depth in the page with the same tag name and same parent tag etc...
|
||||||
then return the ones that match the current element attributes with a percentage higher than the input threshold.
|
then return the ones that match the current element attributes with a percentage higher than the input threshold.
|
||||||
|
|
||||||
@@ -1217,7 +1217,7 @@ class Selectors(List[Selector]):
|
|||||||
def __getitem__(self, pos: slice) -> "Selectors":
|
def __getitem__(self, pos: slice) -> "Selectors":
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def __getitem__(self, pos: SupportsIndex | slice) -> Selector | "Selectors":
|
def __getitem__(self, pos: SupportsIndex | slice) -> Union[Selector, "Selectors"]:
|
||||||
lst = super().__getitem__(pos)
|
lst = super().__getitem__(pos)
|
||||||
if isinstance(pos, slice):
|
if isinstance(pos, slice):
|
||||||
return self.__class__(lst)
|
return self.__class__(lst)
|
||||||
|
|||||||
Reference in New Issue
Block a user