diff --git a/GTG/core/base_store.py b/GTG/core/base_store.py index 975e36532..ca1ab6e91 100644 --- a/GTG/core/base_store.py +++ b/GTG/core/base_store.py @@ -49,7 +49,7 @@ def new(self) -> Any: raise NotImplemented - def get(self, key: str) -> Any: + def get(self, key: UUID) -> Any: """Get an item by id.""" return self.lookup[key] diff --git a/GTG/core/tasks.py b/GTG/core/tasks.py index a6eecfce5..735f62f10 100644 --- a/GTG/core/tasks.py +++ b/GTG/core/tasks.py @@ -753,7 +753,7 @@ def duplicate_for_recurrent(self, task: Task) -> Task: return new_task - def new(self, title: str = None, parent: UUID = None) -> Task: + def new(self, title: str = None, parent: Optional[UUID] = None) -> Task: """Create a new task and add it to the store.""" tid = uuid4() @@ -777,7 +777,7 @@ def from_xml(self, xml: Element, tag_store: TagStore) -> None: elements = list(xml.iter(self.XML_TAG)) for element in elements: - tid = element.get('id') + tid = UUID(element.get('id')) title = element.find('title').text status = element.get('status') @@ -841,11 +841,11 @@ def from_xml(self, xml: Element, tag_store: TagStore) -> None: # All tasks have been added, now we parent them for element in elements: - parent_tid = element.get('id') + parent_tid = UUID(element.get('id')) subtasks = element.find('subtasks') for sub in subtasks.findall('sub'): - self.parent(sub.text, parent_tid) + self.parent(UUID(sub.text), parent_tid) def to_xml(self) -> Element: @@ -934,7 +934,7 @@ def _append_to_parent_model(self,task_id: UUID) -> None: if not pos[0]: model.append(item) - def add(self, item: Any, parent_id: UUID = None) -> None: + def add(self, item: Any, parent_id: Optional[UUID] = None) -> None: """Add a task to the taskstore.""" super().add(item, parent_id) diff --git a/GTG/gtk/editor/taskview.py b/GTG/gtk/editor/taskview.py index 23dfb3f27..9bbf91d1e 100644 --- a/GTG/gtk/editor/taskview.py +++ b/GTG/gtk/editor/taskview.py @@ -21,7 +21,7 @@ import re from time import time -from uuid import uuid4 +from uuid import uuid4, UUID import logging from gi.repository import Gtk, GLib, Gdk, GObject, GtkSource @@ -417,7 +417,7 @@ def on_checkbox_toggle(self, tid: uuid4) -> None: self.process() - def add_checkbox(self, tid: int, start: Gtk.TextIter) -> None: + def add_checkbox(self, tid: UUID, start: Gtk.TextIter) -> None: """Add a checkbox for a subtask.""" task = self.ds.tasks.lookup[tid] @@ -483,7 +483,7 @@ def detect_internal_link(self, text: str, start: Gtk.TextIter) -> None: url_start.forward_chars(match.start()) url_end.forward_chars(match.end()) - tid = match.group(0).replace('gtg://', '') + tid = UUID(match.group(0).replace('gtg://', '')) task = self.ds.tasks.lookup[tid] if task: @@ -769,7 +769,7 @@ def insert(self, text: str) -> None: # Find the subtasks and store their lines if line.lstrip().startswith('{!'): # Get the Task ID - tid = line.replace('{! ', '').replace(' !}', '').strip() + tid = UUID(line.replace('{! ', '').replace(' !}', '').strip()) # Remember there's a line for the title at the top real_index = index + 1 diff --git a/tests/core/test_task.py b/tests/core/test_task.py index a9ab36b1b..fb1bb3aa4 100644 --- a/tests/core/test_task.py +++ b/tests/core/test_task.py @@ -430,7 +430,7 @@ def test_xml_load_tree(self): task_store.from_xml(parsed_xml, None) self.assertEqual(task_store.count(), 4) self.assertEqual(task_store.count(root_only=True), 1) - self.assertEqual(len(task_store.get(str(TASK_ID_1)).children), 2) + self.assertEqual(len(task_store.get(TASK_ID_1).children), 2) def test_xml_load_bad(self): @@ -478,7 +478,7 @@ def test_xml_load_bad(self): ''') - with self.assertRaises(KeyError): + with self.assertRaises(ValueError): task_store.from_xml(parsed_xml, None)