Fix AttributeHandler.get with no Attributes. Also make return_list=True return [] rather than [None]. Resolves #1866
This commit is contained in:
parent
ea07a81696
commit
bb5324ba52
3 changed files with 21 additions and 28 deletions
|
|
@ -19,6 +19,10 @@ without arguments starts a full interactive Python console.
|
||||||
- Make new `CHANNEL_MUDINFO` setting for specifying the mudinfo channel
|
- Make new `CHANNEL_MUDINFO` setting for specifying the mudinfo channel
|
||||||
- Make `CHANNEL_CONNECTINFO` take full channel definition
|
- Make `CHANNEL_CONNECTINFO` take full channel definition
|
||||||
- Make `DEFAULT_CHANNELS` list auto-create channels missing at reload
|
- Make `DEFAULT_CHANNELS` list auto-create channels missing at reload
|
||||||
|
- Webclient `ANSI->HTML` parser updated. Webclient line width changed from 1.6em to 1.1em
|
||||||
|
to better make ANSI graphics look the same as for third-party clients
|
||||||
|
- `AttributeHandler.get(return_list=True)` will return `[]` if there are no
|
||||||
|
Attributes instead of `[None]`.
|
||||||
|
|
||||||
|
|
||||||
## Evennia 0.9 (2018-2019)
|
## Evennia 0.9 (2018-2019)
|
||||||
|
|
|
||||||
|
|
@ -223,7 +223,7 @@ def _run_code_snippet(caller, pycode, mode="eval", measure_time=False,
|
||||||
sys.stdout = old_stdout
|
sys.stdout = old_stdout
|
||||||
sys.stderr = old_stderr
|
sys.stderr = old_stderr
|
||||||
|
|
||||||
if not ret:
|
if ret is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
for session in sessions:
|
for session in sessions:
|
||||||
|
|
|
||||||
|
|
@ -420,10 +420,11 @@ class AttributeHandler(object):
|
||||||
return_list (bool, optional):
|
return_list (bool, optional):
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
result (any or list): One or more matches for keys and/or categories. Each match will be
|
result (any or list): One or more matches for keys and/or
|
||||||
the value of the found Attribute(s) unless `return_obj` is True, at which point it
|
categories. Each match will be the value of the found Attribute(s)
|
||||||
will be the attribute object itself or None. If `return_list` is True, this will
|
unless `return_obj` is True, at which point it will be the
|
||||||
always be a list, regardless of the number of elements.
|
attribute object itself or None. If `return_list` is True, this
|
||||||
|
will always be a list, regardless of the number of elements.
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
AttributeError: If `raise_exception` is set and no matching Attribute
|
AttributeError: If `raise_exception` is set and no matching Attribute
|
||||||
|
|
@ -431,15 +432,6 @@ class AttributeHandler(object):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class RetDefault(object):
|
|
||||||
"""Holds default values"""
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
self.key = None
|
|
||||||
self.value = default
|
|
||||||
self.category = None
|
|
||||||
self.strvalue = str(default) if default is not None else None
|
|
||||||
|
|
||||||
ret = []
|
ret = []
|
||||||
for keystr in make_iter(key):
|
for keystr in make_iter(key):
|
||||||
# it's okay to send a None key
|
# it's okay to send a None key
|
||||||
|
|
@ -450,13 +442,12 @@ class AttributeHandler(object):
|
||||||
raise AttributeError
|
raise AttributeError
|
||||||
elif return_obj:
|
elif return_obj:
|
||||||
ret.append(None)
|
ret.append(None)
|
||||||
else:
|
|
||||||
ret.append(RetDefault())
|
|
||||||
|
|
||||||
if accessing_obj:
|
if accessing_obj:
|
||||||
# check 'attrread' locks
|
# check 'attrread' locks
|
||||||
ret = [attr for attr in ret if attr.access(accessing_obj,
|
ret = [attr for attr in ret if attr.access(accessing_obj,
|
||||||
self._attrread, default=default_access)]
|
self._attrread,
|
||||||
|
default=default_access)]
|
||||||
if strattr:
|
if strattr:
|
||||||
ret = ret if return_obj else [attr.strvalue for attr in ret if attr]
|
ret = ret if return_obj else [attr.strvalue for attr in ret if attr]
|
||||||
else:
|
else:
|
||||||
|
|
@ -464,9 +455,7 @@ class AttributeHandler(object):
|
||||||
|
|
||||||
if return_list:
|
if return_list:
|
||||||
return ret if ret else [default] if default is not None else []
|
return ret if ret else [default] if default is not None else []
|
||||||
elif not ret:
|
return ret[0] if ret and len(ret) == 1 else ret or default
|
||||||
return ret if len(key) > 1 else default
|
|
||||||
return ret[0] if len(ret) == 1 else ret
|
|
||||||
|
|
||||||
def add(self, key, value, category=None, lockstring="",
|
def add(self, key, value, category=None, lockstring="",
|
||||||
strattr=False, accessing_obj=None, default_access=True):
|
strattr=False, accessing_obj=None, default_access=True):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue