Closed ebrehault closed 1 year ago
No, there is no existing method for doing this, and I don't recommend it.
Instead, you could define __str__ on whatever value you're returning so that when it is serialized, it prints the way you want. (This only works if the return type is something you control.)
Another alternative is you can call Fire(serialize=your_fn)
passing a serialization function for the serialize argument.
If you really want to figure out if you're in a Fire context or not (and again, I don't recommend this), it should be possible e.g. by inspecting the current stack.
Defining __str__
is definitely the most pythonic approach, I like it :)
Thanks!
When we use a library both directly as dependency in some projects and through Fire, it could be interesting to know if the code is currently executed in Fire context or not. Typically, we might want a given method to return JSON when used via Fire or an actual object if not:
Is there any existing way to have this
is_fire_context
check?