Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type casting issue when an argument is optional #15

Open
bolinocroustibat opened this issue Sep 30, 2024 · 0 comments
Open

Type casting issue when an argument is optional #15

bolinocroustibat opened this issue Sep 30, 2024 · 0 comments

Comments

@bolinocroustibat
Copy link

bolinocroustibat commented Sep 30, 2024

  • 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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant