Skip to content

Commit fd7481c

Browse files
authored
[icalendar] Use stricter pyright settings (#15159)
1 parent d8d9892 commit fd7481c

File tree

7 files changed

+26
-23
lines changed

7 files changed

+26
-23
lines changed

pyrightconfig.stricter.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@
4949
"stubs/html5lib",
5050
"stubs/httplib2",
5151
"stubs/hvac",
52-
"stubs/icalendar",
52+
"stubs/icalendar/icalendar/prop.pyi",
53+
"stubs/icalendar/icalendar/timezone/provider.pyi",
5354
"stubs/jsonschema",
5455
"stubs/jwcrypto",
5556
"stubs/ldap3",

stubs/icalendar/@tests/stubtest_allowlist.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ icalendar\.tests(\..*)?
66

77
# Methods that use `int` to mean `bool`.
88
icalendar.Component.get_inline
9-
icalendar.Component.set_inline
109
icalendar.cal.Component.get_inline
11-
icalendar.cal.Component.set_inline
1210

1311
# Stubtest gets confused by multiple inheritance.
1412
icalendar.prop.vSkip.__new__

stubs/icalendar/icalendar/alarms.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class AlarmTime:
2121
acknowledged_until: datetime.datetime | None = None,
2222
snoozed_until: datetime.datetime | None = None,
2323
parent: Parent | None = None,
24-
): ...
24+
) -> None: ...
2525
@property
2626
def acknowledged(self) -> datetime.datetime | None: ...
2727
@property
@@ -33,7 +33,7 @@ class AlarmTime:
3333
def trigger(self) -> datetime.date: ...
3434

3535
class Alarms:
36-
def __init__(self, component: Alarm | Event | Todo | None = None): ...
36+
def __init__(self, component: Alarm | Event | Todo | None = None) -> None: ...
3737
def add_component(self, component: Alarm | Parent) -> None: ...
3838
def set_parent(self, parent: Parent) -> None: ...
3939
def add_alarm(self, alarm: Alarm) -> None: ...

stubs/icalendar/icalendar/cal.pyi

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import datetime
22
from _typeshed import Incomplete, SupportsItems
3-
from collections.abc import Callable
4-
from typing import Any, ClassVar, Final, Literal, NamedTuple, overload
3+
from collections.abc import Callable, Iterable
4+
from typing import Any, ClassVar, Final, Literal, NamedTuple, TypeVar, overload
55
from typing_extensions import Self
66

77
from .alarms import Alarms
88
from .caselessdict import CaselessDict
99
from .error import IncompleteComponent as IncompleteComponent
1010
from .parser import Contentline, Contentlines
11-
from .prop import TypesFactory, vRecur
11+
from .parser_tools import ICAL_TYPE
12+
from .prop import TypesFactory, _vType, vRecur
1213
from .timezone.tzp import TZP
1314

