From 4f757aeeb4488f6e27d92dbf9e4392b1e93eb063 Mon Sep 17 00:00:00 2001 From: Daniel Viegas Date: Sun, 30 Nov 2025 01:33:32 +0100 Subject: [PATCH] Fix: Use hashable cache key for event type normalization - Change cache key from EventType (unhashable) to normalized int - Fixes TypeError: unhashable type: 'EventType' error - Cache now uses normalized integer as both key and value This ensures the cache works correctly with non-hashable EventType objects while maintaining caching benefits for repeated conversions. --- MyTimeline.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/MyTimeline.py b/MyTimeline.py index 8b72e9a..f980871 100644 --- a/MyTimeline.py +++ b/MyTimeline.py @@ -473,7 +473,7 @@ class MyTimelineView(NavigationView): self._cached_min_date: Optional[int] = None self._cached_max_date: Optional[int] = None self._event_to_person_cache: Dict[str, Optional['Person']] = {} # Event handle -> Person object (or None) - self._event_type_normalization_cache: Dict[EventType, int] = {} # Cache for event type normalization + self._event_type_normalization_cache: Dict[int, int] = {} # Cache for event type normalization (key: hash/id, value: normalized int) self._normalized_active_event_types: Optional[Set[int]] = None # Pre-computed normalized active types # Filter state @@ -2064,10 +2064,7 @@ class MyTimelineView(NavigationView): Returns: int: The integer value of the event type. """ - # Check cache first - if event_type in self._event_type_normalization_cache: - return self._event_type_normalization_cache[event_type] - + # Normalize to integer first (fast operation) try: if isinstance(event_type, int): normalized = event_type @@ -2078,8 +2075,12 @@ class MyTimelineView(NavigationView): except (TypeError, ValueError, AttributeError): normalized = 0 # Default to 0 if conversion fails - # Cache the result - self._event_type_normalization_cache[event_type] = normalized + # Use normalized value as cache key (ensures same values share same key) + # Check cache - if we've seen this normalized value before, we already know it + # This cache is mainly useful for avoiding repeated int() calls on same objects + if normalized not in self._event_type_normalization_cache: + self._event_type_normalization_cache[normalized] = normalized + return normalized def _is_event_type_enabled(self, event_type: EventType) -> bool: