Skip to content

[BUG] Context .invoke() fails quietly and .forward() fails #102

@jmaroeder

Description

@jmaroeder

Describe the bug

When attempting to use the invoke() or forward() methods on a typer.Context object, the results are unpredictable, resulting in either outright failures, or passing of strange values in place of defaults.

To Reproduce

  • Create a file main.py with:
import typer

app = typer.Typer()

@app.command()
def test(count: int = typer.Option(1, help="How high to count")):
    typer.echo(f"Count: {count}")

@app.command()
def forward(ctx: typer.Context, count: int = 1):
    ctx.forward(test)

@app.command()
def invoke(ctx: typer.Context):
    ctx.invoke(test)

if __name__ == "__main__":
    app()
  • Call it with:
python main.py forward
  • It outputs:
...
TypeError: Callback is not a command.
  • But I expected it to output:
Count: 42
  • Call it with:
python main.py invoke
  • It outputs:
Count: <typer.models.OptionInfo object at 0x10e082a10>
  • But I expected it to output:
Count: 1

Expected behavior

It should be possible to use .invoke() on typer.Context objects in a manner similar to that described in the click documentation.

Environment

  • OS: macOS
  • Typer Version: 0.2.1
  • Python version: 3.7.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions