From 8d20fdcd45412466f8c9393fed3c9e5293a81c0e Mon Sep 17 00:00:00 2001 From: Adam Coddington Date: Tue, 15 Apr 2014 16:15:17 -0700 Subject: [PATCH 1/2] Make annotations really be strings, just special ones. --- taskw/fields/annotationarray.py | 33 +++++---------------------------- 1 file changed, 5 insertions(+), 28 deletions(-) diff --git a/taskw/fields/annotationarray.py b/taskw/fields/annotationarray.py index 0a59b83..118f453 100644 --- a/taskw/fields/annotationarray.py +++ b/taskw/fields/annotationarray.py @@ -1,5 +1,3 @@ -import sys - from dateutil.parser import parse import six @@ -7,7 +5,7 @@ from .base import DirtyableList -class Annotation(object): +class Annotation(six.text_type): """ A special type of string that we'll use for storing annotations. This is, for all intents and purposes, really just a string, but @@ -15,10 +13,12 @@ class Annotation(object): this application: the annotation's entry date. """ + def __new__(self, description, entry=None): + return six.text_type.__new__(self, description) + def __init__(self, description, entry=None): - self._description = description self._entry = entry - super(Annotation, self).__init__() + super(Annotation, self).__init__(description) @property def entry(self): @@ -26,29 +26,6 @@ def entry(self): return parse(self._entry) return self._entry - def __str__(self): - if six.PY3: - return six.text_type(self._description) - return self.__unicode__().encode(sys.getdefaultencoding()) - - def __eq__(self, other): - value = other - if isinstance(other, Annotation): - value = other._description - return self._description == value - - def __ne__(self, other): - value = other - if isinstance(other, Annotation): - value = other._description - return self._description != value - - def __unicode__(self): - return six.text_type(self._description) - - def __repr__(self): - return repr(six.text_type(self._description)) - class AnnotationArrayField(ArrayField): """ A special case of the ArrayField handling idiosyncrasies of Annotations From 8d62c47508520d6fdd46d90a10af553d3865b79c Mon Sep 17 00:00:00 2001 From: Adam Coddington Date: Tue, 15 Apr 2014 16:40:34 -0700 Subject: [PATCH 2/2] That's surprising, but I suppose __new__ takes care of these detais. --- taskw/fields/annotationarray.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/taskw/fields/annotationarray.py b/taskw/fields/annotationarray.py index 118f453..245e4a4 100644 --- a/taskw/fields/annotationarray.py +++ b/taskw/fields/annotationarray.py @@ -18,7 +18,7 @@ def __new__(self, description, entry=None): def __init__(self, description, entry=None): self._entry = entry - super(Annotation, self).__init__(description) + super(Annotation, self).__init__() @property def entry(self):