Skip to content
Myr

🐛 Fix usage of `Annotated` with future annotations in Python 3.7+ (#814)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Iván Todorovich · committed by GitHub · parent 4efe1bc · Browse files · 2 files+28 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: svlandeg <svlandeg@github.com>

Diff stats

2 files+28 added−2 removed

  • tests:+26 added−0 removed
  • other:+2 added−2 removed

2 files+28 added−2 removed

added:tests/test_future_annotations.py+26 added
1from __future__ import annotations23import typer4from typer.testing import CliRunner5from typing_extensions import Annotated67runner = CliRunner()8910def test_annotated():11 app = typer.Typer()1213 @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")1920 result = runner.invoke(app)21 assert result.exit_code == 0, result.output22 assert "Not forcing" in result.output2324 result = runner.invoke(app, ["--force"])25 assert result.exit_code == 0, result.output26 assert "Forcing operation" in result.output
modified:typer/utils.py+2 added-2 removed
1import inspect2import sys3from copy import copy4from typing import Any, Callable, Dict, List, Tuple, Type, cast, get_type_hints4from typing import Any, Callable, Dict, List, Tuple, Type, cast56from typing_extensions import Annotated6from typing_extensions import Annotated, get_type_hints78from ._typing import get_args, get_origin9from .models import ArgumentInfo, OptionInfo, ParameterInfo, ParamMeta10
182 unmodified lines