From f6e7ebcb09fdcf156d0b1b49df3a35868a669409 Mon Sep 17 00:00:00 2001 From: xxiaoxiong <2482929840@qq.com> Date: Thu, 7 May 2026 08:13:33 +0800 Subject: [PATCH 1/3] Add return type hints to property_set_duration and property_del_duration - Added -> None return type hint to property_set_duration function - Added -> None return type hint to property_del_duration function Contributes to #938 (Add type hints) --- src/icalendar/attr.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/icalendar/attr.py b/src/icalendar/attr.py index 545f66c48..c6b8a313b 100644 --- a/src/icalendar/attr.py +++ b/src/icalendar/attr.py @@ -989,7 +989,7 @@ def property_get_duration(self: Component) -> timedelta | None: return result -def property_set_duration(self: Component, value: timedelta | None): +def property_set_duration(self: Component, value: timedelta | None) -> None: """Setter for property DURATION.""" if value is None: self.pop("duration", None) @@ -1001,7 +1001,7 @@ def property_set_duration(self: Component, value: timedelta | None): self.pop("DUE") -def property_del_duration(self: Component): +def property_del_duration(self: Component) -> None: """Delete property DURATION.""" self.pop("DURATION") From a320c2f9eab544cb9898be3746ba75b39e466af4 Mon Sep 17 00:00:00 2001 From: xxiaoxiong <2482929840@qq.com> Date: Thu, 7 May 2026 08:24:12 +0800 Subject: [PATCH 2/3] Add return type hints to 5 more functions - Added -> None to use_pytz() in timezone/__init__.py - Added -> None to use_zoneinfo() in timezone/__init__.py - Added -> None to main() in cli.py - Added -> None to rfc_7953_end_property setter in attr.py - Added -> None to rfc_7953_end_property deleter in attr.py All functions have no return statements, so return type is None. Contributes to #938 (Add type hints) --- src/icalendar/attr.py | 4 ++-- src/icalendar/cli.py | 2 +- src/icalendar/timezone/__init__.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/icalendar/attr.py b/src/icalendar/attr.py index c6b8a313b..12ef5492a 100644 --- a/src/icalendar/attr.py +++ b/src/icalendar/attr.py @@ -1583,12 +1583,12 @@ def rfc_7953_end_property(self) -> timedelta | None: @rfc_7953_end_property.setter -def rfc_7953_end_property(self, value: datetime): +def rfc_7953_end_property(self, value: datetime) -> None: self.DTEND = value @rfc_7953_end_property.deleter -def rfc_7953_end_property(self): +def rfc_7953_end_property(self) -> None: del self.DTEND diff --git a/src/icalendar/cli.py b/src/icalendar/cli.py index 255757004..e3d444a7c 100755 --- a/src/icalendar/cli.py +++ b/src/icalendar/cli.py @@ -86,7 +86,7 @@ def view(event: Event) -> str: {description}""" -def main(): +def main() -> None: parser = argparse.ArgumentParser(description=__doc__) parser.add_argument( diff --git a/src/icalendar/timezone/__init__.py b/src/icalendar/timezone/__init__.py index 0c94cbd49..f8168232d 100644 --- a/src/icalendar/timezone/__init__.py +++ b/src/icalendar/timezone/__init__.py @@ -6,12 +6,12 @@ tzp = TZP() -def use_pytz(): +def use_pytz() -> None: """Use pytz as the implementation that looks up and creates timezones.""" tzp.use_pytz() -def use_zoneinfo(): +def use_zoneinfo() -> None: """Use zoneinfo as the implementation that looks up and creates timezones.""" tzp.use_zoneinfo() From df751ab656cf13fd45ab4b366a85f419d8f9baef Mon Sep 17 00:00:00 2001 From: xxiaoxiong <2482929840@qq.com> Date: Thu, 7 May 2026 08:33:41 +0800 Subject: [PATCH 3/3] Add return type hints to remaining 9 functions - Added -> property to timezone_datetime_property() in attr.py - Added -> property to multi_string_property() in attr.py - Added -> str to unescape_backslash() in parser/property.py - Added -> Callable | property to single_string_parameter() in parser/parameter.py - Added -> tuple[type[_tzicalvtz], tuple] to pickle_tzicalvtz() in timezone/zoneinfo.py - Added -> tuple[functools.partial, tuple] to pickle_rrule_with_cache() in timezone/zoneinfo.py - Added -> tuple[type[unpickle_rruleset_with_cache], tuple] to pickle_rruleset_with_cache() in timezone/zoneinfo.py - Added -> rruleset to unpickle_rruleset_with_cache() in timezone/zoneinfo.py - Added -> None to main() in fuzzing/ical_fuzzer.py This completes all missing return type hints in the main source code. Contributes to #938 (Add type hints) --- src/icalendar/attr.py | 4 ++-- src/icalendar/fuzzing/ical_fuzzer.py | 2 +- src/icalendar/parser/parameter.py | 2 +- src/icalendar/parser/property.py | 2 +- src/icalendar/timezone/zoneinfo.py | 8 ++++---- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/icalendar/attr.py b/src/icalendar/attr.py index 12ef5492a..2b15d6b07 100644 --- a/src/icalendar/attr.py +++ b/src/icalendar/attr.py @@ -1498,7 +1498,7 @@ def fset(self: Component, value: str | StrEnum | None) -> None: ) -def timezone_datetime_property(name: str, docs: str): +def timezone_datetime_property(name: str, docs: str) -> property: """Create a property to access the values with a proper timezone.""" return single_utc_property(name, docs) @@ -2376,7 +2376,7 @@ def _del_concepts(self: Component): concepts_property = property(_get_concepts, _set_concepts, _del_concepts) -def multi_string_property(name: str, doc: str): +def multi_string_property(name: str, doc: str) -> property: """A property for an iCalendar Property that can occur multiple times.""" def fget(self: Component) -> list[str]: diff --git a/src/icalendar/fuzzing/ical_fuzzer.py b/src/icalendar/fuzzing/ical_fuzzer.py index a2d776099..63ceb6773 100755 --- a/src/icalendar/fuzzing/ical_fuzzer.py +++ b/src/icalendar/fuzzing/ical_fuzzer.py @@ -50,7 +50,7 @@ def TestOneInput(data): print("--- end calendar ---") -def main(): +def main() -> None: atheris.Setup(sys.argv, TestOneInput) atheris.Fuzz() diff --git a/src/icalendar/parser/parameter.py b/src/icalendar/parser/parameter.py index 08a135231..e3517d4da 100644 --- a/src/icalendar/parser/parameter.py +++ b/src/icalendar/parser/parameter.py @@ -189,7 +189,7 @@ def q_join(lst: Sequence[str], sep: str = ",", always_quote: bool = False) -> st return sep.join(dquote(itm, always_quote=always_quote) for itm in lst) -def single_string_parameter(func: Callable | None = None, upper=False): +def single_string_parameter(func: Callable | None = None, upper=False) -> Callable | property: """Create a parameter getter/setter for a single string parameter. Parameters: diff --git a/src/icalendar/parser/property.py b/src/icalendar/parser/property.py index 6efca840a..91f12bb80 100644 --- a/src/icalendar/parser/property.py +++ b/src/icalendar/parser/property.py @@ -25,7 +25,7 @@ def unescape_list_or_string(val: str | list[str]) -> str | list[str]: _unescape_backslash_regex = re.compile(r"\\([\\,;:nN])") -def unescape_backslash(val: str): +def unescape_backslash(val: str) -> str: r"""Unescape backslash sequences in iCalendar text. Unlike :py:meth:`unescape_string`, this only handles actual backslash escapes diff --git a/src/icalendar/timezone/zoneinfo.py b/src/icalendar/timezone/zoneinfo.py index 24733a4cc..72f8cb820 100644 --- a/src/icalendar/timezone/zoneinfo.py +++ b/src/icalendar/timezone/zoneinfo.py @@ -120,7 +120,7 @@ def uses_zoneinfo(self) -> bool: return True -def pickle_tzicalvtz(tzicalvtz: _tzicalvtz): +def pickle_tzicalvtz(tzicalvtz: _tzicalvtz) -> tuple[type[_tzicalvtz], tuple]: """Because we use dateutil.tzical, we need to make it pickle-able.""" return _tzicalvtz, (tzicalvtz._tzid, tzicalvtz._comps) # noqa: SLF001 @@ -128,7 +128,7 @@ def pickle_tzicalvtz(tzicalvtz: _tzicalvtz): copyreg.pickle(_tzicalvtz, pickle_tzicalvtz) -def pickle_rrule_with_cache(self: rrule): +def pickle_rrule_with_cache(self: rrule) -> tuple[functools.partial, tuple]: """Make sure we can also pickle rrules that cache. This is mainly copied from rrule.replace. @@ -150,7 +150,7 @@ def pickle_rrule_with_cache(self: rrule): copyreg.pickle(rrule, pickle_rrule_with_cache) -def pickle_rruleset_with_cache(rs: rruleset): +def pickle_rruleset_with_cache(rs: rruleset) -> tuple[type[unpickle_rruleset_with_cache], tuple]: """Pickle an rruleset.""" return unpickle_rruleset_with_cache, ( rs._rrule, # noqa: SLF001 @@ -161,7 +161,7 @@ def pickle_rruleset_with_cache(rs: rruleset): ) -def unpickle_rruleset_with_cache(rrule, rdate, exrule, exdate, cache): +def unpickle_rruleset_with_cache(rrule, rdate, exrule, exdate, cache) -> rruleset: """unpickling the rruleset.""" rs = rruleset(cache) for o in rrule: