cache: Do not store None as a value in the vimwikitask_cache

This commit is contained in:
Tomas Babej 2015-08-10 01:02:47 +02:00
parent 4b2514e731
commit 15fd8ae46d

View file

@ -74,6 +74,9 @@ class TaskCache(object):
if vimwikitask is None:
vimwikitask = vwtask.VimwikiTask.from_line(self, key)
# If we successfully parsed a task, save it to the cache
if vimwikitask is not None:
self.vimwikitask_cache[key] = vimwikitask
return vimwikitask # May return None if the line has no task
@ -93,6 +96,12 @@ class TaskCache(object):
raise ValueError("Wrong key type: %s (%s)" % (key, type(key)))
def __setitem__(self, key, value):
# Never store None in the cache, treat it as deletion
if value is None:
if key in self:
del self[key]
return
# String keys refer to the Task objects
if type(key) is vwtask.ShortUUID:
self.task_cache[key] = value
@ -107,7 +116,7 @@ class TaskCache(object):
def __delitem__(self, key):
# String keys refer to the Task objects
if type(key) in (str, unicode):
if type(key) is vwtask.ShortUUID:
del self.task_cache[key]
# Integer keys (line numbers) refer to the VimwikiTask objects
@ -118,6 +127,19 @@ class TaskCache(object):
else:
raise ValueError("Wrong key type: %s (%s)" % (key, type(key)))
def __contains__(self, key):
# String keys refer to the Task objects
if type(key) is vwtask.ShortUUID:
return key in self.task_cache
# Integer keys (line numbers) refer to the VimwikiTask objects
elif type(key) is int:
return key in self.vimwikitask_cache
# Anything else is wrong
else:
raise ValueError("Wrong key type: %s (%s)" % (key, type(key)))
@property
def vimwikitask_dependency_order(self):
iterated_cache = {