From 7882cf25279d485582fa1aa2e9de4d71d6aadf6e Mon Sep 17 00:00:00 2001 From: Karim shoair Date: Thu, 30 Jan 2025 02:44:57 +0200 Subject: [PATCH] style(TextHandler): Setting overload on check_match argument for auto completion --- scrapling/core/custom_types.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/scrapling/core/custom_types.py b/scrapling/core/custom_types.py index d1ad2c1..03257c3 100644 --- a/scrapling/core/custom_types.py +++ b/scrapling/core/custom_types.py @@ -6,8 +6,8 @@ from types import MappingProxyType from orjson import dumps, loads from w3lib.html import replace_entities as _replace_entities -from scrapling.core._types import (Dict, Iterable, List, Optional, Pattern, - SupportsIndex, TypeVar, Union) +from scrapling.core._types import (Dict, Iterable, List, Literal, Optional, + Pattern, SupportsIndex, TypeVar, Union) from scrapling.core.utils import _is_iterable, flatten # Define type variable for AttributeHandler value type @@ -127,6 +127,28 @@ class TextHandler(str): # Check this out: https://github.com/ijl/orjson/issues/445 return loads(str(self)) + @typing.overload + def re( + self, + regex: Union[str, Pattern[str]], + replace_entities: bool = True, + clean_match: bool = False, + case_sensitive: bool = False, + check_match: Literal[True] = True, + ) -> bool: + ... + + @typing.overload + def re( + self, + regex: Union[str, Pattern[str]], + replace_entities: bool = True, + clean_match: bool = False, + case_sensitive: bool = False, + check_match: Literal[False] = False, + ) -> "TextHandlers[TextHandler]": + ... + def re( self, regex: Union[str, Pattern[str]], replace_entities: bool = True, clean_match: bool = False, case_sensitive: bool = False, check_match: bool = False