from pydantic import BaseModel
from pydantic_settings import BaseSettings, CliSubCommand, get_subcommand
from typing_extensions import reveal_type
class Foo(BaseModel):
bar: int = 1
class CliSettings(BaseSettings):
foo: CliSubCommand[Foo] = None
def main():
subcommand = get_subcommand(CliSettings())
reveal_type(subcommand) # Type of "subcommand" is "CliSettings | None"
if __name__ == '__main__':
main()
In the above code, subcommand
's type is CliSettings
, but it's supposed to be BaseModel
. It's because get_subcommand
's first parameter model
is a generic type PydanticModel
.