Return value from Typer function is printed only when installed
See original GitHub issueI 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:
- Created a year ago
- Comments:7 (7 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Awesome. Thanks @mcflugen!
@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
withimport click
, the extra output disappears.