Skip to content

Fix TypeError in _tzicalvtz._find_comp: comp[0] should be self._comps[0]#1454

Open
bysiber wants to merge 1 commit intodateutil:masterfrom
bysiber:fix/tzical-comps-subscript-typo
Open

Fix TypeError in _tzicalvtz._find_comp: comp[0] should be self._comps[0]#1454
bysiber wants to merge 1 commit intodateutil:masterfrom
bysiber:fix/tzical-comps-subscript-typo

Conversation

@bysiber
Copy link
Copy Markdown

@bysiber bysiber commented Feb 20, 2026

Summary

_tzicalvtz._find_comp raises TypeError when falling back to the first timezone component in an iCalendar VTIMEZONE that has no STANDARD component.

Problem

In the for...else fallback path (when no non-DST component is found), the code indexes into comp — the loop variable — rather than self._comps:

for comp in self._comps:
    if not comp.isdst:
        lastcomp = comp
        break
else:
    lastcomp = comp[0]  # TypeError: '_tzicalvtzcomp' object is not subscriptable

After the for loop completes without break, comp is the last _tzicalvtzcomp object — a plain object with no __getitem__. The intent was clearly to fall back to self._comps[0] (the first component in the list).

This is triggered when querying a datetime that falls before any transition onset in a VTIMEZONE where all components are DST (no STANDARD entry).

Fix

Replace comp[0] with self._comps[0].

In the for...else fallback when no standard component is found,
the code uses comp[0] where comp is a _tzicalvtzcomp object (not
subscriptable). The intent was to fall back to the first component
in the list, i.e. self._comps[0].
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.

1 participant