From e82af8f4b9d3a1511876718ff99d5bcc6dce9067 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Deuchnord?= Date: Tue, 9 Nov 2021 18:59:04 +0100 Subject: [PATCH] fix: fix a display issue on the events list when Kosmorrolib returns events not supported by the CLI --- _kosmorro/i18n/strings.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/_kosmorro/i18n/strings.py b/_kosmorro/i18n/strings.py index 10be55c..0da2f5c 100644 --- a/_kosmorro/i18n/strings.py +++ b/_kosmorro/i18n/strings.py @@ -1,26 +1,20 @@ #!/usr/bin/env python3 +from typing import Union from .utils import _ from kosmorrolib import EventType, MoonPhaseType, ObjectIdentifier, Event -def from_event(event: Event, with_description: bool = True) -> str: +def from_event(event: Event, with_description: bool = True) -> Union[None, str]: string, details = { EventType.OPPOSITION: (_("%s is in opposition"), None), EventType.CONJUNCTION: (_("%s and %s are in conjunction"), None), EventType.OCCULTATION: (_("%s occults %s"), None), - EventType.MAXIMAL_ELONGATION: ( - _("Elongation of %s is maximal"), - ( - "{:.3n}°".format(event.details["deg"]) - if type(event.details) is dict - else event.details - ), - ), + EventType.MAXIMAL_ELONGATION: (_("Elongation of %s is maximal"), lambda e: "{:.3n}°".format(e.details["deg"])), EventType.PERIGEE: (_("%s is at its perigee"), None), EventType.APOGEE: (_("%s is at its apogee"), None), - }.get(event.event_type) + }.get(event.event_type, (None, None)) if string is None: return None @@ -28,7 +22,7 @@ def from_event(event: Event, with_description: bool = True) -> str: string = string % tuple([from_object(o.identifier) for o in event.objects]) if details is not None and with_description: - return "%s (%s)" % (string, details) + return "%s (%s)" % (string, details()) return string