-
-
Notifications
You must be signed in to change notification settings - Fork 671
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
Initial attempt at pydantic support. #630
base: master
Are you sure you want to change the base?
Conversation
📝 Docs preview for commit 1e0334f at: https://649ef33e50d4bf086d7df752--typertiangolo.netlify.app |
I tested it. It's great. thanks. but why you are parsing arguments as below:
it isn't better to do like this:
or:
|
Hi, thanks. As mentioned in the PR text,
is not available to us :( Your other option,
is probably doable, but that would introduce ambiguity for distinguishing submodels and scalar fields. The closest example of resolving such ambiguity can sometimes be found in env var configs in some applications, e.g. Just to re-iterate, I do agree, that this format is very ugly, and would be much more happy with |
Just to give my two cents. I'm doing something like this (not fully implemented) but with attr, my poison of choice atm. One thing that I'll add is that my use-case is similar to ssh's '-o' option, so I'm looking to use it's command line structure, which converted to your example would be:
doesn't look exactly right, since for the ssh use case the fields are clearly not intertwined as they are for your use-case. What I did for your use-case is just create a custom parser, which of course, doesn't get the pretty command line integration, but it is pretty usable. Either way I would suggest working backwards from the desired command line, while it's possible to create what you have, this would start to break down really quickly if you did something like def main(user: Annotated[list[User], typer.Argument[...]):
... |
@gkarg - thanks for this - I'd love to get pydantic (or any complex) models into the cli via this kind of logic! I'm relatively new to using typer (at least outside of quick tests), but familiar with click
I just tested with click version e.g.
Won't work, but:
Will work with Alternatively, but more clunkily, forwarding unprocessed args could handle it - that was how i did it previously (fragilely) when I was trying to do In the past i tried to implement |
Note: I started another draft implementation for pydantic support in #803 which isn't as tightly coupled to |
This PR builds on #111 (comment) by @sm-hawkfish / @ananis25
and attempts to implement #111 (comment) as described by @pypae
To re-state the problem this tries to solve:
This PR basically implements this, with one major (and many minor) problems:
.
(dot) in the name inclick
itself :(--
delimiter, and it looks like this:->
which is, admittedly, very ugly, but oh well.
Beside that, I've yet to test all corner cases and weird field/param combinations (and write proper tests), and probably think long and hard, if things like
should/shouldn't be allowed, etc.
However, I'd love to first hear your thoughts on the viability of this PR in general.