Use defaultdict(list) in TraktBatch items
from __future__ import annotations
+from collections import defaultdict
from time import time
from typing import List, Optional, Union
@@ -389,7 +390,7 @@ def __init__(self, trakt: TraktApi, name: str, add: bool, batch_delay=None):
self.add = add
self.trakt = trakt
self.batch_delay = batch_delay
- self.items = {}
+ self.items = defaultdict(list)
self.last_sent_time = 0
@nocache
@@ -432,9 +433,6 @@ def add_to_items(self, media_type: str, item):
"""
Add item of media_type to list of items
"""
- if media_type not in self.items:
- self.items[media_type] = []
-
self.items[media_type].append(item)
self.flush()
