X-Git-Url: https://git.madduck.net/etc/taskwarrior.git/blobdiff_plain/22e41afb63e6a1bd1627ee9711a7fd76907739bc..4c0d71c0c2a8b190249416b29b310f4afcab755b:/tasklib/task.py?ds=inline diff --git a/tasklib/task.py b/tasklib/task.py index 8fe1e1b..5acabe0 100644 --- a/tasklib/task.py +++ b/tasklib/task.py @@ -122,10 +122,21 @@ class Task(TaskResource): return self['description'] def __eq__(self, other): - return self['uuid'] == other['uuid'] + if self['uuid'] and other['uuid']: + # For saved Tasks, just define equality by equality of uuids + return self['uuid'] == other['uuid'] + else: + # If the tasks are not saved, compare the actual instances + return id(self) == id(other) + def __hash__(self): - return self['uuid'].__hash__() + if self['uuid']: + # For saved Tasks, just define equality by equality of uuids + return self['uuid'].__hash__() + else: + # If the tasks are not saved, return hash of instance id + return id(self).__hash__() @property def _modified_fields(self): @@ -154,6 +165,8 @@ class Task(TaskResource): return self['uuid'] is not None or self['id'] is not None def serialize_due(self, date): + if not date: + return None return date.strftime(DATE_FORMAT) def deserialize_due(self, date_str): @@ -291,7 +304,8 @@ class Task(TaskResource): elif field == 'depends': args.append('{0}:{1}'.format(field, self.format_depends())) else: - args.append('{0}:{1}'.format(field, self._data[field])) + # Use empty string to substitute for None value + args.append('{0}:{1}'.format(field, self._data[field] or '')) # If we're modifying saved task, simply pass on all modified fields if self.saved: