Skip to content

Commit e82af8f

Browse files
Jérôme DeuchnordDeuchnord
authored andcommitted
fix: fix a display issue on the events list when Kosmorrolib returns events not supported by the CLI
1 parent be6bf53 commit e82af8f

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

_kosmorro/i18n/strings.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,28 @@
11
#!/usr/bin/env python3
22

3+
from typing import Union
34
from .utils import _
45

56
from kosmorrolib import EventType, MoonPhaseType, ObjectIdentifier, Event
67

78

8-
def from_event(event: Event, with_description: bool = True) -> str:
9+
def from_event(event: Event, with_description: bool = True) -> Union[None, str]:
910
string, details = {
1011
EventType.OPPOSITION: (_("%s is in opposition"), None),
1112
EventType.CONJUNCTION: (_("%s and %s are in conjunction"), None),
1213
EventType.OCCULTATION: (_("%s occults %s"), None),
13-
EventType.MAXIMAL_ELONGATION: (
14-
_("Elongation of %s is maximal"),
15-
(
16-
"{:.3n}°".format(event.details["deg"])
17-
if type(event.details) is dict
18-
else event.details
19-
),
20-
),
14+
EventType.MAXIMAL_ELONGATION: (_("Elongation of %s is maximal"), lambda e: "{:.3n}°".format(e.details["deg"])),
2115
EventType.PERIGEE: (_("%s is at its perigee"), None),
2216
EventType.APOGEE: (_("%s is at its apogee"), None),
23-
}.get(event.event_type)
17+
}.get(event.event_type, (None, None))
2418

2519
if string is None:
2620
return None
2721

2822
string = string % tuple([from_object(o.identifier) for o in event.objects])
2923

3024
if details is not None and with_description:
31-
return "%s (%s)" % (string, details)
25+
return "%s (%s)" % (string, details())
3226

3327
return string
3428

0 commit comments

Comments
 (0)