<#19126 Change options declarations to use subclas...
# github-notifications
c
#19126 Change options declarations to use subclasses New discussion created by thejcannon I want to fix #18856, which has a secondary benefit of making rule inputs more fine-grained. The only way to accomplish that is by converting options declarations to be types, so that they are valid annotations. As a strawman, that'd look something like:
Copy code
class GlobalOptions(BootstrapOptions, Subsystem):
    options_scope = GLOBAL_SCOPE
    help = "Options to control the overall behavior of Pants."

    @bool_option
    class Colors:
        default = sys.stdout.isatty()
        help = softwrap(
            """
            Whether Pants should use colors in output or not. This may also impact whether
            some tools Pants runs use color.

            When unset, this value defaults based on whether the output destination supports color.
            """
        )
which was previously:
Copy code
colors = BoolOption(
        default=sys.stdout.isatty(),
        help=softwrap(
            """
            Whether Pants should use colors in output or not. This may also impact whether
            some tools Pants runs use color.

            When unset, this value defaults based on whether the output destination supports color.
            """
        ),
    )
Then rule code needing the option would use:
Copy code
@rule
def my_rule(colors_container: GlobalOptions.Colors) -> ...:
    colors_container.value  # known to be type `bool`
    # And we'd also have `colors_container.is_default_value` of type `bool`
    #    instead of `subsystem.options.is_default("<name>")`
This would extend to environment-aware options as well (although the details are fuzzy to me) pantsbuild/pants