Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BoolOption does not allow default=None #20809

Open
vito-laurenza-zocdoc opened this issue Apr 18, 2024 · 2 comments
Open

BoolOption does not allow default=None #20809

vito-laurenza-zocdoc opened this issue Apr 18, 2024 · 2 comments
Labels
bug external-plugins Issues related to plugins outside this repository

Comments

@vito-laurenza-zocdoc
Copy link

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:

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:

$ 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

$ pants --version
2.19.0

OS
MacOS on Apple silicon

@vito-laurenza-zocdoc
Copy link
Author

@sureshjoshi
Copy link
Member

As per my comment in Slack, apparently you need to use UnsetBool

from pants.option.custom_types import UnsetBool

    foo = BoolOption(
        default=UnsetBool,
        help="bar",
    )

@huonw huonw added the external-plugins Issues related to plugins outside this repository label Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug external-plugins Issues related to plugins outside this repository
Projects
None yet
Development

No branches or pull requests

3 participants