Skip to content

Commit ca65b36

Browse files
🐛 Fix usage of Annotated with future annotations in Python 3.7+ (#814)
Co-authored-by: svlandeg <svlandeg@github.com>
1 parent 4efe1bc commit ca65b36

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

tests/test_future_annotations.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from __future__ import annotations
2+
3+
import typer
4+
from typer.testing import CliRunner
5+
from typing_extensions import Annotated
6+
7+
runner = CliRunner()
8+
9+
10+
def test_annotated():
11+
app = typer.Typer()
12+
13+
@app.command()
14+
def cmd(force: Annotated[bool, typer.Option("--force")] = False):
15+
if force:
16+
print("Forcing operation")
17+
else:
18+
print("Not forcing")
19+
20+
result = runner.invoke(app)
21+
assert result.exit_code == 0, result.output
22+
assert "Not forcing" in result.output
23+
24+
result = runner.invoke(app, ["--force"])
25+
assert result.exit_code == 0, result.output
26+
assert "Forcing operation" in result.output

typer/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import inspect
22
import sys
33
from copy import copy
4-
from typing import Any, Callable, Dict, List, Tuple, Type, cast, get_type_hints
4+
from typing import Any, Callable, Dict, List, Tuple, Type, cast
55

6-
from typing_extensions import Annotated
6+
from typing_extensions import Annotated, get_type_hints
77

88
from ._typing import get_args, get_origin
99
from .models import ArgumentInfo, OptionInfo, ParameterInfo, ParamMeta

0 commit comments

Comments
 (0)