Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress printing of function return #179

Closed
mauriceling opened this issue Jun 11, 2019 · 7 comments
Closed

Suppress printing of function return #179

mauriceling opened this issue Jun 11, 2019 · 7 comments
Labels

Comments

@mauriceling
Copy link

Let's say I have a Fire exposed function

def X(paramA):
return {'paramA': paramA}

Fire will automatically print out the function return to the screen. It is possible to suppress the printing of function return?

@dbieber
Copy link
Member

dbieber commented Jun 11, 2019

Can you say a bit more about how this function is used?

If its only used by fire, you could just remove the return statement (since the return value isn't being used elsewhere anyway).
If its used by fire and in other ways, you could wrap X in a function that calls X and returns nothing, e.g.:

def X_cli(paramA): X(paramA)
fire.Fire(X_cli)

@mauriceling
Copy link
Author

Essentially, this function is to be used as both API and CLI. Hence, I will need the function to return a list of dictionaries for use as API. However, as CLI, the printout of the returned list of dictionaries is ugly. Therefore, I am looking for a way to suppress the printing of returned values (list of dictionaries) when the function is used as CLI as I will use a set of print functions to print it nicely on the screen.

@dbieber
Copy link
Member

dbieber commented Jun 13, 2019

Makes sense.

What are the types of the values in your returned dictionary?

It's on our list of TODOs to improve how dicts get printed. The current thinking is to leave the current method of printing dicts when the keys and values are all simple types, but to use the help screen (which is recently improved, and will come out in the next release) when the dict contains more complex types like functions, objects, etc. Would this solution help in your situation?

@dbieber
Copy link
Member

dbieber commented Jul 23, 2019

We've moved forward w/ this approach (showing the help screen when a dict contains complex types) and it will be available in Friday's release.

@dbieber dbieber closed this as completed Jul 23, 2019
@imdadahad
Copy link

Having the same issue. Not ideal to see 'ugly' dict payloads to be printed on the screen.

Is there any workaround?

@ckrapu
Copy link

ckrapu commented May 26, 2022

Same here - I started a decorator to check to see if the function is being called from Fire or somewhere else; any ideas on how to check that in a stable way?

@dbieber
Copy link
Member

dbieber commented May 26, 2022

#345 will be available in the next release and may provide what you're looking for

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants