-
-
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
Using some_type | None
syntax for type annotations causes error in python 3.11
#533
Comments
I'm having the same issue. Using |
@tiangolo, Any updates on this feature? |
Related to |
Hi and thanks a lot for this great library! I've run into this issue as well. May someone provide some guidance on what should be fixed, |
I have the same issue with Python 3.10. Any advisory on how to fix this? |
Switching from |
That is a pretty good workaround, but for me it means that I have to configure my linters one way for modules that use typer and another way for the rest of the code. |
pyupgrade will respect type aliases, as will typer. It's unwieldy, but this means you can do the following without having to configure pyupgrade to keep runtime types:
|
For me, I'd rather use I think the idea here is that we ideally want to use |
Agree, for now I've just disabled linting in that specific line, in Ruff you can do it with |
It would be great to use |
I am stuck between Typer not supporting the new python syntax with
|
Any updates on this? |
Hello all! Thanks for the feedback. ☕ This should have been fixed by #548 It is now available in Typer |
Just upgraded to Typer 0.12.4 but still same error:
|
@tonjo please create a new discussion filling all the form data, including a minimal reproducible example we can copy and run to see your error. Doing it with the original issue seems solved, so there's probably something different in your use case. |
Hey @tonjo have you created a new issue? I'm getting the same issue if I try the operand inside "Annotated" app.command('some')
def some(
option: Annotated[list | str, typer.Option()] = None,
):
... In case I can open a new Issue if you didn't do it yet |
@tonjo If you're getting the following error, you're probably on an earlier version:
@pdonorio
|
Thanks, using |
Somehow still broken under python 3.10, typer 0.12.5. max_tokens: Annotated[int | None, typer.Option(help="Max tokens")] = None, max_tokens
Input should be a valid integer [type=int_type, input_value=None, input_type=NoneType]
For further information visit https://errors.pydantic.dev/2.9/v/int_type Somehow the validation did not pass to pydantic correctly |
❯ python --version
Python 3.11.9 and
or indeed version 0.12.4 as well, I still get AssertionError: Typer Currently doesn't support Union types Downgrading back to 0.12.3 complains then about
Though, I have more "unions", also in the form of |
This means you are bound to Python 3.10 ? In 3.11 (which is how this thread begun) it works. |
If I remember correctly, the |
Indeed the problem here is more complex unions. I removed these for now and it works. But why not add support for it ? |
Indeed, i think Typer should support it (at least for all current python type annotations). In the future, i would hope that it supports all pydantic basemodel types as well. |
I think a "fix" would need to go around https://github.com/fastapi/typer/blob/master/typer/main.py#L844-L852. |
Closing this issue as the original topic/problem has been addressed by #548. Thanks for all the discussion! If there are remaining/related issues, please open a new discussion thread - it's easier to have one specific topic per thread 🙏 |
First Check
Commit to Help
Example Code
Description
In python 3.10 this script runs as expected, but on 3.11 I get the following error
Operating System
macOS
Operating System Details
No response
Typer Version
0.7.0
Python Version
3.11.0
Additional Context
I believe the issue is that for some reason,
typing.get_type_hints
is no longer converting theUnionType
into aUnion
. I would suggest as a fix thatget_click_param
usetyping.get_origin/get_args
instead of__args__
and__origin__
attributes.The text was updated successfully, but these errors were encountered: