From: Tomas Babej Date: Sun, 28 Dec 2014 00:54:22 +0000 (+0100) Subject: Task: Make Task object non-iterable X-Git-Url: https://git.madduck.net/etc/taskwarrior.git/commitdiff_plain/bd3efb6ceee683f9575fb40c4ec9cf730e894939?ds=inline Task: Make Task object non-iterable --- diff --git a/tasklib/task.py b/tasklib/task.py index 44c6965..096f656 100644 --- a/tasklib/task.py +++ b/tasklib/task.py @@ -34,6 +34,14 @@ class TaskResource(object): self._original_data = data.copy() def __getitem__(self, key): + # This is a workaround to make TaskResource non-iterable + # over simple index-based iteration + try: + int(key) + raise StopIteration + except ValueError: + pass + hydrate_func = getattr(self, 'deserialize_{0}'.format(key), lambda x: x) return hydrate_func(self._data.get(key))