Handle spawned attrs with dict, as per #1787
This commit is contained in:
parent
e9df197385
commit
5f8e08ecaf
2 changed files with 8 additions and 8 deletions
|
|
@ -106,7 +106,7 @@ def _format_option_value(prop, required=False, prototype=None, cropper=None):
|
||||||
if utils.is_iter(prop):
|
if utils.is_iter(prop):
|
||||||
out = ", ".join(str(pr) for pr in prop)
|
out = ", ".join(str(pr) for pr in prop)
|
||||||
if not out and required:
|
if not out and required:
|
||||||
out = "|rreqrd"
|
out = "|runset"
|
||||||
if out:
|
if out:
|
||||||
return " ({}|n)".format(cropper(out) if cropper else utils.crop(out, _MENU_CROP_WIDTH))
|
return " ({}|n)".format(cropper(out) if cropper else utils.crop(out, _MENU_CROP_WIDTH))
|
||||||
return ""
|
return ""
|
||||||
|
|
|
||||||
|
|
@ -152,7 +152,7 @@ def save_prototype(prototype):
|
||||||
Create/Store a prototype persistently.
|
Create/Store a prototype persistently.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
prototype (dict): The prototype to save. A `prototype_key` key is
|
prototype (dict): The prototype to save. A `prototype_key` key is
|
||||||
required.
|
required.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
|
@ -267,18 +267,18 @@ def search_prototype(key=None, tags=None, require_single=False):
|
||||||
|
|
||||||
Kwargs:
|
Kwargs:
|
||||||
key (str): An exact or partial key to query for.
|
key (str): An exact or partial key to query for.
|
||||||
tags (str or list): Tag key or keys to query for. These
|
tags (str or list): Tag key or keys to query for. These
|
||||||
will always be applied with the 'db_protototype'
|
will always be applied with the 'db_protototype'
|
||||||
tag category.
|
tag category.
|
||||||
require_single (bool): If set, raise KeyError if the result
|
require_single (bool): If set, raise KeyError if the result
|
||||||
was not found or if there are multiple matches.
|
was not found or if there are multiple matches.
|
||||||
|
|
||||||
Return:
|
Return:
|
||||||
matches (list): All found prototype dicts. Empty list if
|
matches (list): All found prototype dicts. Empty list if
|
||||||
no match was found. Note that if neither `key` nor `tags`
|
no match was found. Note that if neither `key` nor `tags`
|
||||||
were given, *all* available prototypes will be returned.
|
were given, *all* available prototypes will be returned.
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
KeyError: If `require_single` is True and there are 0 or >1 matches.
|
KeyError: If `require_single` is True and there are 0 or >1 matches.
|
||||||
|
|
||||||
Note:
|
Note:
|
||||||
|
|
@ -336,7 +336,7 @@ def search_prototype(key=None, tags=None, require_single=False):
|
||||||
if mta.get('prototype_key') and mta['prototype_key'] == key]
|
if mta.get('prototype_key') and mta['prototype_key'] == key]
|
||||||
if filter_matches and len(filter_matches) < nmatches:
|
if filter_matches and len(filter_matches) < nmatches:
|
||||||
matches = filter_matches
|
matches = filter_matches
|
||||||
|
|
||||||
nmatches = len(matches)
|
nmatches = len(matches)
|
||||||
if nmatches != 1 and require_single:
|
if nmatches != 1 and require_single:
|
||||||
raise KeyError("Found {} matching prototypes.".format(nmatches))
|
raise KeyError("Found {} matching prototypes.".format(nmatches))
|
||||||
|
|
@ -739,7 +739,7 @@ def init_spawn_value(value, validator=None):
|
||||||
validator = validator if validator else lambda o: o
|
validator = validator if validator else lambda o: o
|
||||||
if callable(value):
|
if callable(value):
|
||||||
value = validator(value())
|
value = validator(value())
|
||||||
elif value and is_iter(value) and callable(value[0]):
|
elif value and isinstance(value, (list, tuple)) and callable(value[0]):
|
||||||
# a structure (callable, (args, ))
|
# a structure (callable, (args, ))
|
||||||
args = value[1:]
|
args = value[1:]
|
||||||
value = validator(value[0](*make_iter(args)))
|
value = validator(value[0](*make_iter(args)))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue