question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Return value from Typer function is printed only when installed

See original GitHub issue

I apologize in advance for how obscure this bug is.

I’ll start by taking the simple Typer demo and modifying it to have download return a string:


import rich_click.typer as typer

app = typer.Typer()

@app.command()
def sync(
    type: str = typer.Option("files", help="Type of file to sync"),
    all: bool = typer.Option(False, help="Sync all the things?"),
):
    print("Syncing")


@app.command()
def download(all: bool = typer.Option(False, help="Get everything")):
    return "Shouldn't appear" # <-- RETURNS A STRING NOW


if __name__ == "__main__":
    app()

When run directly, everything is normal:

$ python vdsearch/test.py download
$

Now let’s pip install -e . with testy mapped to test:app

$ testy download
Shouldn't appear
$

I’ve gotten around this bug by defining wrapper functions for my functions but it would be nice to get to the bottom of what’s going on.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
ewelscommented, Jun 21, 2022

Awesome. Thanks @mcflugen!

1reaction
mcflugencommented, Jun 20, 2022

@ewels, sorry, I forgot to mention that I’ve only seen this behavior when I use rich-click, unfortunately. So if in my example I replace import rich_click as click with import click, the extra output disappears.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CLI Option Callback and Context - Typer - tiangolo
The function receives the value from the command line. It can do anything with it, and then return the value. In this case,...
Read more >
Function return values - Learn web development | MDN
When the function completes (finishes running), it returns a value, which is a new string with the replacement made. In the code above,...
Read more >
Print Statement in Python – How to Print with Example Syntax ...
The print() function has no return value. How to Print Objects in Python. Even if you don't pass in any arguments to print()...
Read more >
Built-in Functions — Python 3.11.1 documentation
The return value is None . In all cases, if the optional parts are omitted, the code is executed in the current scope....
Read more >
KB5005652—Manage new Point and Print default driver ...
Default behavior: Setting this value to 1 or if the key is not defined or not present, will require administrator privilege to install...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found