Skip to content

Type casting issue when an argument is optional #15

@bolinocroustibat

Description

@bolinocroustibat
  • Python version: 3.11 (could also be reproduced with 3.12 and 3.10)
  • minicli version: 0.5.3

Hi, thanks for the useful lib. We recently ran into an unexpected behaviour when hint typing the CLI functions.
Minimal reproduction:

from minicli import cli, run

@cli
async def age(my_age: int = None) -> None:
    if my_age:
        print(type(my_age))

@cli
async def age_optional(my_age: int | None = None) -> None:
    if my_age:
        print(type(my_age))

if __name__ == "__main__":
    run()

When running the commands:

  • First command (age) returns int
  • Second command (age_optional) incorrectly returns str

Note: same behaviour with Optional[int] and Union[int, None].

Is this expected?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions