Skip to content

Commit

Permalink
[Optionable] Support for [] as default for list(dict)
Browse files Browse the repository at this point in the history
  • Loading branch information
set-soft committed Aug 14, 2024
1 parent 366eeeb commit ec52e4e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion kibot/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ def force_list(v):
return v if v is None or isinstance(v, list) else [v]


def typeof(v, cls):
def typeof(v, cls, valid=None):
if isinstance(v, bool):
return 'boolean'
if isinstance(v, (int, float)):
Expand All @@ -565,6 +565,8 @@ def typeof(v, cls):
return 'dict'
if isinstance(v, list):
if len(v) == 0:
if valid is not None:
return next(filter(lambda x: x.startswith('list('), valid), 'list(string)')
return 'list(string)'
return 'list({})'.format(typeof(v[0], cls))
return 'None'
Expand Down
2 changes: 1 addition & 1 deletion kibot/optionable.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def _perform_config_mapping(self):
v.set_default(def_val)
cur_val = getattr(self, alias)
# Get the type used by the user as a string
v_type = typeof(v, Optionable)
v_type = typeof(v, Optionable, valid)
if v_type not in valid and not self.check_string_dict(v_type, valid, k, v):
# Not a valid type for this key
if v_type == 'None':
Expand Down

0 comments on commit ec52e4e

Please sign in to comment.