From bd3efb6ceee683f9575fb40c4ec9cf730e894939 Mon Sep 17 00:00:00 2001 From: Tomas Babej Date: Sun, 28 Dec 2014 01:54:22 +0100 Subject: [PATCH] Task: Make Task object non-iterable --- tasklib/task.py | 8 ++++++++ 1 file changed, 8 insertions(+) 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)) -- 2.39.2