Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve dateparser #13796

Merged
merged 1 commit into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions stubs/dateparser/dateparser/calendars/hijri.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import Any

from dateparser.calendars import CalendarBase
from dateparser.calendars.hijri_parser import hijri_parser

class HijriCalendar(CalendarBase):
parser: Any
parser: type[hijri_parser]
15 changes: 8 additions & 7 deletions stubs/dateparser/dateparser/calendars/hijri_parser.pyi
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
from _typeshed import Incomplete
from typing import Any
from typing import Any, SupportsIndex

from dateparser.calendars import non_gregorian_parser

class hijri:
@classmethod
def to_gregorian(cls, year: Incomplete | None = ..., month: Incomplete | None = ..., day: Incomplete | None = ...): ...
def to_gregorian(cls, year: int | None = None, month: int | None = None, day: int | None = None) -> tuple[int, int, int]: ...
@classmethod
def from_gregorian(cls, year: Incomplete | None = ..., month: Incomplete | None = ..., day: Incomplete | None = ...): ...
def from_gregorian(
cls, year: SupportsIndex | None = None, month: SupportsIndex | None = None, day: SupportsIndex | None = None
) -> tuple[int, int, int]: ...
@classmethod
def month_length(cls, year, month): ...
def month_length(cls, year: int, month: int) -> int: ...

class HijriDate:
year: Any
Expand All @@ -19,9 +20,9 @@ class HijriDate:
def weekday(self): ...

class hijri_parser(non_gregorian_parser):
calendar_converter: Any
calendar_converter: type[hijri]
default_year: int
default_month: int
default_day: int
non_gregorian_date_cls: Any
non_gregorian_date_cls: type[HijriDate]
def handle_two_digit_year(self, year: int) -> int: ...
4 changes: 2 additions & 2 deletions stubs/dateparser/dateparser/calendars/jalali.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any
from dateparser.calendars.jalali_parser import jalali_parser

from . import CalendarBase

class JalaliCalendar(CalendarBase):
parser: Any
parser: type[jalali_parser]
2 changes: 1 addition & 1 deletion stubs/dateparser/dateparser/calendars/jalali_parser.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ class jalali_parser(non_gregorian_parser):
default_year: int
default_month: int
default_day: int
non_gregorian_date_cls: Any
non_gregorian_date_cls: type[PersianDate]
def handle_two_digit_year(self, year: int) -> int: ...
11 changes: 5 additions & 6 deletions stubs/dateparser/dateparser/conf.pyi
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
from _typeshed import Incomplete
from typing import Any
from typing_extensions import Self

class Settings:
def __new__(cls, *args, **kw) -> Self: ...
def __init__(self, settings: Incomplete | None = None) -> None: ...
def __init__(self, settings: dict[str, Any] | None = None) -> None: ...
@classmethod
def get_key(cls, settings: Incomplete | None = None): ...
def replace(self, mod_settings: Incomplete | None = None, **kwds): ...
def get_key(cls, settings: dict[str, Any] | None = None) -> str: ...
def replace(self, mod_settings: dict[str, Any] | None = None, **kwds) -> Self: ...

settings: Any
settings: Settings

def apply_settings(f): ...

class SettingValidationError(ValueError): ...

def check_settings(settings) -> None: ...
def check_settings(settings: Settings) -> None: ...
8 changes: 5 additions & 3 deletions stubs/dateparser/dateparser/data/languages_info.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
language_order: list[str]
language_locale_dict: dict[str, str]
language_map: dict[str, list[str]]
from typing import Final

language_order: Final[list[str]]
language_locale_dict: Final[dict[str, str]]
language_map: Final[dict[str, list[str]]]
36 changes: 18 additions & 18 deletions stubs/dateparser/dateparser/date.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import collections
from collections.abc import Callable, Iterable, Iterator
from datetime import datetime
from datetime import datetime, tzinfo
from re import Pattern
from typing import ClassVar, Literal, overload
from typing import ClassVar, Final, Literal, overload
from typing_extensions import TypeAlias

from dateparser import _Settings
Expand All @@ -13,23 +13,23 @@ from dateparser.languages.locale import Locale
_DetectLanguagesFunction: TypeAlias = Callable[[str, float], list[str]]
_Period: TypeAlias = Literal["time", "day", "week", "month", "year"]

APOSTROPHE_LOOK_ALIKE_CHARS: list[str]
RE_NBSP: Pattern[str]
RE_SPACES: Pattern[str]
RE_TRIM_SPACES: Pattern[str]
RE_TRIM_COLONS: Pattern[str]
RE_SANITIZE_SKIP: Pattern[str]
RE_SANITIZE_RUSSIAN: Pattern[str]
RE_SANITIZE_PERIOD: Pattern[str]
RE_SANITIZE_ON: Pattern[str]
RE_SANITIZE_APOSTROPHE: Pattern[str]
RE_SEARCH_TIMESTAMP: Pattern[str]
RE_SANITIZE_CROATIAN: Pattern[str]
RE_SEARCH_NEGATIVE_TIMESTAMP: Pattern[str]
APOSTROPHE_LOOK_ALIKE_CHARS: Final[list[str]]
RE_NBSP: Final[Pattern[str]]
RE_SPACES: Final[Pattern[str]]
RE_TRIM_SPACES: Final[Pattern[str]]
RE_TRIM_COLONS: Final[Pattern[str]]
RE_SANITIZE_SKIP: Final[Pattern[str]]
RE_SANITIZE_RUSSIAN: Final[Pattern[str]]
RE_SANITIZE_PERIOD: Final[Pattern[str]]
RE_SANITIZE_ON: Final[Pattern[str]]
RE_SANITIZE_APOSTROPHE: Final[Pattern[str]]
RE_SEARCH_TIMESTAMP: Final[Pattern[str]]
RE_SANITIZE_CROATIAN: Final[Pattern[str]]
RE_SEARCH_NEGATIVE_TIMESTAMP: Final[Pattern[str]]

def sanitize_spaces(date_string: str) -> str: ...
def date_range(begin, end, **kwargs) -> None: ...
def get_intersecting_periods(low, high, period: str = "day") -> None: ...
def date_range(begin: datetime, end: datetime, **kwargs) -> None: ...
def get_intersecting_periods(low: datetime, high: datetime, period: str = "day") -> None: ...
def sanitize_date(date_string: str) -> str: ...
def get_date_from_timestamp(date_string: str, settings: Settings, negative: bool = False) -> datetime | None: ...
def parse_with_formats(date_string: str, date_formats: Iterable[str], settings: Settings) -> DateData: ...
Expand Down Expand Up @@ -58,7 +58,7 @@ class _DateLocaleParser:
def _try_freshness_parser(self) -> DateData | None: ...
def _try_absolute_parser(self) -> DateData | None: ...
def _try_nospaces_parser(self) -> DateData | None: ...
def _try_parser(self, parse_method) -> DateData | None: ...
def _try_parser(self, parse_method: Callable[[str, Settings, tzinfo | None], tuple[datetime, str]]) -> DateData | None: ...
def _try_given_formats(self) -> DateData | None: ...
def _get_translated_date(self) -> str: ...
def _get_translated_date_with_formatting(self) -> str: ...
Expand Down
15 changes: 11 additions & 4 deletions stubs/dateparser/dateparser/date_parser.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
from _typeshed import Incomplete
from typing import Any
from collections.abc import Callable
from datetime import datetime, tzinfo

from dateparser.conf import Settings

class DateParser:
def parse(self, date_string, parse_method, settings: Incomplete | None = None): ...
def parse(
self,
date_string: str,
parse_method: Callable[[str, Settings, tzinfo | None], tuple[datetime, str]],
settings: Settings | None = None,
) -> tuple[datetime, str]: ...

date_parser: Any
date_parser: DateParser
18 changes: 11 additions & 7 deletions stubs/dateparser/dateparser/freshness_date_parser.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import re
from _typeshed import Incomplete
from typing import Any
from typing import Final
from zoneinfo import ZoneInfo

PATTERN: Any
from dateparser.date import DateData

PATTERN: Final[re.Pattern[str]]

class FreshnessDateDataParser:
def get_local_tz(self): ...
def parse(self, date_string, settings): ...
def get_kwargs(self, date_string): ...
def get_date_data(self, date_string, settings: Incomplete | None = None): ...
def get_local_tz(self) -> ZoneInfo: ...
def parse(self, date_string: str, settings) -> tuple[Incomplete | None, str | None]: ...
def get_kwargs(self, date_string: str) -> dict[str, float]: ...
def get_date_data(self, date_string: str, settings: Incomplete | None = None) -> DateData: ...

freshness_date_parser: Any
freshness_date_parser: FreshnessDateDataParser
2 changes: 2 additions & 0 deletions stubs/dateparser/dateparser/languages/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .loader import default_loader as default_loader
from .locale import Locale as Locale
28 changes: 16 additions & 12 deletions stubs/dateparser/dateparser/languages/dictionary.pyi
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
import re
from _typeshed import Incomplete
from typing import Any
from typing import Any, Final, overload

PARSER_HARDCODED_TOKENS: Any
PARSER_KNOWN_TOKENS: Any
ALWAYS_KEEP_TOKENS: list[str]
KNOWN_WORD_TOKENS: Any
PARENTHESES_PATTERN: Any
NUMERAL_PATTERN: Any
KEEP_TOKEN_PATTERN: Any
PARSER_HARDCODED_TOKENS: Final[list[str]]
PARSER_KNOWN_TOKENS: Final[list[str]]
ALWAYS_KEEP_TOKENS: Final[list[str]]
KNOWN_WORD_TOKENS: Final[list[str]]
PARENTHESES_PATTERN: Final[re.Pattern[str]]
NUMERAL_PATTERN: Final[re.Pattern[str]]
KEEP_TOKEN_PATTERN: Final[re.Pattern[str]]

class UnknownTokenError(Exception): ...

class Dictionary:
info: Any
def __init__(self, locale_info, settings: Incomplete | None = None) -> None: ...
def __init__(self, locale_info: dict[str, Incomplete], settings: Incomplete | None = None) -> None: ...
def __contains__(self, key): ...
def __getitem__(self, key): ...
def __iter__(self) -> Any: ...
def are_tokens_valid(self, tokens): ...
def split(self, string, keep_formatting: bool = False): ...
def are_tokens_valid(self, tokens: list[str]) -> bool: ...
@overload
def split(self, string: None, keep_formatting: bool = False) -> None: ...
@overload
def split(self, string: str, keep_formatting: bool = False) -> list[str]: ...

class NormalizedDictionary(Dictionary):
def __init__(self, locale_info, settings: Incomplete | None = None) -> None: ...
def __init__(self, locale_info: dict[str, Incomplete], settings: Incomplete | None = None) -> None: ...
7 changes: 4 additions & 3 deletions stubs/dateparser/dateparser/languages/loader.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import re
from collections import OrderedDict
from collections.abc import Iterator
from typing import Any
from typing import Any, Final

from .locale import Locale

LOCALE_SPLIT_PATTERN: Any
LOCALE_SPLIT_PATTERN: Final[re.Pattern[str]]

class LocaleDataLoader:
def get_locale_map(
Expand All @@ -25,4 +26,4 @@ class LocaleDataLoader:
) -> Iterator[Locale]: ...
def get_locale(self, shortname: str) -> Locale: ...

default_loader: Any
default_loader: LocaleDataLoader
3 changes: 2 additions & 1 deletion stubs/dateparser/dateparser/languages/locale.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from re import Pattern
from typing import Final

from dateparser.conf import Settings

NUMERAL_PATTERN: Pattern[str]
NUMERAL_PATTERN: Final[Pattern[str]]

class Locale:
shortname: str
Expand Down
11 changes: 6 additions & 5 deletions stubs/dateparser/dateparser/languages/validation.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from typing import Any
from _typeshed import Incomplete
from logging import Logger

class LanguageValidator:
logger: Any
VALID_KEYS: Any
logger: Logger | None
VALID_KEYS: list[str]
@classmethod
def get_logger(cls): ...
def get_logger(cls) -> Logger: ...
@classmethod
def validate_info(cls, language_id, info): ...
def validate_info(cls, language_id, info: dict[str, Incomplete]) -> bool: ...
81 changes: 46 additions & 35 deletions stubs/dateparser/dateparser/parser.pyi
Original file line number Diff line number Diff line change
@@ -1,53 +1,64 @@
import collections
import datetime
import re
from _typeshed import Incomplete
from typing import Any
from collections.abc import Callable, Generator
from io import StringIO
from typing import Any, Final, Literal, overload

NSP_COMPATIBLE: Any
MERIDIAN: Any
MICROSECOND: Any
EIGHT_DIGIT: Any
HOUR_MINUTE_REGEX: Any
from dateparser.conf import Settings

def no_space_parser_eligibile(datestring): ...
def get_unresolved_attrs(parser_object): ...
NSP_COMPATIBLE: Final[re.Pattern[str]]
MERIDIAN: Final[re.Pattern[str]]
MICROSECOND: Final[re.Pattern[str]]
EIGHT_DIGIT: Final[re.Pattern[str]]
HOUR_MINUTE_REGEX: Final[re.Pattern[str]]

date_order_chart: Any
def no_space_parser_eligibile(datestring: str) -> bool: ...
def get_unresolved_attrs(
parser_object: object,
) -> tuple[list[Literal["year", "month", "day"]], list[Literal["year", "month", "day"]]]: ...

def resolve_date_order(order, lst: Incomplete | None = None): ...
date_order_chart: Final[dict[str, str]]

@overload
def resolve_date_order(order: str, lst: Literal[True]) -> list[str]: ...
@overload
def resolve_date_order(order: str, lst: Literal[False] | None = None) -> str: ...

class _time_parser:
time_directives: Any
def __call__(self, timestring): ...
time_directives: list[str]
def __call__(self, timestring: str) -> datetime.time: ...

time_parser: Any
time_parser: _time_parser

class _no_spaces_parser:
period: Any
date_formats: Any
period: dict[str, list[str]]
date_formats: dict[str, list[str]]
def __init__(self, *args, **kwargs): ...
@classmethod
def parse(cls, datestring, settings): ...
def parse(cls, datestring: str, settings: Settings) -> tuple[datetime.datetime, str]: ...

class _parser:
alpha_directives: Any
num_directives: Any
settings: Any
tokens: Any
filtered_tokens: Any
unset_tokens: Any
day: Any
month: Any
year: Any
time: Any
auto_order: Any
ordered_num_directives: Any
def __init__(self, tokens, settings): ...
alpha_directives: collections.OrderedDict[str, list[str]]
num_directives: dict[str, list[str]]
settings: Settings
tokens: list[tuple[Incomplete, Incomplete]]
filtered_tokens: list[tuple[Incomplete, Incomplete, int]]
unset_tokens: list[Incomplete]
day: int | None
month: int | None
year: int | None
time: Callable[[], datetime.time] | None
auto_order: list[str]
ordered_num_directives: collections.OrderedDict[str, list[str]]
def __init__(self, tokens, settings: Settings): ...
@classmethod
def parse(cls, datestring, settings, tz: datetime.tzinfo | None = None): ...
def parse(cls, datestring: str, settings: Settings, tz: datetime.tzinfo | None = None): ...

class tokenizer:
digits: str
letters: str
instream: Any
def __init__(self, ds) -> None: ...
def tokenize(self) -> None: ...
digits: Literal["0123456789:"]
letters: Literal["abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"]
instream: StringIO
def __init__(self, ds: str) -> None: ...
def tokenize(self) -> Generator[tuple[str, Literal[0, 1, 2]], Any, None]: ...
Loading