Skip to content

Commit 1f6f368

Browse files
committed
[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
1 parent 843c1fd commit 1f6f368

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

stubs/python-dateutil/dateutil/parser/_parser.pyi

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ from _typeshed import SupportsRead
33
from collections.abc import Callable, Mapping
44
from datetime import _TzInfo, datetime
55
from io import StringIO
6-
from typing import IO, Any
6+
from typing import IO, Any, Literal, overload
77
from typing_extensions import Self, TypeAlias
88

99
_FileOrStr: TypeAlias = bytes | str | IO[str] | IO[Any]
@@ -77,6 +77,7 @@ class _ymd(list[int]):
7777
class parser:
7878
info: parserinfo
7979
def __init__(self, info: parserinfo | None = None) -> None: ...
80+
@overload
8081
def parse(
8182
self,
8283
timestr: _FileOrStr,
@@ -87,11 +88,25 @@ class parser:
8788
dayfirst: bool | None = ...,
8889
yearfirst: bool | None = ...,
8990
fuzzy: bool = ...,
90-
fuzzy_with_tokens: bool = ...,
91+
fuzzy_with_tokens: Literal[False] = ...,
9192
) -> datetime: ...
93+
@overload
94+
def parse(
95+
self,
96+
timestr: _FileOrStr,
97+
default: datetime | None = None,
98+
ignoretz: bool = False,
99+
tzinfos: _TzInfos | None = None,
100+
*,
101+
dayfirst: bool | None = ...,
102+
yearfirst: bool | None = ...,
103+
fuzzy: bool = ...,
104+
fuzzy_with_tokens: Literal[True] = ...,
105+
) -> tuple[datetime, tuple[str]]: ...
92106

93107
DEFAULTPARSER: parser
94108

109+
@overload
95110
def parse(
96111
timestr: _FileOrStr,
97112
parserinfo: parserinfo | None = None,
@@ -100,10 +115,23 @@ def parse(
100115
yearfirst: bool | None = ...,
101116
ignoretz: bool = ...,
102117
fuzzy: bool = ...,
103-
fuzzy_with_tokens: bool = ...,
118+
fuzzy_with_tokens: Literal[False] = ...,
104119
default: datetime | None = ...,
105120
tzinfos: _TzInfos | None = ...,
106121
) -> datetime: ...
122+
@overload
123+
def parse(
124+
timestr: _FileOrStr,
125+
parserinfo: parserinfo | None = None,
126+
*,
127+
dayfirst: bool | None = ...,
128+
yearfirst: bool | None = ...,
129+
ignoretz: bool = ...,
130+
fuzzy: bool = ...,
131+
fuzzy_with_tokens: Literal[True] = ...,
132+
default: datetime | None = ...,
133+
tzinfos: _TzInfos | None = ...,
134+
) -> tuple[datetime, tuple[str]]: ...
107135

108136
class _tzparser:
109137
class _result(_resultbase):

0 commit comments

Comments
 (0)