Skip to content

Commit e18b99c

Browse files
authored
[icalendar] Update to 6.1.2 (#13672)
Finish icalendar.prop annotations
1 parent 506eceb commit e18b99c

File tree

4 files changed

+136
-91
lines changed

4 files changed

+136
-91
lines changed

stubs/icalendar/@tests/stubtest_allowlist.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,12 @@ icalendar.cal.Component.set_inline
1212

1313
# Stubtest gets confused by multiple inheritance.
1414
icalendar.prop.vSkip.__new__
15+
16+
# Stubtest incorrectly reports that stub argument "cls" should be
17+
# positional or keyword.
18+
icalendar.vBoolean.__new__
19+
icalendar.vFloat.__new__
20+
icalendar.vInt.__new__
21+
icalendar.prop.vBoolean.__new__
22+
icalendar.prop.vFloat.__new__
23+
icalendar.prop.vInt.__new__

stubs/icalendar/METADATA.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version = "6.1.*"
1+
version = "~= 6.1.2"
22
upstream_repository = "https://github.com/collective/icalendar"
33
requires = ["types-python-dateutil", "types-pytz"]
44

stubs/icalendar/icalendar/prop.pyi

Lines changed: 124 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import datetime
2-
from _typeshed import Incomplete, Unused
3-
from collections.abc import Iterator
2+
from _typeshed import ConvertibleToFloat, ConvertibleToInt, SupportsKeysAndGetItem, Unused
3+
from collections.abc import Iterable, Iterator
44
from enum import Enum
55
from re import Pattern
6-
from typing import Any, ClassVar, Final, TypeVar, overload
6+
from typing import Any, ClassVar, Final, Literal, Protocol, SupportsIndex, overload
77
from typing_extensions import Self, TypeAlias
88

99
from .caselessdict import CaselessDict
@@ -44,70 +44,80 @@ __all__ = [
4444
]
4545

4646
_PropType: TypeAlias = type[Any] # any of the v* classes in this file
47-
_vRecurT = TypeVar("_vRecurT", bound=vRecur)
47+
_PeriodTuple: TypeAlias = tuple[datetime.datetime, datetime.datetime | datetime.timedelta]
48+
_AnyTimeType: TypeAlias = datetime.datetime | datetime.date | datetime.timedelta | datetime.time | _PeriodTuple
49+
50+
class _vType(Protocol):
51+
def to_ical(self) -> bytes | str: ...
4852

4953
DURATION_REGEX: Final[Pattern[str]]
5054
WEEKDAY_RULE: Final[Pattern[str]]
5155

5256
class vBinary:
53-
obj: Incomplete
57+
obj: str
5458
params: Parameters
55-
def __init__(self, obj) -> None: ...
59+
def __init__(self, obj: str | bytes) -> None: ...
5660
def to_ical(self) -> bytes: ...
5761
@staticmethod
58-
def from_ical(ical): ...
59-
def __eq__(self, other): ...
62+
def from_ical(ical: ICAL_TYPE) -> bytes: ...
63+
def __eq__(self, other: object) -> bool: ...
6064

6165
class vBoolean(int):
62-
BOOL_MAP: Incomplete
66+
BOOL_MAP: Final[CaselessDict[bool]]
6367
params: Parameters
64-
def __new__(cls, *args, **kwargs): ...
65-
def to_ical(self) -> bytes: ...
68+
def __new__(cls, x: ConvertibleToInt = ..., /, *, params: SupportsKeysAndGetItem[str, str] = {}) -> Self: ...
69+
def to_ical(self) -> Literal[b"TRUE", b"FALSE"]: ...
6670
@classmethod
67-
def from_ical(cls, ical): ...
71+
def from_ical(cls, ical: ICAL_TYPE) -> bool: ...
6872

6973
class vText(str):
7074
encoding: str
7175
params: Parameters
72-
def __new__(cls, value: ICAL_TYPE, encoding: str = "utf-8") -> Self: ...
76+
def __new__(cls, value: ICAL_TYPE, encoding: str = "utf-8", params: SupportsKeysAndGetItem[str, str] = {}) -> Self: ...
7377
def to_ical(self) -> bytes: ...
7478
@classmethod
7579
def from_ical(cls, ical: ICAL_TYPE) -> Self: ...
7680

7781
class vCalAddress(str):
7882
params: Parameters
79-
def __new__(cls, value, encoding="utf-8"): ...
83+
def __new__(cls, value: ICAL_TYPE, encoding="utf-8", params: SupportsKeysAndGetItem[str, str] = {}) -> Self: ...
8084
def to_ical(self) -> bytes: ...
8185
@classmethod
82-
def from_ical(cls, ical): ...
86+
def from_ical(cls, ical: ICAL_TYPE) -> Self: ...
87+
@property
88+
def email(self) -> str: ...
89+
@property
90+
def name(self) -> str: ...
91+
@name.setter
92+
def name(self, value: str) -> None: ...
8393

8494
class vFloat(float):
8595
params: Parameters
86-
def __new__(cls, *args, **kwargs): ...
96+
def __new__(cls, x: ConvertibleToFloat = ..., /, *, params: SupportsKeysAndGetItem[str, str] = {}) -> Self: ...
8797
def to_ical(self) -> bytes: ...
8898
@classmethod
89-
def from_ical(cls, ical): ...
99+
def from_ical(cls, ical: ICAL_TYPE) -> Self: ...
90100

91101
class vInt(int):
92102
params: Parameters
93-
def __new__(cls, *args, **kwargs): ...
103+
def __new__(cls, x: ConvertibleToInt = ..., /, *, params: SupportsKeysAndGetItem[str, str] = {}) -> Self: ...
94104
def to_ical(self) -> bytes: ...
95105
@classmethod
96106
def from_ical(cls, ical: ICAL_TYPE) -> Self: ...
97107

98108
class vDDDLists:
99109
params: Parameters
100-
dts: Incomplete
101-
def __init__(self, dt_list) -> None: ...
110+
dts: list[vDDDTypes]
111+
def __init__(self, dt_list: Iterable[_AnyTimeType] | _AnyTimeType) -> None: ...
102112
def to_ical(self) -> bytes: ...
103113
@staticmethod
104-
def from_ical(ical, timezone: Incomplete | None = None): ...
105-
def __eq__(self, other): ...
114+
def from_ical(ical: str, timezone: str | datetime.timezone | None = None): ...
115+
def __eq__(self, other: object) -> bool: ...
106116

107117
class vCategory:
108-
cats: Incomplete
118+
cats: list[vText]
109119
params: Parameters
110-
def __init__(self, c_list) -> None: ...
120+
def __init__(self, c_list: Iterable[ICAL_TYPE] | ICAL_TYPE, params: SupportsKeysAndGetItem[str, str] = {}) -> None: ...
111121
def __iter__(self) -> Iterator[str]: ...
112122
def to_ical(self) -> bytes: ...
113123
@staticmethod
@@ -116,80 +126,95 @@ class vCategory:
116126

117127
class TimeBase:
118128
def __eq__(self, other: object) -> bool: ...
119-
def __hash__(self): ...
129+
def __hash__(self) -> int: ...
120130

121131
class vDDDTypes(TimeBase):
122132
params: Parameters
123-
dt: Incomplete
124-
def __init__(self, dt) -> None: ...
133+
dt: _AnyTimeType
134+
def __init__(self, dt: _AnyTimeType) -> None: ...
125135
def to_ical(self) -> bytes: ...
136+
@overload
126137
@classmethod
127-
def from_ical(cls, ical, timezone: Incomplete | None = None): ...
138+
def from_ical(cls, ical: Self, timezone: Unused | None = None) -> _AnyTimeType: ...
139+
# Return type is one of vDuration, vPeriod, vDatetime, vDate, or vTime,
140+
# depending on the ical string.
141+
@overload
142+
@classmethod
143+
def from_ical(cls, ical: str, timezone: datetime.timezone | str | None = None) -> Any: ...
128144

129145
class vDate(TimeBase):
130-
dt: Incomplete
146+
dt: datetime.date
131147
params: Parameters
132-
def __init__(self, dt) -> None: ...
148+
def __init__(self, dt: datetime.date) -> None: ...
133149
def to_ical(self) -> bytes: ...
134150
@staticmethod
135-
def from_ical(ical): ...
151+
def from_ical(ical: ICAL_TYPE) -> datetime.date: ...
136152

137153
class vDatetime(TimeBase):
138-
dt: Incomplete
154+
dt: datetime.datetime
139155
params: Parameters
140-
def __init__(self, dt) -> None: ...
156+
def __init__(self, dt: datetime.datetime, params: SupportsKeysAndGetItem[str, str] = {}) -> None: ...
141157
def to_ical(self) -> bytes: ...
142158
@staticmethod
143-
def from_ical(ical, timezone: datetime.timezone | str | None = None) -> datetime.datetime: ...
159+
def from_ical(ical: ICAL_TYPE, timezone: datetime.timezone | str | None = None) -> datetime.datetime: ...
144160

145161
class vDuration(TimeBase):
146-
td: Incomplete
162+
td: datetime.timedelta
147163
params: Parameters
148-
def __init__(self, td) -> None: ...
164+
def __init__(self, td: datetime.timedelta, params: SupportsKeysAndGetItem[str, str] = {}) -> None: ...
149165
def to_ical(self) -> bytes: ...
150166
@staticmethod
151-
def from_ical(ical): ...
167+
def from_ical(ical: str) -> datetime.timedelta: ...
152168
@property
153-
def dt(self): ...
169+
def dt(self) -> datetime.timedelta: ...
154170

155171
class vPeriod(TimeBase):
156172
params: Parameters
157-
start: Incomplete
158-
end: Incomplete
159-
by_duration: Incomplete
160-
duration: Incomplete
161-
def __init__(self, per) -> None: ...
162-
def overlaps(self, other): ...
173+
start: datetime.datetime
174+
end: datetime.datetime
175+
by_duration: bool
176+
duration: datetime.timedelta
177+
def __init__(self, per: _PeriodTuple) -> None: ...
178+
def overlaps(self, other: vPeriod) -> bool: ...
163179
def to_ical(self) -> bytes: ...
180+
# Return type is a tuple of vDuration, vPeriod, vDatetime, vDate, or vTime,
181+
# depending on the ical string. If the ical string is formed according to
182+
# the iCalendar specification, this should always return a
183+
# (datetime, datetime) or a (datetime, timedelta) tuple, but this is not
184+
# enforced.
164185
@staticmethod
165-
def from_ical(ical, timezone: Incomplete | None = None): ...
186+
def from_ical(ical: str, timezone: datetime.timezone | str | None = None) -> tuple[Any, Any]: ...
166187
@property
167-
def dt(self): ...
188+
def dt(self) -> _PeriodTuple: ...
168189

169190
class vWeekday(str):
170-
week_days: Incomplete
171-
relative: Incomplete
191+
week_days: Final[CaselessDict[int]]
192+
weekday: Literal["SU", "MO", "TU", "WE", "TH", "FR", "SA"] | None
193+
relative: int | None
172194
params: Parameters
173-
def __new__(cls, value, encoding="utf-8"): ...
195+
def __new__(cls, value: ICAL_TYPE, encoding: str = "utf-8", params: SupportsKeysAndGetItem[str, str] = {}) -> Self: ...
174196
def to_ical(self) -> bytes: ...
175197
@classmethod
176-
def from_ical(cls, ical): ...
198+
def from_ical(cls, ical: ICAL_TYPE) -> Self: ...
177199

178200
class vFrequency(str):
179-
frequencies: Incomplete
201+
frequencies: Final[CaselessDict[str]]
180202
params: Parameters
181-
def __new__(cls, value, encoding="utf-8"): ...
203+
def __new__(cls, value: ICAL_TYPE, encoding: str = "utf-8", params: SupportsKeysAndGetItem[str, str] = {}) -> Self: ...
182204
def to_ical(self) -> bytes: ...
183205
@classmethod
184-
def from_ical(cls, ical): ...
206+
def from_ical(cls, ical: ICAL_TYPE) -> Self: ...
185207

186208
class vMonth(int):
187-
leap: bool
188209
params: Parameters
189-
def __new__(cls, month: vMonth | str | int) -> Self: ...
210+
def __new__(cls, month: vMonth | str | int, params: SupportsKeysAndGetItem[str, str] = {}) -> Self: ...
190211
def to_ical(self) -> bytes: ...
191212
@classmethod
192213
def from_ical(cls, ical: vMonth | str | int) -> Self: ...
214+
@property
215+
def leap(self) -> bool: ...
216+
@leap.setter
217+
def leap(self, value: bool) -> None: ...
193218

194219
class vSkip(vText, Enum):
195220
OMIT = "OMIT"
@@ -198,69 +223,82 @@ class vSkip(vText, Enum):
198223

199224
def __reduce_ex__(self, proto: Unused) -> tuple[Any, ...]: ...
200225

201-
class vRecur(CaselessDict[Incomplete]):
202-
frequencies: ClassVar[list[str]]
203-
canonical_order: ClassVar[tuple[str, ...]]
204-
types: ClassVar[CaselessDict[_PropType]]
226+
# The type of the values depend on the key. Each key maps to a v* class, and
227+
# the allowed types are the types that the corresponding v* class can parse.
228+
class vRecur(CaselessDict[Iterable[Any] | Any]):
205229
params: Parameters
206-
def __init__(self, *args, **kwargs) -> None: ...
230+
frequencies: Final[list[str]]
231+
canonical_order: ClassVar[tuple[str, ...]]
232+
types: Final[CaselessDict[_PropType]]
233+
def __init__(
234+
self, *args, params: SupportsKeysAndGetItem[str, str] = {}, **kwargs: list[Any] | tuple[Any, ...] | Any
235+
) -> None: ...
207236
def to_ical(self) -> bytes: ...
208237
@classmethod
209-
def parse_type(cls, key, values): ...
238+
def parse_type(cls, key: str, values: str) -> list[Any]: ... # Returns a list of v* objects
210239
@classmethod
211-
@overload
212-
def from_ical(cls, ical: _vRecurT) -> _vRecurT: ...
213-
@classmethod
214-
@overload
215-
def from_ical(cls, ical: str) -> Self: ...
240+
def from_ical(cls, ical: vRecur | str) -> Self: ...
216241

217242
class vTime(TimeBase):
218-
dt: Incomplete
243+
dt: datetime.time | datetime.datetime
219244
params: Parameters
220-
def __init__(self, *args) -> None: ...
221-
def to_ical(self) -> bytes: ...
245+
@overload
246+
def __init__(self, dt: datetime.time | datetime.datetime, /) -> None: ...
247+
# args are passed to the datetime.time() constructor
248+
@overload
249+
def __init__(
250+
self,
251+
hour: SupportsIndex = ...,
252+
minute: SupportsIndex = ...,
253+
second: SupportsIndex = ...,
254+
microsecond: SupportsIndex = ...,
255+
tzinfo: datetime.tzinfo | None = ...,
256+
/,
257+
) -> None: ...
258+
def to_ical(self) -> str: ...
222259
@staticmethod
223-
def from_ical(ical): ...
260+
def from_ical(ical: ICAL_TYPE) -> datetime.time: ...
224261

225262
class vUri(str):
226263
params: Parameters
227-
def __new__(cls, value, encoding="utf-8"): ...
264+
def __new__(cls, value: ICAL_TYPE, encoding: str = "utf-8", params: SupportsKeysAndGetItem[str, str] = {}) -> Self: ...
228265
def to_ical(self) -> bytes: ...
229266
@classmethod
230-
def from_ical(cls, ical): ...
267+
def from_ical(cls, ical: ICAL_TYPE) -> Self: ...
231268

232269
class vGeo:
233-
latitude: Incomplete
234-
longitude: Incomplete
270+
latitude: float
271+
longitude: float
235272
params: Parameters
236-
def __init__(self, geo) -> None: ...
237-
def to_ical(self) -> bytes: ...
273+
def __init__(self, geo: tuple[float | str, float | str], params: SupportsKeysAndGetItem[str, str] = {}) -> None: ...
274+
def to_ical(self) -> str: ...
238275
@staticmethod
239-
def from_ical(ical): ...
240-
def __eq__(self, other): ...
276+
def from_ical(ical: str) -> tuple[float, float]: ...
277+
def __eq__(self, other: _vType) -> bool: ... # type: ignore[override]
241278

242279
class vUTCOffset:
243280
ignore_exceptions: bool
244281
td: datetime.timedelta
245282
params: Parameters
246-
def __init__(self, td: datetime.timedelta) -> None: ...
247-
def to_ical(self) -> bytes: ...
283+
def __init__(self, td: datetime.timedelta, params: SupportsKeysAndGetItem[str, str] = {}) -> None: ...
284+
def to_ical(self) -> str: ...
248285
@classmethod
249-
def from_ical(cls, ical): ...
286+
def from_ical(cls, ical: Self | ICAL_TYPE) -> datetime.timedelta: ...
250287
def __eq__(self, other: object) -> bool: ...
251288
def __hash__(self) -> int: ...
252289

253290
class vInline(str):
254291
params: Parameters
255-
def __new__(cls, value, encoding="utf-8"): ...
292+
def __new__(cls, value: ICAL_TYPE, encoding: str = "utf-8", params: SupportsKeysAndGetItem[str, str] = {}) -> Self: ...
256293
def to_ical(self) -> bytes: ...
257294
@classmethod
258-
def from_ical(cls, ical): ...
295+
def from_ical(cls, ical: ICAL_TYPE) -> Self: ...
259296

260297
class TypesFactory(CaselessDict[_PropType]):
261298
all_types: tuple[_PropType, ...]
262-
def __init__(self, *args, **kwargs) -> None: ...
263299
types_map: CaselessDict[str]
264300
def for_property(self, name: str) -> _PropType: ...
265-
def to_ical(self, name: str, value) -> bytes: ...
266-
def from_ical(self, name: str, value): ...
301+
# value is str | bytes, depending on what the v* class supports
302+
def to_ical(self, name: str, value: Any) -> bytes: ...
303+
# value and return type depend on what the v* class supports
304+
def from_ical(self, name: str, value: Any) -> Any: ...

stubs/icalendar/icalendar/timezone/equivalent_timezone_ids.pyi

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ from typing import Final
44

55
__all__ = ["main"]
66

7-
def check(dt: datetime.datetime, tz: datetime.tzinfo) -> tuple[datetime.datetime, datetime.timedelta]: ...
8-
def checks(tz: datetime.tzinfo) -> list[tuple[datetime.datetime, datetime.timedelta]]: ...
9-
107
START: Final[datetime.datetime]
118
END: Final[datetime.datetime]
9+
DISTANCE_FROM_TIMEZONE_CHANGE: Final[datetime.timedelta]
1210

1311
DTS: Final[list[datetime.datetime]]
1412

15-
def main(create_timezones: list[Callable[[str], datetime.tzinfo]], name: str, pool_size: int = ...) -> None: ...
13+
def main(create_timezones: list[Callable[[str], datetime.tzinfo]], name: str) -> None: ...

0 commit comments

Comments
 (0)