Skip to content

Commit

Permalink
Merge pull request #61 from coddingtonbear/better_annotation_objects
Browse files Browse the repository at this point in the history
Make annotations really be strings, just special ones.
  • Loading branch information
ralphbean committed Apr 17, 2014
2 parents e2ef3bd + 8d62c47 commit f90fcc6
Showing 1 changed file with 4 additions and 27 deletions.
31 changes: 4 additions & 27 deletions taskw/fields/annotationarray.py
@@ -1,22 +1,22 @@
import sys

from dateutil.parser import parse
import six

from .array import ArrayField
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
it does allow us to store additional information if we have it -- in
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__()

Expand All @@ -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
Expand Down

0 comments on commit f90fcc6

Please sign in to comment.