Skip to content

Return early from rrule._iter when bysetpos cannot match any interval - #1679

Draft
EnesKartal wants to merge 2 commits into
dateutil:masterfrom
EnesKartal:fix/rrule-bysetpos-unreachable
Draft

EnesKartal wants to merge 2 commits into
dateutil:masterfrom
EnesKartal:fix/rrule-bysetpos-unreachable

Conversation

@EnesKartal

@EnesKartal EnesKartal commented Nov 19, 2026 •

Copy link
Copy Markdown

Summary of changes

When every requested �ysetpos value has an absolute value larger than the maximum number of occurrences a single interval can produce (for example,
rule(MINUTELY, dtstart=datetime(2019, 1, 1), bysetpos=2, count=1, byweekday=MO)),
rule._iter() hits IndexError on every interval and advances all the way to datetime.MAXYEAR before returning empty.

rule._iter() now computes the maximum possible number of occurrences per interval for the rule's frequency and time set, and returns early with self._len = 0 if no �ysetpos entry can ever match. The RFC 5545 range validation (1..366 and -366..-1) is unchanged.

Closes #905

Pull Request Checklist

  • Changes have tests
  • Authors have been added to AUTHORS.md
  • News fragment added in changelog.d. See CONTRIBUTING.md for details

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Arbitrary bysetpos restriction to 1 to 366

1 participant