Skip to content

The return type of get_subcommand is the same as the first argument #646

@ausaki

Description

@ausaki
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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions