Skip to content

BUG: setting a boolean parameter via the command line break runtime #4462

@neutrinoceros

Description

@neutrinoceros

Bug report

Bug summary

Code for reproduction

$ yt config set --local yt colored_logs true && python -c "import yt"

Actual outcome

Traceback (most recent call last):
  File "/Users/robcleme/.pyenv/versions/yt-dev/bin/yt", line 8, in <module>
    sys.exit(run_main())
             ^^^^^^^^^^
  File "/Users/robcleme/dev/yt-project/yt/yt/utilities/command_line.py", line 1615, in run_main
    args.func(args)
  File "/Users/robcleme/dev/yt-project/yt/yt/utilities/command_line.py", line 228, in run
    self(args)
  File "/Users/robcleme/dev/yt-project/yt/yt/utilities/command_line.py", line 1402, in __call__
    set_config(args.section, args.option, args.value, self.config_file)
  File "/Users/robcleme/dev/yt-project/yt/yt/utilities/configure.py", line 195, in set_config
    CONFIG.set(section, *option_path, _cast_value_helper(value))
  File "/Users/robcleme/dev/yt-project/yt/yt/utilities/configure.py", line 79, in set
    self.config_root.upsert_from_list(
  File "/Users/robcleme/dev/yt-project/yt/yt/utilities/configuration_tree.py", line 54, in upsert_from_list
    next_node.upsert_from_list(next_keys, value, extra_data)
  File "/Users/robcleme/dev/yt-project/yt/yt/utilities/configuration_tree.py", line 46, in upsert_from_list
    leaf.value = value
    ^^^^^^^^^^
  File "/Users/robcleme/dev/yt-project/yt/yt/utilities/configuration_tree.py", line 187, in value
    raise TypeError(msg)
TypeError: Error when setting yt.colored_logs.
Tried to assign a value of type <class 'str'>, expected type <class 'bool'>.
This entry was last modified in file: /Users/robcleme/dev/yt-project/yt/yt.toml.

One way to patch this would be to special-case true and false to be interpreted as booleans when received from the command line.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions