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

Optional args #111

Open
hidaris opened this issue Aug 10, 2023 · 3 comments
Open

Optional args #111

hidaris opened this issue Aug 10, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@hidaris
Copy link

hidaris commented Aug 10, 2023

Hello, I noticed that in version 1.3, the help method converts Python objects into a JSON structure. However, the current implementation prevents the use of UnionType in action definitions, which makes the args unable to be optional.

I looked at the code, and the main reason for this is:

# type
 sig_annotation = signature.parameters[arg_name].annotation
 if sig_annotation is not None and sig_annotation.__name__ != "_empty":

When the argument type is a UnionType, sig_annotation does not have the __name__ attribute.

Is this a design decision?

@hidaris
Copy link
Author

hidaris commented Aug 10, 2023

@operand
Copy link
Owner

operand commented Aug 10, 2023

You mean individual optional arguments? Yeah those are not supported yet. It's only because I haven't gotten to it.

The API currently assumes all method args are required and are plain JSON serializable types like (dict, list, string, ...). I should add that to the documentation I think.

This wasn't so much a design decision but just that I haven't explored it yet. I will tinker with this to see how the API can be adjusted to allow optional args.

@hidaris
Copy link
Author

hidaris commented Aug 11, 2023

Yes, because after Python 3.10, the optional type is a special case of the union type, which can be written as int | None. In many scenarios, this is convenient for code reuse. However, what may need to be considered here is whether the action tends to be designed as a function with a single responsibility, which is also the reason I'm asking if it is a design decision.

@operand operand changed the title The args of "action" cannot be optional after version 1.3 Optional args Aug 11, 2023
@operand operand added the enhancement New feature or request label Aug 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants