diff --git a/stubs/dateparser/METADATA.toml b/stubs/dateparser/METADATA.toml index 34b910b18e45..2e688a20eb1c 100644 --- a/stubs/dateparser/METADATA.toml +++ b/stubs/dateparser/METADATA.toml @@ -1,4 +1,4 @@ -version = "1.4.1" +version = "1.4.2" upstream-repository = "https://github.com/scrapinghub/dateparser" [tool.stubtest] diff --git a/stubs/dateparser/dateparser/__init__.pyi b/stubs/dateparser/dateparser/__init__.pyi index ff3ab72b686a..2b91d4db2992 100644 --- a/stubs/dateparser/dateparser/__init__.pyi +++ b/stubs/dateparser/dateparser/__init__.pyi @@ -22,6 +22,7 @@ class _Settings(TypedDict, total=False): # noqa: Y049 RELATIVE_BASE: datetime.datetime STRICT_PARSING: bool REQUIRE_PARTS: list[Literal["day", "month", "year"]] + IGNORE_SURROUNDING_TEXT: bool SKIP_TOKENS: list[str] NORMALIZE: bool RETURN_TIME_AS_PERIOD: bool diff --git a/stubs/dateparser/dateparser/conf.pyi b/stubs/dateparser/dateparser/conf.pyi index d2fafefb1cdb..26202baaf9e9 100644 --- a/stubs/dateparser/dateparser/conf.pyi +++ b/stubs/dateparser/dateparser/conf.pyi @@ -20,6 +20,7 @@ class Settings: RELATIVE_BASE: datetime.datetime STRICT_PARSING: bool REQUIRE_PARTS: list[Literal["day", "month", "year"]] + IGNORE_SURROUNDING_TEXT: bool SKIP_TOKENS: list[str] NORMALIZE: bool RETURN_TIME_AS_PERIOD: bool diff --git a/stubs/dateparser/dateparser/date.pyi b/stubs/dateparser/dateparser/date.pyi index 0b730c9d6899..465e738b3806 100644 --- a/stubs/dateparser/dateparser/date.pyi +++ b/stubs/dateparser/dateparser/date.pyi @@ -74,6 +74,7 @@ class _DateLocaleParser: date_string: str, date_formats: list[str] | tuple[str, ...] | AbstractSet[str] | None, settings: Settings | None = None, + ignore_surrounding_text: bool = False, ) -> None: ... @classmethod def parse( @@ -82,6 +83,7 @@ class _DateLocaleParser: date_string: str, date_formats: list[str] | tuple[str, ...] | AbstractSet[str] | None = None, settings: Settings | None = None, + ignore_surrounding_text: bool = False, ) -> DateData: ... def _parse(self) -> DateData | None: ... def _try_timestamp(self) -> DateData: ... @@ -140,7 +142,7 @@ class DateDataParser: def get_date_tuple( self, date_string: str, date_formats: list[str] | tuple[str, ...] | AbstractSet[str] | None = None ) -> _DateData: ... - def _get_applicable_locales(self, date_string: str) -> Iterator[Locale]: ... - def _is_applicable_locale(self, locale: Locale, date_string: str) -> bool: ... + def _get_applicable_locales(self, date_string: str, ignore_surrounding_text: bool = False) -> Iterator[Locale]: ... + def _is_applicable_locale(self, locale: Locale, date_string: str, ignore_surrounding_text: bool = False) -> bool: ... @classmethod def _get_locale_loader(cls: type[DateDataParser]) -> LocaleDataLoader: ... diff --git a/stubs/dateparser/dateparser/languages/locale.pyi b/stubs/dateparser/dateparser/languages/locale.pyi index ad6ae9d283d2..587414f06bfe 100644 --- a/stubs/dateparser/dateparser/languages/locale.pyi +++ b/stubs/dateparser/dateparser/languages/locale.pyi @@ -15,11 +15,23 @@ class Locale: shortname: str info: OrderedDict[str, Incomplete] def __init__(self, shortname: str, language_info: Mapping[Incomplete, Incomplete]) -> None: ... - def is_applicable(self, date_string: str, strip_timezone: bool = False, settings: Settings | None = None) -> bool: ... + def is_applicable( + self, + date_string: str, + strip_timezone: bool = False, + settings: Settings | None = None, + ignore_surrounding_text: bool = False, + ) -> bool: ... def count_applicability(self, text: str, strip_timezone: bool = False, settings: Settings | None = None) -> list[int]: ... @staticmethod def clean_dictionary(dictionary: Mapping[_K, _V], threshold: int = 2) -> Mapping[_K, _V]: ... - def translate(self, date_string: str, keep_formatting: bool = False, settings: Settings | None = None) -> str: ... + def translate( + self, + date_string: str, + keep_formatting: bool = False, + settings: Settings | None = None, + ignore_surrounding_text: bool = False, + ) -> str: ... def translate_search(self, search_string: str, settings: Settings | None = None) -> tuple[list[str], list[str]]: ... def get_wordchars_for_detection(self, settings: Settings) -> set[str]: ... def to_parserinfo(self, base_cls: type = ...): ... diff --git a/stubs/dateparser/dateparser/search/__init__.pyi b/stubs/dateparser/dateparser/search/__init__.pyi index d6eb3182de64..4c5d5c6c467d 100644 --- a/stubs/dateparser/dateparser/search/__init__.pyi +++ b/stubs/dateparser/dateparser/search/__init__.pyi @@ -13,6 +13,7 @@ def search_dates( settings: Settings | dict[str, Any] | None, add_detected_language: Literal[True], detect_languages_function: _DetectLanguagesFunction | None = None, + strategy: Literal["split", "ngram"] = "split", ) -> list[tuple[str, datetime, str]] | None: ... @overload def search_dates( @@ -21,4 +22,5 @@ def search_dates( settings: Settings | dict[str, Any] | None = None, add_detected_language: Literal[False] = False, detect_languages_function: _DetectLanguagesFunction | None = None, + strategy: Literal["split", "ngram"] = "split", ) -> list[tuple[str, datetime]] | None: ... diff --git a/stubs/dateparser/dateparser/search/ngram_search.pyi b/stubs/dateparser/dateparser/search/ngram_search.pyi new file mode 100644 index 000000000000..9a22a1c57174 --- /dev/null +++ b/stubs/dateparser/dateparser/search/ngram_search.pyi @@ -0,0 +1,18 @@ +import datetime +from _typeshed import Incomplete +from collections.abc import Set as AbstractSet +from logging import Logger + +from dateparser.conf import Settings + +logger: Logger + +class _NgramDateSearch: + max_tokens: int + def __init__(self, max_tokens: int = 7) -> None: ... + def search_parse( + self, + languages: list[str] | tuple[str, ...] | AbstractSet[str] | None, + text: str, + settings: Settings | dict[str, Incomplete] | None, + ) -> list[tuple[str, datetime.datetime]]: ... diff --git a/stubs/dateparser/dateparser/search/search.pyi b/stubs/dateparser/dateparser/search/search.pyi index 5e3c3d37dda2..274e86130e01 100644 --- a/stubs/dateparser/dateparser/search/search.pyi +++ b/stubs/dateparser/dateparser/search/search.pyi @@ -3,7 +3,7 @@ import re from _typeshed import Incomplete from collections import OrderedDict from collections.abc import Iterable, Sequence, Set as AbstractSet -from typing import Any, Final, TypedDict, type_check_only +from typing import Any, Final, Literal, TypedDict, type_check_only from dateparser.conf import Settings from dateparser.date import DateData, DateDataParser, _DetectLanguagesFunction @@ -72,5 +72,6 @@ class DateSearchWithDetection: languages: list[str] | tuple[str, ...] | AbstractSet[str] | None = None, settings: Settings | dict[str, Any] | None = None, detect_languages_function: _DetectLanguagesFunction | None = None, + strategy: Literal["split", "ngram"] = "split", ) -> _SearchDates: ... def preprocess_text(self, text: str, languages: Iterable[str] | None) -> str: ... diff --git a/stubs/dateparser/dateparser/timezone_parser.pyi b/stubs/dateparser/dateparser/timezone_parser.pyi index dbdbf8e73ece..e8be25d29462 100644 --- a/stubs/dateparser/dateparser/timezone_parser.pyi +++ b/stubs/dateparser/dateparser/timezone_parser.pyi @@ -15,6 +15,7 @@ class StaticTzInfo(tzinfo): def pop_tz_offset_from_string(date_string: str, as_offset: bool = True) -> tuple[str, StaticTzInfo | str | None]: ... def word_is_tz(word: str) -> bool: ... +def is_timezone_token(token: str) -> bool: ... def convert_to_local_tz(datetime_obj: _DateTimeT, datetime_tz_offset: timedelta) -> _DateTimeT: ... def build_tz_offsets(search_regex_parts: list[str]) -> Generator[tuple[str, dict[str, re.Pattern[str] | timedelta]]]: ... def get_local_tz_offset() -> timedelta: ...