-
-
Notifications
You must be signed in to change notification settings - Fork 678
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
TypeError: unsupported operand type(s) for |: 'type' and 'NoneType' #371
Comments
There's a bug with `typer` when using `annotations` from `__future__`. So revert to using vanilla python type annotations. BUG: fastapi/typer#371
def test(flag: bool | None = typer.Option(None, "--flag", "-f", help="A flag")): Either you can use def test(flag: "bool | None" = typer.Option(None, "--flag", "-f", help="A flag")): |
I've imported it from Also, this sample code works in python 3.8, as I've imported from __future__ import annotations
def test(arg: int | str) -> None:
print(arg)
test("string")
test(999) |
I'm getting the same issue with python 3.10:
|
This causes Turns out my iPython was pointing to wrong python version (3.7.10) - Needed to point it to 3.10 |
Would the typealias String = str | None be a possibility? It should match the semantics. The other types (Float, ...) could also be turned into aliases. Though, Typealias seems to require python 3.10 (https://peps.python.org/pep-0613/). Is supporting < 3.10 a hard requirement for this module? |
by removing the | characters Some info here: fastapi/typer#371
Duplicate of |
Update for python3.8, support future annotations, see fastapi/typer#371
Reference for type hinting: fastapi/typer#371
Oh, I need this fix please! I started refactoring to use |
How to do in this case ? |
First Check
Commit to Help
Example Code
Description
Operating System
Linux
Operating System Details
No response
Typer Version
0.4.0
Python Version
Python 3.8.10
Additional Context
No response
The text was updated successfully, but these errors were encountered: