From 1f6f368735cda6cbbe742f227a9cf210fb63a57d Mon Sep 17 00:00:00 2001 From: ellieayla <1447600+me@users.noreply.github.com> Date: Sat, 28 Feb 2026 13:09:27 -0500 Subject: [PATCH 1/4] [python-dateutil] dateutil.parser.parse(fuzzy_with_tokens=True) returns a tuple @overload the parse function at module and class level, separate return type for fuzzy_with_tokens: Literal[True] and Literal[False]. Note, not entirely sure this syntax is perfect. mypy is happy locally, but that doesn't check against the upstream library behaviour. Could use a second pair of eyes. Closes issue #15473 ref: https://github.com/dateutil/dateutil/blob/e081f6725fbb49cae6eedab7010f517e8490859b/src/dateutil/parser/_parser.py#L702 https://github.com/dateutil/dateutil/blob/e081f6725fbb49cae6eedab7010f517e8490859b/src/dateutil/parser/_parser.py#L871 --- .../dateutil/parser/_parser.pyi | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/stubs/python-dateutil/dateutil/parser/_parser.pyi b/stubs/python-dateutil/dateutil/parser/_parser.pyi index 9119ec25d7b7..cb6c1eeb6aa2 100644 --- a/stubs/python-dateutil/dateutil/parser/_parser.pyi +++ b/stubs/python-dateutil/dateutil/parser/_parser.pyi @@ -3,7 +3,7 @@ from _typeshed import SupportsRead from collections.abc import Callable, Mapping from datetime import _TzInfo, datetime from io import StringIO -from typing import IO, Any +from typing import IO, Any, Literal, overload from typing_extensions import Self, TypeAlias _FileOrStr: TypeAlias = bytes | str | IO[str] | IO[Any] @@ -77,6 +77,7 @@ class _ymd(list[int]): class parser: info: parserinfo def __init__(self, info: parserinfo | None = None) -> None: ... + @overload def parse( self, timestr: _FileOrStr, @@ -87,11 +88,25 @@ class parser: dayfirst: bool | None = ..., yearfirst: bool | None = ..., fuzzy: bool = ..., - fuzzy_with_tokens: bool = ..., + fuzzy_with_tokens: Literal[False] = ..., ) -> datetime: ... + @overload + def parse( + self, + timestr: _FileOrStr, + default: datetime | None = None, + ignoretz: bool = False, + tzinfos: _TzInfos | None = None, + *, + dayfirst: bool | None = ..., + yearfirst: bool | None = ..., + fuzzy: bool = ..., + fuzzy_with_tokens: Literal[True] = ..., + ) -> tuple[datetime, tuple[str]]: ... DEFAULTPARSER: parser +@overload def parse( timestr: _FileOrStr, parserinfo: parserinfo | None = None, @@ -100,10 +115,23 @@ def parse( yearfirst: bool | None = ..., ignoretz: bool = ..., fuzzy: bool = ..., - fuzzy_with_tokens: bool = ..., + fuzzy_with_tokens: Literal[False] = ..., default: datetime | None = ..., tzinfos: _TzInfos | None = ..., ) -> datetime: ... +@overload +def parse( + timestr: _FileOrStr, + parserinfo: parserinfo | None = None, + *, + dayfirst: bool | None = ..., + yearfirst: bool | None = ..., + ignoretz: bool = ..., + fuzzy: bool = ..., + fuzzy_with_tokens: Literal[True] = ..., + default: datetime | None = ..., + tzinfos: _TzInfos | None = ..., +) -> tuple[datetime, tuple[str]]: ... class _tzparser: class _result(_resultbase): From 7885fd11745f43e2f90e87592686b56d34bf6408 Mon Sep 17 00:00:00 2001 From: Ellie <1447600+ellieayla@users.noreply.github.com> Date: Sat, 28 Feb 2026 16:55:05 -0500 Subject: [PATCH 2/4] Update stubs/python-dateutil/dateutil/parser/_parser.pyi Co-authored-by: Semyon Moroz --- stubs/python-dateutil/dateutil/parser/_parser.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/python-dateutil/dateutil/parser/_parser.pyi b/stubs/python-dateutil/dateutil/parser/_parser.pyi index cb6c1eeb6aa2..fabd149c1cfd 100644 --- a/stubs/python-dateutil/dateutil/parser/_parser.pyi +++ b/stubs/python-dateutil/dateutil/parser/_parser.pyi @@ -131,7 +131,7 @@ def parse( fuzzy_with_tokens: Literal[True] = ..., default: datetime | None = ..., tzinfos: _TzInfos | None = ..., -) -> tuple[datetime, tuple[str]]: ... +) -> tuple[datetime, tuple[str, ...]]: ... class _tzparser: class _result(_resultbase): From ae58483fde90cba53d6b791334659db075db4f42 Mon Sep 17 00:00:00 2001 From: Ellie <1447600+ellieayla@users.noreply.github.com> Date: Sat, 28 Feb 2026 16:55:16 -0500 Subject: [PATCH 3/4] Update stubs/python-dateutil/dateutil/parser/_parser.pyi Co-authored-by: Semyon Moroz --- stubs/python-dateutil/dateutil/parser/_parser.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/python-dateutil/dateutil/parser/_parser.pyi b/stubs/python-dateutil/dateutil/parser/_parser.pyi index fabd149c1cfd..b5a26aa82d62 100644 --- a/stubs/python-dateutil/dateutil/parser/_parser.pyi +++ b/stubs/python-dateutil/dateutil/parser/_parser.pyi @@ -102,7 +102,7 @@ class parser: yearfirst: bool | None = ..., fuzzy: bool = ..., fuzzy_with_tokens: Literal[True] = ..., - ) -> tuple[datetime, tuple[str]]: ... + ) -> tuple[datetime, tuple[str, ...]]: ... DEFAULTPARSER: parser From 997b743077920a327c0d048670eff8f92be6e820 Mon Sep 17 00:00:00 2001 From: Ellie <1447600+ellieayla@users.noreply.github.com> Date: Sun, 1 Mar 2026 21:57:50 +0000 Subject: [PATCH 4/4] Apply suggestions from code review Co-authored-by: Brian Schubert --- stubs/python-dateutil/dateutil/parser/_parser.pyi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stubs/python-dateutil/dateutil/parser/_parser.pyi b/stubs/python-dateutil/dateutil/parser/_parser.pyi index b5a26aa82d62..94fc991691a1 100644 --- a/stubs/python-dateutil/dateutil/parser/_parser.pyi +++ b/stubs/python-dateutil/dateutil/parser/_parser.pyi @@ -88,7 +88,7 @@ class parser: dayfirst: bool | None = ..., yearfirst: bool | None = ..., fuzzy: bool = ..., - fuzzy_with_tokens: Literal[False] = ..., + fuzzy_with_tokens: Literal[False] = False, ) -> datetime: ... @overload def parse( @@ -101,7 +101,7 @@ class parser: dayfirst: bool | None = ..., yearfirst: bool | None = ..., fuzzy: bool = ..., - fuzzy_with_tokens: Literal[True] = ..., + fuzzy_with_tokens: Literal[True], ) -> tuple[datetime, tuple[str, ...]]: ... DEFAULTPARSER: parser @@ -115,7 +115,7 @@ def parse( yearfirst: bool | None = ..., ignoretz: bool = ..., fuzzy: bool = ..., - fuzzy_with_tokens: Literal[False] = ..., + fuzzy_with_tokens: Literal[False] = False, default: datetime | None = ..., tzinfos: _TzInfos | None = ..., ) -> datetime: ... @@ -128,7 +128,7 @@ def parse( yearfirst: bool | None = ..., ignoretz: bool = ..., fuzzy: bool = ..., - fuzzy_with_tokens: Literal[True] = ..., + fuzzy_with_tokens: Literal[True], default: datetime | None = ..., tzinfos: _TzInfos | None = ..., ) -> tuple[datetime, tuple[str, ...]]: ...