API change - changed the AttributeHandler/TagHandler.get() second argument to be 'default' instead of 'category' ('category' is now the third argument). The reasoning is that this brings the attributes.get() call in line with the similar-looking dict.get(), where you can do dict.get(key, default) to give a default value.
This commit is contained in:
parent
c34561dba2
commit
4ab6414ffa
2 changed files with 4 additions and 3 deletions
|
|
@ -239,7 +239,7 @@ class AttributeHandler(object):
|
|||
ret = [self._cache.get(skey) for skey in searchkeys if skey in self._cache]
|
||||
return ret[0] if len(ret) == 1 else ret
|
||||
|
||||
def get(self, key=None, category=None, default=None, return_obj=False,
|
||||
def get(self, key=None, default=None, category=None, return_obj=False,
|
||||
strattr=False, raise_exception=False, accessing_obj=None,
|
||||
default_access=True):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -146,12 +146,13 @@ class TagHandler(object):
|
|||
cachestring = "%s-%s" % (tagstr, category)
|
||||
self._cache[cachestring] = tagobj
|
||||
|
||||
def get(self, key, category=None, return_tagobj=False):
|
||||
def get(self, key, default=None, category=None, return_tagobj=False):
|
||||
"""
|
||||
Get the tag for the given key or list of tags.
|
||||
|
||||
Args:
|
||||
key (str or list): The tag or tags to retrieve.
|
||||
default (any, optional): The value to return in case of no match.
|
||||
category (str, optional): The Tag category to limit the
|
||||
request to. Note that `None` is the valid, default
|
||||
category.
|
||||
|
|
@ -171,7 +172,7 @@ class TagHandler(object):
|
|||
searchkey = ["%s-%s" % (key.strip().lower(), category) if key is not None else None for key in make_iter(key)]
|
||||
ret = [val for val in (self._cache.get(keystr) for keystr in searchkey) if val]
|
||||
ret = [to_str(tag.db_data) for tag in ret] if return_tagobj else ret
|
||||
return ret[0] if len(ret) == 1 else ret
|
||||
return ret[0] if len(ret) == 1 else (ret if ret else default)
|
||||
|
||||
def remove(self, key, category=None):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue