Skip to content

Commit

Permalink
correct ci errors
Browse files Browse the repository at this point in the history
  • Loading branch information
niccokunzmann committed Nov 15, 2024
1 parent 2a639dd commit 368ae94
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/icalendar/tests/test_issue_722_generate_vtimezone.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from dateutil.tz import gettz

from icalendar import Calendar, Component, Event, Timezone
from icalendar.prop import _identify_tzinfo, tzid_from_tzinfo, tzids_from_tzinfo
from icalendar.timezone import tzid_from_tzinfo, tzids_from_tzinfo

tzids = pytest.mark.parametrize("tzid", [
"Europe/Berlin",
Expand Down Expand Up @@ -406,4 +406,4 @@ def test_we_can_identify_dateutil_timezones(tzid):
But if we know their shortcodes, we should be able to identify them.
"""
tz = gettz(tzid)
assert tzid in tzids_from_tzinfo(tz), f"{tzid} -> {_identify_tzinfo(tz)}"
assert tzid in tzids_from_tzinfo(tz)
12 changes: 8 additions & 4 deletions src/icalendar/timezone/tzid.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from datetime import datetime, tzinfo


def tzids_from_tzinfo(tzinfo: tzinfo) -> tuple[str]:
def tzids_from_tzinfo(tzinfo: Optional[tzinfo]) -> tuple[str]:
"""Get several timezone ids if we can identify the timezone.
>>> import zoneinfo
Expand All @@ -24,14 +24,16 @@ def tzids_from_tzinfo(tzinfo: tzinfo) -> tuple[str]:
('Africa/Abidjan', 'Africa/Accra', 'Africa/Bamako', 'Africa/Banjul', 'Africa/Conakry', 'Africa/Dakar')
"""
if tzinfo is None:
return ()
if hasattr(tzinfo, 'zone'):
return (tzinfo.zone,) # pytz implementation
if hasattr(tzinfo, 'key'):
return (tzinfo.key,) # dateutil implementation, tzinfo.key # ZoneInfo implementation
return tzinfo2tzids(tzinfo)
return tuple(sorted(tzinfo2tzids(tzinfo)))


def tzid_from_tzinfo(tzinfo: tzinfo) -> Optional[str]:
def tzid_from_tzinfo(tzinfo: Optional[tzinfo]) -> Optional[str]:
"""Retrieve the timezone id from the tzinfo object.
Some timezones are equivalent.
Expand All @@ -48,7 +50,7 @@ def tzid_from_dt(dt: datetime) -> Optional[str]:
return tzid


def tzinfo2tzids(tzinfo: tzinfo) -> set[str]:
def tzinfo2tzids(tzinfo: Optional[tzinfo]) -> set[str]:
"""We return the tzids for a certain tzinfo object.
With different datetimes, we match
Expand All @@ -69,6 +71,8 @@ def tzinfo2tzids(tzinfo: tzinfo) -> set[str]:
>>> tzinfo2tzids(zoneinfo.ZoneInfo("Africa/Accra"))
('Africa/Abidjan', 'Africa/Accra', 'Africa/Bamako', 'Africa/Banjul', 'Africa/Conakry', 'Africa/Dakar')
"""
if tzinfo is None:
return set()
from icalendar.timezone.equivalent_timezone_ids_result import lookup

while 1:
Expand Down

0 comments on commit 368ae94

Please sign in to comment.