Skip to content

Commit e524443

Browse files
authored
[python-dateutil] add some missing parameter types (#14992)
1 parent f7ff48e commit e524443

File tree

5 files changed

+58
-53
lines changed

5 files changed

+58
-53
lines changed

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import re
2-
from _typeshed import Incomplete, SupportsRead
2+
from _typeshed import SupportsRead
33
from collections.abc import Callable, Mapping
44
from datetime import _TzInfo, datetime
55
from io import StringIO
@@ -58,22 +58,21 @@ class parserinfo:
5858
def convertyear(self, year: int, century_specified: bool = False) -> int: ...
5959
def validate(self, res: datetime) -> bool: ...
6060

61-
class _ymd(list[Incomplete]):
61+
class _ymd(list[int]):
6262
century_specified: bool
6363
dstridx: int | None
6464
mstridx: int | None
6565
ystridx: int | None
66-
def __init__(self, *args, **kwargs) -> None: ...
6766
@property
6867
def has_year(self) -> bool: ...
6968
@property
7069
def has_month(self) -> bool: ...
7170
@property
7271
def has_day(self) -> bool: ...
73-
def could_be_day(self, value): ...
74-
def append(self, val, label=None): ...
75-
def _resolve_from_stridxs(self, strids): ...
76-
def resolve_ymd(self, yearfirst: bool | None, dayfirst: bool | None): ...
72+
def could_be_day(self, value: int) -> bool: ...
73+
def append(self, val: str | int, label: str | None = None) -> None: ...
74+
def _resolve_from_stridxs(self, strids: dict[str, int]) -> tuple[int, int, int]: ...
75+
def resolve_ymd(self, yearfirst: bool | None, dayfirst: bool | None) -> tuple[int, int, int]: ...
7776

7877
class parser:
7978
info: parserinfo

stubs/python-dateutil/dateutil/rrule.pyi

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import datetime
2-
from _typeshed import Incomplete
3-
from collections.abc import Generator, Iterable, Iterator, Sequence
2+
from collections.abc import Callable, Generator, Iterable, Iterator, Mapping, Sequence
43
from typing import Final, Literal, overload
54
from typing_extensions import Self, TypeAlias
65

6+
from dateutil.parser._parser import _TzInfos
7+
78
from ._common import weekday as weekdaybase
89

910
__all__ = [
@@ -58,13 +59,15 @@ SU: weekday
5859
class rrulebase:
5960
def __init__(self, cache: bool | None = False) -> None: ...
6061
def __iter__(self) -> Iterator[datetime.datetime]: ...
61-
def __getitem__(self, item): ...
62-
def __contains__(self, item) -> bool: ...
62+
def __getitem__(self, item: int | slice) -> datetime.datetime: ...
63+
def __contains__(self, item: datetime.datetime) -> bool: ...
6364
def count(self) -> int | None: ...
64-
def before(self, dt, inc: bool = False): ...
65-
def after(self, dt, inc: bool = False): ...
66-
def xafter(self, dt, count=None, inc: bool = False) -> Generator[Incomplete]: ...
67-
def between(self, after, before, inc: bool = False, count: int = 1) -> list[Incomplete]: ...
65+
def before(self, dt: datetime.datetime, inc: bool = False): ...
66+
def after(self, dt: datetime.datetime, inc: bool = False): ...
67+
def xafter(self, dt: datetime.datetime, count: int | None = None, inc: bool = False) -> Generator[datetime.datetime]: ...
68+
def between(
69+
self, after: datetime.datetime, before: datetime.datetime, inc: bool = False, count: int = 1
70+
) -> list[datetime.datetime]: ...
6871

6972
class rrule(rrulebase):
7073
def __init__(
@@ -156,22 +159,22 @@ class _iterinfo:
156159

157160
class rruleset(rrulebase):
158161
class _genitem:
159-
dt: Incomplete
160-
genlist: list[Incomplete]
161-
gen: Incomplete
162-
def __init__(self, genlist, gen) -> None: ...
162+
dt: datetime.datetime
163+
genlist: list[Self]
164+
gen: Iterator[datetime.datetime]
165+
def __init__(self, genlist: list[Self], gen: Iterator[datetime.datetime]) -> None: ...
163166
def __next__(self) -> None: ...
164167
next = __next__
165-
def __lt__(self, other) -> bool: ...
166-
def __gt__(self, other) -> bool: ...
167-
def __eq__(self, other) -> bool: ...
168-
def __ne__(self, other) -> bool: ...
168+
def __lt__(self, other: Self) -> bool: ...
169+
def __gt__(self, other: Self) -> bool: ...
170+
def __eq__(self, other: object) -> bool: ...
171+
def __ne__(self, other: object) -> bool: ...
169172

170173
def __init__(self, cache: bool | None = False) -> None: ...
171174
def rrule(self, rrule: _RRule) -> None: ...
172-
def rdate(self, rdate) -> None: ...
173-
def exrule(self, exrule) -> None: ...
174-
def exdate(self, exdate) -> None: ...
175+
def rdate(self, rdate: datetime.datetime) -> None: ...
176+
def exrule(self, exrule: _RRule) -> None: ...
177+
def exdate(self, exdate: datetime.datetime) -> None: ...
175178

176179
class _rrulestr:
177180
@overload
@@ -185,8 +188,8 @@ class _rrulestr:
185188
unfold: bool = False,
186189
compatible: bool = False,
187190
ignoretz: bool = False,
188-
tzids=None,
189-
tzinfos=None,
191+
tzids: Callable[[str], datetime.tzinfo] | Mapping[str, datetime.tzinfo] | None = None,
192+
tzinfos: _TzInfos | None = None,
190193
) -> rruleset: ...
191194
@overload
192195
def __call__(
@@ -199,8 +202,8 @@ class _rrulestr:
199202
unfold: bool = False,
200203
forceset: bool = False,
201204
ignoretz: bool = False,
202-
tzids=None,
203-
tzinfos=None,
205+
tzids: Callable[[str], datetime.tzinfo] | Mapping[str, datetime.tzinfo] | None = None,
206+
tzinfos: _TzInfos | None = None,
204207
) -> rruleset: ...
205208
@overload
206209
def __call__(
@@ -213,8 +216,8 @@ class _rrulestr:
213216
forceset: bool = False,
214217
compatible: bool = False,
215218
ignoretz: bool = False,
216-
tzids=None,
217-
tzinfos=None,
219+
tzids: Callable[[str], datetime.tzinfo] | Mapping[str, datetime.tzinfo] | None = None,
220+
tzinfos: _TzInfos | None = None,
218221
) -> rrule | rruleset: ...
219222

220223
rrulestr: _rrulestr

stubs/python-dateutil/dateutil/tz/_common.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ class tzrangebase(_tzinfo):
2424
def fromutc(self, dt: datetime) -> datetime: ...
2525
def is_ambiguous(self, dt: datetime) -> bool: ...
2626
__hash__: ClassVar[None] # type: ignore[assignment]
27-
def __ne__(self, other): ...
27+
def __ne__(self, other: object) -> bool: ...
2828
__reduce__ = object.__reduce__

stubs/python-dateutil/dateutil/tz/tz.pyi

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import sys
2+
from _typeshed import Unused
23
from datetime import datetime, timedelta, tzinfo
3-
from typing import ClassVar, Literal, Protocol, TypeVar, type_check_only
4+
from typing import Any, ClassVar, Literal, Protocol, TypeVar, type_check_only
5+
from typing_extensions import Self
46

57
from ..relativedelta import relativedelta
68
from ._common import _tzinfo, enfold as enfold, tzrangebase
@@ -23,36 +25,36 @@ class tzutc(tzinfo):
2325
def tzname(self, dt: datetime | None) -> str: ...
2426
def is_ambiguous(self, dt: datetime | None) -> bool: ...
2527
def fromutc(self, dt: _DT) -> _DT: ...
26-
def __eq__(self, other): ...
28+
def __eq__(self, other: object) -> bool: ...
2729
__hash__: ClassVar[None] # type: ignore[assignment]
28-
def __ne__(self, other): ...
30+
def __ne__(self, other: object) -> bool: ...
2931
__reduce__ = object.__reduce__
3032

3133
UTC: tzutc
3234

3335
class tzoffset(tzinfo):
34-
def __init__(self, name, offset) -> None: ...
36+
def __init__(self, name: str | None, offset: float | timedelta) -> None: ...
3537
def utcoffset(self, dt: datetime | None) -> timedelta | None: ...
3638
def dst(self, dt: datetime | None) -> timedelta | None: ...
3739
def is_ambiguous(self, dt: datetime | None) -> bool: ...
3840
def tzname(self, dt: datetime | None) -> str: ...
3941
def fromutc(self, dt: _DT) -> _DT: ...
40-
def __eq__(self, other): ...
42+
def __eq__(self, other: object) -> bool: ...
4143
__hash__: ClassVar[None] # type: ignore[assignment]
42-
def __ne__(self, other): ...
44+
def __ne__(self, other: object) -> bool: ...
4345
__reduce__ = object.__reduce__
4446
@classmethod
45-
def instance(cls, name, offset) -> tzoffset: ...
47+
def instance(cls, name: str | None, offset: float | timedelta) -> tzoffset: ...
4648

4749
class tzlocal(_tzinfo):
4850
def __init__(self) -> None: ...
4951
def utcoffset(self, dt: datetime | None) -> timedelta | None: ...
5052
def dst(self, dt: datetime | None) -> timedelta | None: ...
5153
def tzname(self, dt: datetime | None) -> str: ...
5254
def is_ambiguous(self, dt: datetime | None) -> bool: ...
53-
def __eq__(self, other): ...
55+
def __eq__(self, other: object) -> bool: ...
5456
__hash__: ClassVar[None] # type: ignore[assignment]
55-
def __ne__(self, other): ...
57+
def __ne__(self, other: object) -> bool: ...
5658
__reduce__ = object.__reduce__
5759

5860
class _ttinfo:
@@ -65,9 +67,9 @@ class _ttinfo:
6567
isgmt: bool
6668
dstoffset: timedelta
6769
def __init__(self) -> None: ...
68-
def __eq__(self, other): ...
70+
def __eq__(self, other: object) -> bool: ...
6971
__hash__: ClassVar[None] # type: ignore[assignment]
70-
def __ne__(self, other): ...
72+
def __ne__(self, other: object) -> bool: ...
7173

7274
@type_check_only
7375
class _TZFileReader(Protocol):
@@ -82,11 +84,11 @@ class tzfile(_tzinfo):
8284
def utcoffset(self, dt: datetime | None) -> timedelta | None: ...
8385
def dst(self, dt: datetime | None) -> timedelta | None: ...
8486
def tzname(self, dt: datetime | None) -> str: ...
85-
def __eq__(self, other): ...
87+
def __eq__(self, other: object) -> bool: ...
8688
__hash__: ClassVar[None] # type: ignore[assignment]
87-
def __ne__(self, other): ...
88-
def __reduce__(self): ...
89-
def __reduce_ex__(self, protocol): ...
89+
def __ne__(self, other: object) -> bool: ...
90+
def __reduce__(self) -> tuple[type[Self], tuple[None, str], dict[str, Any]]: ...
91+
def __reduce_ex__(self, protocol: Unused) -> tuple[type[Self], tuple[None, str], dict[str, Any]]: ...
9092

9193
class tzrange(tzrangebase):
9294
hasdst: bool
@@ -100,13 +102,13 @@ class tzrange(tzrangebase):
100102
end: relativedelta | None = None,
101103
) -> None: ...
102104
def transitions(self, year: int) -> tuple[datetime, datetime]: ...
103-
def __eq__(self, other): ...
105+
def __eq__(self, other: object) -> bool: ...
104106

105107
class tzstr(tzrange):
106108
hasdst: bool
107109
def __init__(self, s: str, posix_offset: bool = False) -> None: ...
108110
@classmethod
109-
def instance(cls, name, offset) -> tzoffset: ...
111+
def instance(cls, name: str | None, offset: float | timedelta) -> tzoffset: ...
110112

111113
@type_check_only
112114
class _ICalReader(Protocol):
@@ -116,8 +118,8 @@ class _ICalReader(Protocol):
116118

117119
class tzical:
118120
def __init__(self, fileobj: str | _ICalReader) -> None: ...
119-
def keys(self): ...
120-
def get(self, tzid=None): ...
121+
def keys(self) -> list[str]: ...
122+
def get(self, tzid: str | None = None) -> tzinfo | None: ...
121123

122124
TZFILES: list[str]
123125
TZPATHS: list[str]

stubs/python-dateutil/dateutil/zoneinfo/__init__.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ ZONEFILENAME: Final[str]
1616
METADATA_FN: Final[str]
1717

1818
class tzfile(_tzfile):
19-
def __reduce__(self) -> tuple[Callable[[str], Self], tuple[str, ...]]: ...
19+
# source code does this override, changing the type
20+
def __reduce__(self) -> tuple[Callable[[str], Self], tuple[str]]: ... # type: ignore[override]
2021

2122
def getzoneinfofile_stream() -> BytesIO | None: ...
2223

0 commit comments

Comments
 (0)