moskomule / chika

chika is a simple and easy config tool for hierarchical configurations.
MIT License
20 stars 3 forks source link

chika.sequence does not work as expected when size is not specified #10

Closed moskomule closed 3 years ago

moskomule commented 3 years ago

chika.sequence does not work as expected when size is not specified. Also, the float values seem to be converted to [("0", ".", "9")] etc.

moskomule commented 3 years ago

Fix sequence like this:

def sequence(*values: Any,
             size: Optional[int] = None,
             help: Optional[str] = None
             ) -> dataclasses.Field:
    """ Add a default value of list, which is invalid in dataclass.

    Args:
        *values:
        size: size of sequence. If specified, the length is fixed, and if violated, ValueError will be raised.
        help: help message

    Returns: sequence with a help message

    """
    meta = {'default': list(values)}
    meta['nargs'] = size or '+'
    if help is not None:
        meta['help'] = help
    return dataclasses.field(default=tuple(values), metadata=meta)