15+
_D = TypeVar("_D")
16+
1417
__all__ = [
1518
"Alarm",
1619
"Calendar",
@@ -32,7 +35,8 @@ __all__ = [
3235
def get_example(component_directory: str, example_name: str) -> bytes: ...
3336

3437
class ComponentFactory(CaselessDict[Incomplete]):
35-
def __init__(self, *args, **kwargs) -> None: ...
38+
# Inherit complex __init__ from CaselessDict<-dict.
39+
...
3640

3741
INLINE: CaselessDict[int]
3842

@@ -47,7 +51,7 @@ class Component(CaselessDict[Incomplete]):
4751
subcomponents: list[Incomplete]
4852
errors: list[str]
4953

50-
def __init__(self, *args, **kwargs) -> None: ...
54+
# Inherit complex __init__ from CaselessDict<-dict.
5155
def __bool__(self) -> bool: ...
5256
__nonzero__ = __bool__
5357
def is_empty(self) -> bool: ...
@@ -59,9 +63,12 @@ class Component(CaselessDict[Incomplete]):
5963
def add(
6064
self, name: str, value: Any, parameters: SupportsItems[str, str | None] | None = None, encode: Literal[True] = True
6165
) -> None: ...
62-
def decoded(self, name, default=[]): ...
63-
def get_inline(self, name, decode: bool = True): ...
64-
def set_inline(self, name, values, encode: bool = True) -> None: ...
66+
def decoded(self, name: str, default: _D = ...) -> Incomplete | _D: ...
67+
def get_inline(self, name: str, decode: bool = True) -> list[Incomplete]: ...
68+
@overload
69+
def set_inline(self, name: str, values: Iterable[str], encode: Literal[False] = ...) -> None: ...
70+
@overload
71+
def set_inline(self, name: str, values: Iterable[Incomplete], encode: Literal[True] = True) -> None: ...
6572
def add_component(self, component: Component) -> None: ...
6673
def walk(self, name: str | None = None, select: Callable[[Component], bool] = ...) -> list[Component]: ...
6774
def property_items(self, recursive: bool = True, sorted: bool = True) -> list[tuple[str, object]]: ...
@@ -71,7 +78,7 @@ class Component(CaselessDict[Incomplete]):
7178
@overload
7279
@classmethod
7380
def from_ical(cls, st: str, multiple: Literal[True]) -> list[Component]: ... # or any of its subclasses
74-
def content_line(self, name: str, value, sorted: bool = True) -> Contentline: ...
81+
def content_line(self, name: str, value: _vType | ICAL_TYPE, sorted: bool = True) -> Contentline: ...
7582
def content_lines(self, sorted: bool = True) -> Contentlines: ...
7683
def to_ical(self, sorted: bool = True) -> bytes: ...
7784
def __eq__(self, other: Component) -> bool: ... # type: ignore[override]

stubs/icalendar/icalendar/parser.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ from typing_extensions import Self
77

88
from .caselessdict import CaselessDict
99
from .parser_tools import ICAL_TYPE
10+
from .prop import _vType
1011

1112
__all__ = [
1213
"Contentline",
@@ -83,7 +84,7 @@ class Contentline(str):
8384
strict: bool
8485
def __new__(cls, value: str | bytes, strict: bool = False, encoding: str = "utf-8") -> Self: ...
8586
@classmethod
86-
def from_parts(cls, name: ICAL_TYPE, params: Parameters, values, sorted: bool = True) -> Self: ...
87+
def from_parts(cls, name: ICAL_TYPE, params: Parameters, values: _vType | ICAL_TYPE, sorted: bool = True) -> Self: ...
8788
def parts(self) -> tuple[str, Parameters, str]: ...
8889
@classmethod
8990
def from_ical(cls, ical: str | bytes, strict: bool = False) -> Self: ...

stubs/icalendar/icalendar/prop.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import datetime
2-
from _typeshed import ConvertibleToFloat, ConvertibleToInt, SupportsKeysAndGetItem, Unused
2+
from _typeshed import ConvertibleToFloat, ConvertibleToInt, Incomplete, SupportsKeysAndGetItem, Unused
33
from collections.abc import Iterable, Iterator
44
from enum import Enum
55
from re import Pattern
@@ -84,7 +84,7 @@ class vText(str):
8484

8585
class vCalAddress(str):
8686
params: Parameters
87-
def __new__(cls, value: ICAL_TYPE, encoding="utf-8", params: SupportsKeysAndGetItem[str, str] = {}) -> Self: ...
87+
def __new__(cls, value: ICAL_TYPE, encoding: str = "utf-8", params: SupportsKeysAndGetItem[str, str] = {}) -> Self: ...
8888
def to_ical(self) -> bytes: ...
8989
@classmethod
9090
def from_ical(cls, ical: ICAL_TYPE) -> Self: ...
@@ -127,7 +127,7 @@ class vDDDLists:
127127
def __init__(self, dt_list: Iterable[_AnyTimeType] | _AnyTimeType) -> None: ...
128128
def to_ical(self) -> bytes: ...
129129
@staticmethod
130-
def from_ical(ical: str, timezone: str | datetime.timezone | None = None): ...
130+
def from_ical(ical: str, timezone: str | datetime.timezone | None = None) -> list[Incomplete]: ...
131131
def __eq__(self, other: object) -> bool: ...
132132

133133
class vCategory:

stubs/icalendar/icalendar/timezone/zoneinfo.pyi

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import datetime
22
from typing import Final, Literal
33
from zoneinfo import ZoneInfo
44

5-
from dateutil.rrule import rrule, rruleset
5+
from dateutil.rrule import rrule
66

77
from ..cal import Timezone
88
from ..prop import vRecur
@@ -22,7 +22,3 @@ class ZONEINFO(TZProvider):
2222
def create_timezone(self, tz: Timezone) -> datetime.tzinfo: ... # type: ignore[override]
2323
def uses_pytz(self) -> Literal[False]: ...
2424
def uses_zoneinfo(self) -> Literal[True]: ...
25-
26-
def pickle_tzicalvtz(tzicalvtz): ...
27-
def pickle_rruleset_with_cache(rs: rruleset): ...
28-
def unpickle_rruleset_with_cache(rrule, rdate, exrule, exdate, cache): ...

0 commit comments

Comments
 (0)