CLI: cli_implicit_flags=True with nested model booleans naming issue
rredburn opened this issue · comments
Given a settings class with a nested model and cli_implicit_flags enabled like so:
class Nested(BaseModel):
foo: bool = False
class Options(BaseSettings, cli_implicit_flags=True):
nested: NestedThe generated cli variant for the no-foo version (foo=False) creates --no-nested.foo vs --nested.no-foo. Is this intended and desired? I expected the latter value.
usage: example.py [-h] [--nested JSON] [--nested.foo | --no-nested.foo]
options:
-h, --help show this help message and exit
nested options:
--nested JSON set nested from JSON string
--nested.foo, --no-nested.foo
(default: False)This next example may be a bit contrived, but if another nested model existed with name no_nested it could get confusing, it not create outright conflicts.
nested options:
--nested JSON set nested from JSON string
--nested.foo, --no-nested.foo
(default: False)
no_nested options:
--no_nested JSON set no_nested from JSON string
--no_nested.foo, --no-no_nested.foo
(default: False)
@kschwab could you please take a look?
Hey @rredburn, yes, the above --no-nested.foo is expected. It's a result of the underlying argparse implementation for optional flags and how they handle their naming.
The second case from a parsing perspective will not create conflicts. Definitely confusing from a user perspective though, but I think this is an unlikely (i.e. agree that this is a mostly contrived) case.
@kschwab can we do something here or you think we can close the issue?
@hramezani this one is ok to close.