From d336d75a8161fa0363e8ee69723305a7d1395038 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 22 Jul 2013 12:59:07 +0530 Subject: [PATCH] Add a comment explaining the use of a bytestring for default sort key --- src/calibre/db/fields.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/calibre/db/fields.py b/src/calibre/db/fields.py index 933a4c861c..403a76707c 100644 --- a/src/calibre/db/fields.py +++ b/src/calibre/db/fields.py @@ -31,7 +31,13 @@ class Field(object): self.has_text_data = dt in {'text', 'comments', 'series', 'enumeration'} self.table_type = self.table.table_type self._sort_key = (sort_key if dt in ('text', 'series', 'enumeration') else lambda x: x) + + # This will be compared to the output of sort_key() which is a + # bytestring, therefore it is safer to have it be a bytestring. + # Coercing an empty bytestring to unicode will never fail, but the + # output of sort_key cannot be coerced to unicode self._default_sort_key = b'' + if dt in {'int', 'float', 'rating'}: self._default_sort_key = 0 elif dt == 'bool':