-
-
Notifications
You must be signed in to change notification settings - Fork 680
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 Fix usage of
Annotated
with future annotations in Python 3.8
Fixes #802 `RuntimeError: Type not yet supported: typing_extensions.Annotated[...]` The solution is to use the `get_type_hints` method from `typing_extensions` instead of the built-in in the `typing` module, as it includes backports that support properly evaluating the forward reference.
- Loading branch information
1 parent
8bffffd
commit ab857cb
Showing
2 changed files
with
28 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from __future__ import annotations | ||
|
||
import typer | ||
from typer.testing import CliRunner | ||
from typing_extensions import Annotated | ||
|
||
runner = CliRunner() | ||
|
||
|
||
def test_annotated(): | ||
app = typer.Typer() | ||
|
||
@app.command() | ||
def cmd(force: Annotated[bool, typer.Option("--force")] = False): | ||
if force: | ||
print("Forcing operation") | ||
else: | ||
print("Not forcing") | ||
|
||
result = runner.invoke(app) | ||
assert result.exit_code == 0, result.output | ||
assert "Not forcing" in result.output | ||
|
||
result = runner.invoke(app, ["--force"]) | ||
assert result.exit_code == 0, result.output | ||
assert "Forcing operation" in result.output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters