-
-
Notifications
You must be signed in to change notification settings - Fork 672
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
Is support for Union types on the roadmap? #461
Comments
https://typer.tiangolo.com/tutorial/commands/help/#help-panels-for-cli-parameters |
Just wanted to throw some more engagement on this issue. The number of issues around even the simple A quick example of what I'm looking to do:
Currently, I have to fall back on a |
@ntaylorwss excellent example. much better than the one i gave and, funnily enough, exactly what i'm after as well. cheers! |
Just wanted to chime in here. The official Mypy docs lean toward using See the example here from those docs (the Note that supporting literals would solve #76, which has a lot of recent activity, despite a bot marking it closed 😅... I think #669 is a pretty complete PR for this, though @pchanial would have to chime in on whether that PR already supports compound literals already. :) To demonstrate @ntaylorwss 's example, OptA = Literal['A']
OptB = Literal['B']
MyOpts = Literal[OptA, OptB]
### or, equivalently, but without needed OptA/B later ###
MyOpts = Literal['A', 'B'] |
I haven't tried compound Literals, but that's something I could look at if @tiangolo is willing to add Literal handling on the roadmap. |
+1 Would love to see Literal handling as well.
|
Use case for a Union: I'd like my program to accept URL (custom type) or Path as a parameter |
Is there any workaround for this currently? I've got a usecase where I need to be able to accept any of |
It would be nice if typer would allow me to use a Union when passing a |
Please, please make UNION possible for typer as e.g. |
First Check
Commit to Help
Example Code
Description
Typer does not yet support Union types. Running the above snippet yields:
Not sure how much demand there is for this feature, but I'd personally love to have it.
Operating System
macOS
Operating System Details
No response
Typer Version
0.6.1
Python Version
3.10
Additional Context
Typer is amazing. Absolutely in love with it 💖.
The text was updated successfully, but these errors were encountered: