Skip to content

Commit

Permalink
Add eval_str to inspect.signature
Browse files Browse the repository at this point in the history
  • Loading branch information
heckad committed Dec 19, 2023
1 parent 3a7264c commit 928cca6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions tests/test_annotated.py
Expand Up @@ -21,6 +21,22 @@ def cmd(val: Annotated[int, typer.Argument()] = 0):
assert "hello 42" in result.output


def test_annotated_argument_in_string_type_with_default():
app = typer.Typer()

@app.command()
def cmd(val: "Annotated[int, typer.Argument()]" = 0):
print(f"hello {val}")

result = runner.invoke(app)
assert result.exit_code == 0, result.output
assert "hello 0" in result.output

result = runner.invoke(app, ["42"])
assert result.exit_code == 0, result.output
assert "hello 42" in result.output


def test_annotated_argument_with_default_factory():
app = typer.Typer()

Expand Down
2 changes: 1 addition & 1 deletion typer/utils.py
Expand Up @@ -106,7 +106,7 @@ def _split_annotation_from_typer_annotations(


def get_params_from_function(func: Callable[..., Any]) -> Dict[str, ParamMeta]:
signature = inspect.signature(func)
signature = inspect.signature(func, eval_str=True)
type_hints = get_type_hints(func)
params = {}
for param in signature.parameters.values():
Expand Down

0 comments on commit 928cca6

Please sign in to comment.