<#20809 BoolOption does not allow default=None> Is...
# github-notifications
c
#20809 BoolOption does not allow default=None Issue created by vito-laurenza-zocdoc Describe the bug The doc string for the
BoolOption
type says:
If you don't provide a
default
value, this becomes a "tri-bool" where the property will return
None
if unset by the user.
This is consistent with the other "scalar" option types, however in practice
BoolOption
does not adhere to this behavior, while the others do. Given this example subsystem class:
Copy code
from pants.option.option_types import BoolOption, StrOption, IntOption, FloatOption
from pants.option.subsystem import Subsystem


class MySubsystem(Subsystem):
    name = "My subsystem"
    options_scope = "my-subsystem"
    help = "My subsystem"

    bool_option = BoolOption(
        help="a boolean",
        default=None,
    )
    int_option = IntOption(
        help="an integer",
        default=None,
    )
    float_option = FloatOption(
        help="a float",
        default=None,
    )
    str_option = StrOption(
        help="a string",
        default=None,
    )
We can see in the following help output that the default (and current) value for the
BoolOption
is
False
, not
None
as documented/expected:
Copy code
$ pants --no-pantsd help my-subsystem

`my-subsystem` subsystem options
--------------------------------

My subsystem

Activated by zocdoc.pants
Config section: [my-subsystem]

  --[no-]my-subsystem-bool-option
  PANTS_MY_SUBSYSTEM_BOOL_OPTION
  bool_option
      default: False
      current value: False
      a boolean

  --my-subsystem-int-option=<int>
  PANTS_MY_SUBSYSTEM_INT_OPTION
  int_option
      default: None
      current value: None
      an integer

  --my-subsystem-float-option=<float>
  PANTS_MY_SUBSYSTEM_FLOAT_OPTION
  float_option
      default: None
      current value: None
      a float

  --my-subsystem-str-option=<str>
  PANTS_MY_SUBSYSTEM_STR_OPTION
  str_option
      default: None
      current value: None
      a string
Pants version
Copy code
$ pants --version
2.19.0
OS MacOS on Apple silicon pantsbuild/pants