From 0d00f86b464b5bc32e5425adfe2711c165f600be Mon Sep 17 00:00:00 2001 From: Joel Date: Fri, 6 Nov 2026 12:22:51 +0530 Subject: [PATCH 01/23] feat(recur): add interval property accessor AI model: OpenAI GPT-6. AI use: drafted the INTERVAL getter, setter, deleter, and regression tests following the existing vRecur count/wkst patterns. Prompt summary: add an interval accessor with positive-integer validation, None/deletion semantics, and tests for parsing, mutation, invalid values, and iCalendar round-tripping. I reviewed the implementation and repository contribution policy. --- news/1851.feature.1 | 1 + src/icalendar/prop/recur/recur.py | 59 ++++++++++ .../tests/prop/recur/test_interval.py | 102 ++++++++++++++++++ 3 files changed, 162 insertions(+) create mode 100644 news/1851.feature.1 create mode 100644 src/icalendar/tests/prop/recur/test_interval.py diff --git a/news/1851.feature.1 b/news/1851.feature.1 new file mode 100644 index 000000000..859da74de --- /dev/null +++ b/news/1851.feature.1 @@ -0,0 +1 @@ +Added an :attr:`~icalendar.prop.recur.recur.vRecur.interval` accessor for reading, setting, and deleting the positive INTERVAL value of a recurrence rule. I used OpenAI GPT-6 to assist with implementation and tests. @aspire488 diff --git a/src/icalendar/prop/recur/recur.py b/src/icalendar/prop/recur/recur.py index 09c5fca59..693d1e6e2 100644 --- a/src/icalendar/prop/recur/recur.py +++ b/src/icalendar/prop/recur/recur.py @@ -414,6 +414,65 @@ def count(self) -> None: """Delete the COUNT part of the recurrence rule.""" self.pop("COUNT", None) + @property + def interval(self) -> int | None: + """The INTERVAL part of the recurrence rule. + + This is the positive integer interval between occurrences of the + recurrence frequency. When omitted, RFC 5545 defines the default as + 1; this accessor returns None so callers can distinguish an omitted + value from an explicit one. + + If multiple values are present, the first one is returned. If the + value is missing or an empty sequence, None is returned. + + Setting this to None deletes the value, as does del. + + Raises: + InvalidCalendar: if a stored value is not a positive integer. + InvalidCalendar: when setting a value less than one. + TypeError: when setting a value that is not an int. + + Example: + .. code-block:: pycon + + >>> from icalendar.prop import vRecur + >>> vRecur.from_ical("FREQ=DAILY;INTERVAL=2").interval + 2 + >>> vRecur.from_ical("FREQ=DAILY").interval is None + True + """ + values = self.get("INTERVAL") + if values is None or (isinstance(values, SEQUENCE_TYPES) and len(values) == 0): + return None + value = values[0] if isinstance(values, SEQUENCE_TYPES) else values + if isinstance(value, bool): + raise InvalidCalendar("INTERVAL must be a positive int") + try: + interval = int(value) + except (TypeError, ValueError) as e: + raise InvalidCalendar("INTERVAL must be a positive int") from e + if interval < 1: + raise InvalidCalendar(f"INTERVAL must be >= 1, got {interval}") + return interval + + @interval.setter + def interval(self, value: int | None) -> None: + """Set the INTERVAL part of the recurrence rule, or delete it if None.""" + if value is None: + del self.interval + return + if not isinstance(value, int) or isinstance(value, bool): + raise TypeError(f"interval must be an int, got {value!r}") + if value < 1: + raise InvalidCalendar(f"INTERVAL must be >= 1, got {value}") + self["INTERVAL"] = [vNonNegativeInt(value)] + + @interval.deleter + def interval(self) -> None: + """Delete the INTERVAL part of the recurrence rule.""" + self.pop("INTERVAL", None) + @property def wkst(self) -> vWeekday | None: """The WKST part of the recurrence rule. diff --git a/src/icalendar/tests/prop/recur/test_interval.py b/src/icalendar/tests/prop/recur/test_interval.py new file mode 100644 index 000000000..fa41ac3b3 --- /dev/null +++ b/src/icalendar/tests/prop/recur/test_interval.py @@ -0,0 +1,102 @@ +"""Tests for the vRecur.interval accessor (issue #1851).""" + +import pytest + +from icalendar.error import InvalidCalendar +from icalendar.prop import vRecur +from icalendar.prop.integer import vNonNegativeInt + + +def test_interval_returns_none_when_absent(): + assert vRecur.from_ical("FREQ=DAILY").interval is None + + +def test_interval_returns_the_value(): + assert vRecur.from_ical("FREQ=DAILY;INTERVAL=2").interval == 2 + + +def test_interval_returns_first_value_when_multiple_are_present(): + recur = vRecur(FREQ=["DAILY"], INTERVAL=[2, 3]) + assert recur.interval == 2 + + +def test_interval_returns_none_when_value_is_an_empty_list(): + recur = vRecur(FREQ=["DAILY"], INTERVAL=[]) + assert recur.interval is None + + +def test_setting_interval_stores_a_registered_non_negative_int(): + recur = vRecur.from_ical("FREQ=DAILY") + recur.interval = 3 + + assert recur.interval == 3 + assert isinstance(recur["INTERVAL"][0], vNonNegativeInt) + assert recur.to_ical() == b"FREQ=DAILY;INTERVAL=3" + + +def test_setting_interval_to_none_deletes_the_value(): + recur = vRecur.from_ical("FREQ=DAILY;INTERVAL=2") + recur.interval = None + + assert recur.interval is None + assert "INTERVAL" not in recur + + +def test_deleting_interval_removes_the_value(): + recur = vRecur.from_ical("FREQ=DAILY;INTERVAL=2") + del recur.interval + + assert recur.interval is None + assert "INTERVAL" not in recur + + +def test_deleting_interval_when_absent_does_not_raise(): + recur = vRecur.from_ical("FREQ=DAILY") + del recur.interval + assert recur.interval is None + + +@pytest.mark.parametrize("value", ["2", 2.0, True]) +def test_setting_interval_to_non_int_raises_type_error(value): + recur = vRecur.from_ical("FREQ=DAILY") + with pytest.raises(TypeError): + recur.interval = value + + +@pytest.mark.parametrize("value", [0, -1]) +def test_setting_interval_to_non_positive_value_raises_invalid_calendar(value): + recur = vRecur.from_ical("FREQ=DAILY") + with pytest.raises(InvalidCalendar, match="INTERVAL must be >= 1"): + recur.interval = value + + +def test_zero_interval_is_rejected_when_read(): + recur = vRecur.from_ical("FREQ=DAILY;INTERVAL=0") + with pytest.raises(InvalidCalendar, match="INTERVAL must be >= 1"): + recur.interval + + +@pytest.mark.parametrize("stored", ["abc", "", ["abc"], True]) +def test_directly_assigned_unreadable_interval_raises_invalid_calendar(stored): + recur = vRecur.from_ical("FREQ=DAILY") + recur["INTERVAL"] = stored + with pytest.raises(InvalidCalendar, match="INTERVAL must be"): + recur.interval + + +def test_interval_roundtrips_through_ical(): + recur = vRecur.from_ical("FREQ=DAILY;INTERVAL=3") + roundtripped = vRecur.from_ical(recur.to_ical().decode()) + + assert roundtripped.interval == 3 + assert isinstance(roundtripped["INTERVAL"][0], vNonNegativeInt) + + +def test_setting_interval_matches_parsed_vrecur(): + parsed = vRecur.from_ical("FREQ=DAILY;INTERVAL=3") + assigned = vRecur.from_ical("FREQ=DAILY") + assigned.interval = 3 + + assert assigned == parsed + assert assigned["INTERVAL"] == parsed["INTERVAL"] + assert assigned.to_ical() == parsed.to_ical() From efd7cbee54dd7a5e1fde56d617d5cef6e501d7be Mon Sep 17 00:00:00 2001 From: Joel Date: Fri, 6 Nov 2026 13:21:57 +0530 Subject: [PATCH 02/23] fix(recur): align interval accessor docs and errors --- src/icalendar/prop/recur/recur.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/icalendar/prop/recur/recur.py b/src/icalendar/prop/recur/recur.py index 693d1e6e2..536be6cf8 100644 --- a/src/icalendar/prop/recur/recur.py +++ b/src/icalendar/prop/recur/recur.py @@ -424,12 +424,13 @@ def interval(self) -> int | None: value from an explicit one. If multiple values are present, the first one is returned. If the - value is missing or an empty sequence, None is returned. - - Setting this to None deletes the value, as does del. + value is missing or an empty sequence, None is returned. Assigning + None or deleting the property removes the entire INTERVAL entry, + including all values in a multi-value entry. Raises: - InvalidCalendar: if a stored value is not a positive integer. + InvalidCalendar: if a stored value cannot be read as an int or is + less than one. InvalidCalendar: when setting a value less than one. TypeError: when setting a value that is not an int. @@ -439,6 +440,8 @@ def interval(self) -> int | None: >>> from icalendar.prop import vRecur >>> vRecur.from_ical("FREQ=DAILY;INTERVAL=2").interval 2 + >>> vRecur(FREQ=["DAILY"], INTERVAL=[2, 3]).interval + 2 >>> vRecur.from_ical("FREQ=DAILY").interval is None True """ @@ -446,12 +449,10 @@ def interval(self) -> int | None: if values is None or (isinstance(values, SEQUENCE_TYPES) and len(values) == 0): return None value = values[0] if isinstance(values, SEQUENCE_TYPES) else values - if isinstance(value, bool): - raise InvalidCalendar("INTERVAL must be a positive int") try: interval = int(value) except (TypeError, ValueError) as e: - raise InvalidCalendar("INTERVAL must be a positive int") from e + raise InvalidCalendar("INTERVAL must be an int") from e if interval < 1: raise InvalidCalendar(f"INTERVAL must be >= 1, got {interval}") return interval From 54d9f27f290bcb6c537232c533c72dde87e221d1 Mon Sep 17 00:00:00 2001 From: Joel Date: Fri, 6 Nov 2026 13:22:01 +0530 Subject: [PATCH 03/23] test(recur): cover deleting multiple interval values --- src/icalendar/tests/prop/recur/test_interval.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/icalendar/tests/prop/recur/test_interval.py b/src/icalendar/tests/prop/recur/test_interval.py index fa41ac3b3..aea616c7e 100644 --- a/src/icalendar/tests/prop/recur/test_interval.py +++ b/src/icalendar/tests/prop/recur/test_interval.py @@ -42,6 +42,14 @@ def test_setting_interval_to_none_deletes_the_value(): assert "INTERVAL" not in recur +def test_setting_interval_to_none_removes_all_multiple_values(): + recur = vRecur(FREQ=["DAILY"], INTERVAL=[2, 3]) + recur.interval = None + + assert recur.interval is None + assert "INTERVAL" not in recur + + def test_deleting_interval_removes_the_value(): recur = vRecur.from_ical("FREQ=DAILY;INTERVAL=2") del recur.interval @@ -50,6 +58,14 @@ def test_deleting_interval_removes_the_value(): assert "INTERVAL" not in recur +def test_deleting_interval_removes_all_multiple_values(): + recur = vRecur(FREQ=["DAILY"], INTERVAL=[2, 3]) + del recur.interval + + assert recur.interval is None + assert "INTERVAL" not in recur + + def test_deleting_interval_when_absent_does_not_raise(): recur = vRecur.from_ical("FREQ=DAILY") del recur.interval From ee6c8c15f18308f22b15b038ccabebd41d56acde Mon Sep 17 00:00:00 2001 From: Joel Date: Fri, 6 Nov 2026 13:22:17 +0530 Subject: [PATCH 04/23] fix(recur): reject boolean interval values --- src/icalendar/prop/recur/recur.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/icalendar/prop/recur/recur.py b/src/icalendar/prop/recur/recur.py index 536be6cf8..ec0c83740 100644 --- a/src/icalendar/prop/recur/recur.py +++ b/src/icalendar/prop/recur/recur.py @@ -449,6 +449,8 @@ def interval(self) -> int | None: if values is None or (isinstance(values, SEQUENCE_TYPES) and len(values) == 0): return None value = values[0] if isinstance(values, SEQUENCE_TYPES) else values + if isinstance(value, bool): + raise InvalidCalendar("INTERVAL must be an int") try: interval = int(value) except (TypeError, ValueError) as e: From 77af158321a843377bfbd78f70f9e101a80759df Mon Sep 17 00:00:00 2001 From: Joel Date: Thu, 12 Nov 2026 15:40:02 +0530 Subject: [PATCH 05/23] Add positive integer value type for recurrence intervals --- src/icalendar/prop/integer.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/icalendar/prop/integer.py b/src/icalendar/prop/integer.py index 634e04e17..3a03e9cb6 100644 --- a/src/icalendar/prop/integer.py +++ b/src/icalendar/prop/integer.py @@ -243,4 +243,17 @@ def examples(cls) -> list[vInt]: XCAL_TYPE = "xsd:nonNegativeInteger" -__all__ = ["vInt", "vNonNegativeInt"] +class vPositiveInt(vInt): + """This is an integer that is supposed to be at least 1.""" + + min: ClassVar[int] = 1 + + @classmethod + def examples(cls) -> list[vInt]: + """Examples of vPositiveInt.""" + return [cls(1000), cls(1)] + + XCAL_TYPE = "xsd:positiveInteger" + + +__all__ = ["vInt", "vNonNegativeInt", "vPositiveInt"] From 9f53729c146f16081d5559dda5e2eb2aaf0bbe30 Mon Sep 17 00:00:00 2001 From: Joel Date: Thu, 12 Nov 2026 15:40:04 +0530 Subject: [PATCH 06/23] Validate INTERVAL with positive integer parser --- src/icalendar/prop/recur/recur.py | 34 ++++++++++++++++++------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/icalendar/prop/recur/recur.py b/src/icalendar/prop/recur/recur.py index ec0c83740..de4a90d1c 100644 --- a/src/icalendar/prop/recur/recur.py +++ b/src/icalendar/prop/recur/recur.py @@ -12,7 +12,7 @@ from icalendar.parser.xcal.wrapper import from_xcal_wrapper from icalendar.parser_tools import DEFAULT_ENCODING, SEQUENCE_TYPES from icalendar.prop.dt import vDDDTypes -from icalendar.prop.integer import vInt, vNonNegativeInt +from icalendar.prop.integer import vInt, vNonNegativeInt, vPositiveInt from icalendar.prop.recur.frequency import vFrequency from icalendar.prop.recur.month import vMonth from icalendar.prop.recur.skip import vSkip @@ -170,7 +170,7 @@ class vRecur(CaselessDict): ] = CaselessDict( { "COUNT": vNonNegativeInt, - "INTERVAL": vNonNegativeInt, + "INTERVAL": vPositiveInt, "BYSECOND": vNonNegativeInt, "BYMINUTE": vNonNegativeInt, "BYHOUR": vNonNegativeInt, @@ -419,20 +419,24 @@ def interval(self) -> int | None: """The INTERVAL part of the recurrence rule. This is the positive integer interval between occurrences of the - recurrence frequency. When omitted, RFC 5545 defines the default as - 1; this accessor returns None so callers can distinguish an omitted - value from an explicit one. + recurrence frequency. When omitted, :rfc:`5545#section-3.3.10` + defines the default as ``1``, but this accessor returns ``None`` + instead so callers can distinguish an omitted value from an explicit + one. - If multiple values are present, the first one is returned. If the - value is missing or an empty sequence, None is returned. Assigning - None or deleting the property removes the entire INTERVAL entry, + If multiple values are present, only the first one is returned. If the + value is missing or an empty sequence, ``None`` is returned. Assigning + ``None`` or deleting the property removes the entire INTERVAL entry, including all values in a multi-value entry. Raises: - InvalidCalendar: if a stored value cannot be read as an int or is - less than one. - InvalidCalendar: when setting a value less than one. - TypeError: when setting a value that is not an int. + InvalidCalendar: if a directly stored value cannot be read as an + :class:`int` or is less than ``1``, or when setting a value + less than ``1``. + TypeError: when setting a value that is not an :class:`int`. + + Parsing an invalid INTERVAL value raises ``ValueError`` before the + accessor can be read. Example: .. code-block:: pycon @@ -442,6 +446,8 @@ def interval(self) -> int | None: 2 >>> vRecur(FREQ=["DAILY"], INTERVAL=[2, 3]).interval 2 + >>> vRecur.from_ical("FREQ=DAILY;INTERVAL=2,3").interval + 2 >>> vRecur.from_ical("FREQ=DAILY").interval is None True """ @@ -461,7 +467,7 @@ def interval(self) -> int | None: @interval.setter def interval(self, value: int | None) -> None: - """Set the INTERVAL part of the recurrence rule, or delete it if None.""" + """Set the INTERVAL part of the recurrence rule, or delete it if ``None``.""" if value is None: del self.interval return @@ -469,7 +475,7 @@ def interval(self, value: int | None) -> None: raise TypeError(f"interval must be an int, got {value!r}") if value < 1: raise InvalidCalendar(f"INTERVAL must be >= 1, got {value}") - self["INTERVAL"] = [vNonNegativeInt(value)] + self["INTERVAL"] = [vPositiveInt(value)] @interval.deleter def interval(self) -> None: From fbfb1380eed695502242f787ad777060c9647642 Mon Sep 17 00:00:00 2001 From: Joel Date: Thu, 12 Nov 2026 15:40:07 +0530 Subject: [PATCH 07/23] Test positive INTERVAL parsing and accessor behavior --- src/icalendar/tests/prop/recur/test_interval.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/icalendar/tests/prop/recur/test_interval.py b/src/icalendar/tests/prop/recur/test_interval.py index aea616c7e..28dd2092c 100644 --- a/src/icalendar/tests/prop/recur/test_interval.py +++ b/src/icalendar/tests/prop/recur/test_interval.py @@ -4,7 +4,7 @@ from icalendar.error import InvalidCalendar from icalendar.prop import vRecur -from icalendar.prop.integer import vNonNegativeInt +from icalendar.prop.integer import vPositiveInt def test_interval_returns_none_when_absent(): @@ -25,12 +25,12 @@ def test_interval_returns_none_when_value_is_an_empty_list(): assert recur.interval is None -def test_setting_interval_stores_a_registered_non_negative_int(): +def test_setting_interval_stores_a_registered_positive_int(): recur = vRecur.from_ical("FREQ=DAILY") recur.interval = 3 assert recur.interval == 3 - assert isinstance(recur["INTERVAL"][0], vNonNegativeInt) + assert isinstance(recur["INTERVAL"][0], vPositiveInt) assert recur.to_ical() == b"FREQ=DAILY;INTERVAL=3" @@ -86,8 +86,15 @@ def test_setting_interval_to_non_positive_value_raises_invalid_calendar(value): recur.interval = value -def test_zero_interval_is_rejected_when_read(): - recur = vRecur.from_ical("FREQ=DAILY;INTERVAL=0") +@pytest.mark.parametrize("value", ["0", "-1"]) +def test_parsing_non_positive_interval_raises_value_error(value): + with pytest.raises(ValueError): + vRecur.from_ical(f"FREQ=DAILY;INTERVAL={value}") + + +def test_directly_assigned_non_positive_interval_raises_invalid_calendar(): + recur = vRecur.from_ical("FREQ=DAILY") + recur["INTERVAL"] = [-1] with pytest.raises(InvalidCalendar, match="INTERVAL must be >= 1"): recur.interval From fcf8a98fa434cbc4abe4ffc9e47b279560ca6a84 Mon Sep 17 00:00:00 2001 From: Joel Date: Thu, 12 Nov 2026 15:40:30 +0530 Subject: [PATCH 08/23] Validate positive integers in xCal recurrence parsing --- src/icalendar/prop/integer.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/icalendar/prop/integer.py b/src/icalendar/prop/integer.py index 3a03e9cb6..4bb97a1b7 100644 --- a/src/icalendar/prop/integer.py +++ b/src/icalendar/prop/integer.py @@ -255,5 +255,17 @@ def examples(cls) -> list[vInt]: XCAL_TYPE = "xsd:positiveInteger" + @classmethod + def from_xcal_element(cls, element: ElementAdapter, params: Parameters) -> Self: + """Parse a positive integer from xCal.""" + value = super().from_xcal_element(element, params) + if value < cls.min: + raise XCalParsingError( + f"Expected {cls.XCAL_TYPE}", + element.get_xsd_token(), + element, + ) + return value + __all__ = ["vInt", "vNonNegativeInt", "vPositiveInt"] From d7fe84b45fde563d4d6e5d6289900eb859f6ab26 Mon Sep 17 00:00:00 2001 From: Joel Date: Thu, 12 Nov 2026 15:40:33 +0530 Subject: [PATCH 09/23] Clarify INTERVAL accessor documentation --- src/icalendar/prop/recur/recur.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/icalendar/prop/recur/recur.py b/src/icalendar/prop/recur/recur.py index de4a90d1c..637f33faf 100644 --- a/src/icalendar/prop/recur/recur.py +++ b/src/icalendar/prop/recur/recur.py @@ -424,8 +424,9 @@ def interval(self) -> int | None: instead so callers can distinguish an omitted value from an explicit one. - If multiple values are present, only the first one is returned. If the - value is missing or an empty sequence, ``None`` is returned. Assigning + If multiple values are present (although RFC 5545 permits only one), + only the first one is returned. If the value is missing or an empty + sequence, ``None`` is returned. Assigning ``None`` or deleting the property removes the entire INTERVAL entry, including all values in a multi-value entry. @@ -446,8 +447,6 @@ def interval(self) -> int | None: 2 >>> vRecur(FREQ=["DAILY"], INTERVAL=[2, 3]).interval 2 - >>> vRecur.from_ical("FREQ=DAILY;INTERVAL=2,3").interval - 2 >>> vRecur.from_ical("FREQ=DAILY").interval is None True """ From 025fe614386401602d323794109bbd53cfd5a3c0 Mon Sep 17 00:00:00 2001 From: Joel Date: Thu, 12 Nov 2026 15:40:35 +0530 Subject: [PATCH 10/23] Cover invalid parsed and stored recurrence intervals --- src/icalendar/tests/prop/recur/test_interval.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/icalendar/tests/prop/recur/test_interval.py b/src/icalendar/tests/prop/recur/test_interval.py index 28dd2092c..05eb215ff 100644 --- a/src/icalendar/tests/prop/recur/test_interval.py +++ b/src/icalendar/tests/prop/recur/test_interval.py @@ -123,3 +123,16 @@ def test_setting_interval_matches_parsed_vrecur(): assert assigned == parsed assert assigned["INTERVAL"] == parsed["INTERVAL"] assert assigned.to_ical() == parsed.to_ical() + + +@pytest.mark.parametrize("value", ["0", "-1"]) +def test_parsing_non_positive_interval_raises_value_error(value): + with pytest.raises(ValueError): + vRecur.from_ical(f"FREQ=DAILY;INTERVAL={value}") + + +def test_directly_assigned_non_positive_interval_raises_invalid_calendar(): + recur = vRecur.from_ical("FREQ=DAILY") + recur["INTERVAL"] = [-1] + with pytest.raises(InvalidCalendar, match="INTERVAL must be >= 1"): + recur.interval From e29247c2dae61a811f8b33de0939d085e9eecefb Mon Sep 17 00:00:00 2001 From: Joel Date: Thu, 12 Nov 2026 15:41:19 +0530 Subject: [PATCH 11/23] Fix recurrence interval tests after CI lint feedback --- src/icalendar/tests/prop/recur/test_interval.py | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/src/icalendar/tests/prop/recur/test_interval.py b/src/icalendar/tests/prop/recur/test_interval.py index 05eb215ff..6c26bd00e 100644 --- a/src/icalendar/tests/prop/recur/test_interval.py +++ b/src/icalendar/tests/prop/recur/test_interval.py @@ -112,7 +112,7 @@ def test_interval_roundtrips_through_ical(): roundtripped = vRecur.from_ical(recur.to_ical().decode()) assert roundtripped.interval == 3 - assert isinstance(roundtripped["INTERVAL"][0], vNonNegativeInt) + assert isinstance(roundtripped["INTERVAL"][0], vPositiveInt) def test_setting_interval_matches_parsed_vrecur(): @@ -123,16 +123,3 @@ def test_setting_interval_matches_parsed_vrecur(): assert assigned == parsed assert assigned["INTERVAL"] == parsed["INTERVAL"] assert assigned.to_ical() == parsed.to_ical() - - -@pytest.mark.parametrize("value", ["0", "-1"]) -def test_parsing_non_positive_interval_raises_value_error(value): - with pytest.raises(ValueError): - vRecur.from_ical(f"FREQ=DAILY;INTERVAL={value}") - - -def test_directly_assigned_non_positive_interval_raises_invalid_calendar(): - recur = vRecur.from_ical("FREQ=DAILY") - recur["INTERVAL"] = [-1] - with pytest.raises(InvalidCalendar, match="INTERVAL must be >= 1"): - recur.interval From 84c26f2a99b0a07a0b5155776bfaa6934a405f31 Mon Sep 17 00:00:00 2001 From: Joel Date: Thu, 12 Nov 2026 15:42:29 +0530 Subject: [PATCH 12/23] Clarify invalid RRULE parsing behavior in accessor docs --- src/icalendar/prop/recur/recur.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/icalendar/prop/recur/recur.py b/src/icalendar/prop/recur/recur.py index 637f33faf..e431d520a 100644 --- a/src/icalendar/prop/recur/recur.py +++ b/src/icalendar/prop/recur/recur.py @@ -436,8 +436,8 @@ def interval(self) -> int | None: less than ``1``. TypeError: when setting a value that is not an :class:`int`. - Parsing an invalid INTERVAL value raises ``ValueError`` before the - accessor can be read. + Parsing an invalid iCalendar RRULE value raises ``ValueError`` before + the accessor can be read. Example: .. code-block:: pycon From 48742db72eb046d4a5cd4193906103b5f5df6fba Mon Sep 17 00:00:00 2001 From: Joel Date: Thu, 12 Nov 2026 15:42:32 +0530 Subject: [PATCH 13/23] Cover malformed INTERVAL values during parsing --- src/icalendar/tests/prop/recur/test_interval.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/icalendar/tests/prop/recur/test_interval.py b/src/icalendar/tests/prop/recur/test_interval.py index 6c26bd00e..5cb9ad62c 100644 --- a/src/icalendar/tests/prop/recur/test_interval.py +++ b/src/icalendar/tests/prop/recur/test_interval.py @@ -86,8 +86,8 @@ def test_setting_interval_to_non_positive_value_raises_invalid_calendar(value): recur.interval = value -@pytest.mark.parametrize("value", ["0", "-1"]) -def test_parsing_non_positive_interval_raises_value_error(value): +@pytest.mark.parametrize("value", ["0", "-1", "True", "abc"]) +def test_parsing_invalid_interval_raises_value_error(value): with pytest.raises(ValueError): vRecur.from_ical(f"FREQ=DAILY;INTERVAL={value}") From e3661e3613c1dcff39632b9d6f45bb25bea54e6c Mon Sep 17 00:00:00 2001 From: Joel Date: Sat, 14 Nov 2026 10:50:20 +0530 Subject: [PATCH 14/23] docs(recur): clarify INTERVAL accessor documentation --- src/icalendar/prop/recur/recur.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/icalendar/prop/recur/recur.py b/src/icalendar/prop/recur/recur.py index e431d520a..b463e21df 100644 --- a/src/icalendar/prop/recur/recur.py +++ b/src/icalendar/prop/recur/recur.py @@ -419,14 +419,12 @@ def interval(self) -> int | None: """The INTERVAL part of the recurrence rule. This is the positive integer interval between occurrences of the - recurrence frequency. When omitted, :rfc:`5545#section-3.3.10` - defines the default as ``1``, but this accessor returns ``None`` - instead so callers can distinguish an omitted value from an explicit - one. + recurrence frequency. When omitted, although :rfc:`5545#section-3.3.10` + defines the default as ``1``, this accessor returns ``None`` instead. + As such, callers can distinguish an omitted value from an explicit one. - If multiple values are present (although RFC 5545 permits only one), - only the first one is returned. If the value is missing or an empty - sequence, ``None`` is returned. Assigning + If multiple values are present, only the first one is returned. If the + value is missing or an empty sequence, ``None`` is returned. Assigning ``None`` or deleting the property removes the entire INTERVAL entry, including all values in a multi-value entry. From e99015c8faa4a2e74998d9971e73e49de9c10c1d Mon Sep 17 00:00:00 2001 From: Joel Date: Sun, 15 Nov 2026 10:47:58 +0530 Subject: [PATCH 15/23] test(recur): align xCal interval expectations with positive integer --- src/icalendar/tests/rfc_6321_xcal/prop/test_recur.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/icalendar/tests/rfc_6321_xcal/prop/test_recur.py b/src/icalendar/tests/rfc_6321_xcal/prop/test_recur.py index c57287b69..d0a046bd0 100644 --- a/src/icalendar/tests/rfc_6321_xcal/prop/test_recur.py +++ b/src/icalendar/tests/rfc_6321_xcal/prop/test_recur.py @@ -257,7 +257,7 @@ def test_leap_month_from_xcal(leap): ( key, "asd", - f"Expected xsd:nonNegativeInteger, got 'asd' in /recur/{key.lower()}[1].", + f"Expected xsd:{'positiveInteger' if key == 'INTERVAL' else 'nonNegativeInteger'}, got 'asd' in /recur/{key.lower()}[1].", ) ) @@ -282,7 +282,7 @@ def test_invalid_values_raise_xcal_error(key, xml, message): assert e.value.message == message -@pytest.mark.parametrize("key", POSITIVE_INTS) +@pytest.mark.parametrize("key", [key for key in POSITIVE_INTS if key != "INTERVAL"]) def test_negative_integer_still_parses(key): """We still want to preserve invalid values because - we might just want to convert a calendar @@ -294,6 +294,14 @@ def test_negative_integer_still_parses(key): assert result[key][0].min == 0 +def test_negative_interval_raises_xcal_error(): + """INTERVAL is an xsd:positiveInteger and cannot be negative.""" + xml = list2xml(["recur", ["interval", "-1"]]) + with pytest.raises(XCalParsingError) as exc_info: + vRecur.from_xcal(xml) + assert exc_info.value.message == "Expected xsd:positiveInteger, got '-1' in /recur/interval[1]." + + def test_weekday_becomes_uppercase(): """Uppercase is required for xCal.""" xml = list2xml(["recur", ["byday", "su"]]) From 20b575bcfd10efbf508e21c461c3236740fcd7c6 Mon Sep 17 00:00:00 2001 From: Joel Date: Sun, 15 Nov 2026 10:48:01 +0530 Subject: [PATCH 16/23] test(recur): accept positive integer validation for jCal interval --- src/icalendar/tests/rfc_7265_jcal/test_invalid_jcal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/icalendar/tests/rfc_7265_jcal/test_invalid_jcal.py b/src/icalendar/tests/rfc_7265_jcal/test_invalid_jcal.py index fdff993b5..489fd5979 100644 --- a/src/icalendar/tests/rfc_7265_jcal/test_invalid_jcal.py +++ b/src/icalendar/tests/rfc_7265_jcal/test_invalid_jcal.py @@ -434,7 +434,7 @@ def test_int_parameters(int_expected, key, as_list): # parse bad value with pytest.raises( JCalParsingError, - match=f'\\[3\\]\\["{key}"\\](?:\\[0\\])? in v(NonNegative)?Int: The value must be an integer.', + match=f'\\[3\\]\\["{key}"\\](?:\\[0\\])? in v(?:NonNegative|Positive)?Int: The value must be an integer.', ): vRecur.from_jcal(["rrule", {}, "recur", {key: int_expected}]) From 26f330d99d17e771869eeb0b90c104b641f8aae7 Mon Sep 17 00:00:00 2001 From: Joel Date: Sun, 15 Nov 2026 10:49:44 +0530 Subject: [PATCH 17/23] style(recur): format xCal interval regression test --- src/icalendar/tests/rfc_6321_xcal/prop/test_recur.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/icalendar/tests/rfc_6321_xcal/prop/test_recur.py b/src/icalendar/tests/rfc_6321_xcal/prop/test_recur.py index d0a046bd0..03a7f0428 100644 --- a/src/icalendar/tests/rfc_6321_xcal/prop/test_recur.py +++ b/src/icalendar/tests/rfc_6321_xcal/prop/test_recur.py @@ -299,7 +299,9 @@ def test_negative_interval_raises_xcal_error(): xml = list2xml(["recur", ["interval", "-1"]]) with pytest.raises(XCalParsingError) as exc_info: vRecur.from_xcal(xml) - assert exc_info.value.message == "Expected xsd:positiveInteger, got '-1' in /recur/interval[1]." + assert exc_info.value.message == ( + "Expected xsd:positiveInteger, got '-1' in /recur/interval[1]." + ) def test_weekday_becomes_uppercase(): From 85965c183d0410cce818eb7c75f05ad4e72d7c9c Mon Sep 17 00:00:00 2001 From: Joel Date: Sun, 15 Nov 2026 15:17:53 +0530 Subject: [PATCH 18/23] Clarify interval accessor parsing errors --- src/icalendar/prop/recur/recur.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/icalendar/prop/recur/recur.py b/src/icalendar/prop/recur/recur.py index 48c8bf752..cfd4acc1c 100644 --- a/src/icalendar/prop/recur/recur.py +++ b/src/icalendar/prop/recur/recur.py @@ -429,14 +429,13 @@ def interval(self) -> int | None: including all values in a multi-value entry. Raises: + ValueError: when parsing an RRULE whose INTERVAL is not a positive + integer. InvalidCalendar: if a directly stored value cannot be read as an :class:`int` or is less than ``1``, or when setting a value less than ``1``. TypeError: when setting a value that is not an :class:`int`. - Parsing an invalid iCalendar RRULE value raises ``ValueError`` before - the accessor can be read. - Example: .. code-block:: pycon From 4855bfbf4203bcdc39ca78dbb61a753796f2a3ab Mon Sep 17 00:00:00 2001 From: Joel Date: Sun, 15 Nov 2026 15:17:55 +0530 Subject: [PATCH 19/23] Polish positive integer docstring --- src/icalendar/prop/integer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/icalendar/prop/integer.py b/src/icalendar/prop/integer.py index 4bb97a1b7..9f52fcb5b 100644 --- a/src/icalendar/prop/integer.py +++ b/src/icalendar/prop/integer.py @@ -244,7 +244,7 @@ def examples(cls) -> list[vInt]: class vPositiveInt(vInt): - """This is an integer that is supposed to be at least 1.""" + """This is an integer that is at least ``1``.""" min: ClassVar[int] = 1 From 022ab05aa1427704ac7e4370866fd89f3337756b Mon Sep 17 00:00:00 2001 From: Joel Date: Sun, 15 Nov 2026 15:17:57 +0530 Subject: [PATCH 20/23] Cover zero and negative stored intervals --- src/icalendar/tests/prop/recur/test_interval.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/icalendar/tests/prop/recur/test_interval.py b/src/icalendar/tests/prop/recur/test_interval.py index 5cb9ad62c..21848294e 100644 --- a/src/icalendar/tests/prop/recur/test_interval.py +++ b/src/icalendar/tests/prop/recur/test_interval.py @@ -92,9 +92,10 @@ def test_parsing_invalid_interval_raises_value_error(value): vRecur.from_ical(f"FREQ=DAILY;INTERVAL={value}") -def test_directly_assigned_non_positive_interval_raises_invalid_calendar(): +@pytest.mark.parametrize("stored", [0, -1]) +def test_directly_assigned_non_positive_interval_raises_invalid_calendar(stored): recur = vRecur.from_ical("FREQ=DAILY") - recur["INTERVAL"] = [-1] + recur["INTERVAL"] = [stored] with pytest.raises(InvalidCalendar, match="INTERVAL must be >= 1"): recur.interval From 488b6bbc306148af18e71c599f680a9a30b7173a Mon Sep 17 00:00:00 2001 From: Joel Date: Mon, 16 Nov 2026 11:57:26 +0530 Subject: [PATCH 21/23] fix(recur): clarify interval access errors --- src/icalendar/prop/recur/recur.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/icalendar/prop/recur/recur.py b/src/icalendar/prop/recur/recur.py index cfd4acc1c..785d4f879 100644 --- a/src/icalendar/prop/recur/recur.py +++ b/src/icalendar/prop/recur/recur.py @@ -431,7 +431,8 @@ def interval(self) -> int | None: Raises: ValueError: when parsing an RRULE whose INTERVAL is not a positive integer. - InvalidCalendar: if a directly stored value cannot be read as an + InvalidCalendar: after using :ref:`dictionary-access`, if a stored + value cannot be read through :ref:`property-access` as an :class:`int` or is less than ``1``, or when setting a value less than ``1``. TypeError: when setting a value that is not an :class:`int`. @@ -452,13 +453,17 @@ def interval(self) -> int | None: return None value = values[0] if isinstance(values, SEQUENCE_TYPES) else values if isinstance(value, bool): - raise InvalidCalendar("INTERVAL must be an int") + raise InvalidCalendar( + f"INTERVAL must be an int, got {type(value).__name__}" + ) try: interval = int(value) except (TypeError, ValueError) as e: - raise InvalidCalendar("INTERVAL must be an int") from e + raise InvalidCalendar( + f"INTERVAL must be an int, got {type(value).__name__}" + ) from e if interval < 1: - raise InvalidCalendar(f"INTERVAL must be >= 1, got {interval}") + raise InvalidCalendar(f"INTERVAL must be >= 1, got {interval}.") return interval @interval.setter From 8d8a90f3b3764931ac6573627d30606d3a4adf59 Mon Sep 17 00:00:00 2001 From: Joel Date: Mon, 16 Nov 2026 11:57:28 +0530 Subject: [PATCH 22/23] test(recur): cover interval dictionary access errors --- src/icalendar/tests/prop/recur/test_interval.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/icalendar/tests/prop/recur/test_interval.py b/src/icalendar/tests/prop/recur/test_interval.py index 21848294e..4dd5620ea 100644 --- a/src/icalendar/tests/prop/recur/test_interval.py +++ b/src/icalendar/tests/prop/recur/test_interval.py @@ -93,7 +93,7 @@ def test_parsing_invalid_interval_raises_value_error(value): @pytest.mark.parametrize("stored", [0, -1]) -def test_directly_assigned_non_positive_interval_raises_invalid_calendar(stored): +def test_dictionary_access_non_positive_interval_raises_invalid_calendar(stored): recur = vRecur.from_ical("FREQ=DAILY") recur["INTERVAL"] = [stored] with pytest.raises(InvalidCalendar, match="INTERVAL must be >= 1"): @@ -101,10 +101,13 @@ def test_directly_assigned_non_positive_interval_raises_invalid_calendar(stored) @pytest.mark.parametrize("stored", ["abc", "", ["abc"], True]) -def test_directly_assigned_unreadable_interval_raises_invalid_calendar(stored): +def test_dictionary_access_unreadable_interval_raises_invalid_calendar(stored): recur = vRecur.from_ical("FREQ=DAILY") recur["INTERVAL"] = stored - with pytest.raises(InvalidCalendar, match="INTERVAL must be"): + with pytest.raises( + InvalidCalendar, + match=f"INTERVAL must be an int, got {type(stored).__name__}", + ): recur.interval From b9214453168ebe9d63aab96fb0030bde28f586cd Mon Sep 17 00:00:00 2001 From: Joel Date: Mon, 16 Nov 2026 11:58:04 +0530 Subject: [PATCH 23/23] test(recur): assert interval error value types --- src/icalendar/tests/prop/recur/test_interval.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/icalendar/tests/prop/recur/test_interval.py b/src/icalendar/tests/prop/recur/test_interval.py index 4dd5620ea..4e08915aa 100644 --- a/src/icalendar/tests/prop/recur/test_interval.py +++ b/src/icalendar/tests/prop/recur/test_interval.py @@ -100,13 +100,18 @@ def test_dictionary_access_non_positive_interval_raises_invalid_calendar(stored) recur.interval -@pytest.mark.parametrize("stored", ["abc", "", ["abc"], True]) -def test_dictionary_access_unreadable_interval_raises_invalid_calendar(stored): +@pytest.mark.parametrize( + ("stored", "value_type"), + [("abc", "str"), ("", "str"), (["abc"], "str"), (True, "bool")], +) +def test_dictionary_access_unreadable_interval_raises_invalid_calendar( + stored, value_type +): recur = vRecur.from_ical("FREQ=DAILY") recur["INTERVAL"] = stored with pytest.raises( InvalidCalendar, - match=f"INTERVAL must be an int, got {type(stored).__name__}", + match=f"INTERVAL must be an int, got {value_type}", ): recur.interval