From 139621d148340c5c8a6d01fc601c6bce36e63943 Mon Sep 17 00:00:00 2001 From: Matt Welke Date: Tue, 3 Jan 2023 15:02:40 -0500 Subject: [PATCH] Add support for function signatures - no param and returning nothing. All of our other runtimes support having a function that has no parameters. They also support having a function that returns nothing. In the case where nothing is returned by the function, the runtime returns an empty dictionary to the rest of the OpenWhisk system. This changes he Python runtime to match that behavior. --- core/python3Action/lib/launcher.py | 9 +++++++-- core/python3Action/lib/prelauncher.py | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/core/python3Action/lib/launcher.py b/core/python3Action/lib/launcher.py index f288b8f0..c7adc82f 100755 --- a/core/python3Action/lib/launcher.py +++ b/core/python3Action/lib/launcher.py @@ -62,12 +62,17 @@ def get_remaining_time_in_millis(self): return delta_ms if delta_ms > 0 else 0 def fun(payload, env): + # Compatibility: Supporting "old" context-less functions that have no params + # to match other languages. + if main.__code__.co_argcount == 0: + return main() or {} + # Compatibility: Supports "old" context-less functions. if main.__code__.co_argcount == 1: - return main(payload) + return main(payload) or {} # Lambda-like "new-style" function. - return main(payload, Context(env)) + return main(payload, Context(env)) or {} out = fdopen(3, "wb") if os.getenv("__OW_WAIT_FOR_ACK", "") != "": diff --git a/core/python3Action/lib/prelauncher.py b/core/python3Action/lib/prelauncher.py index 7f6d70ad..bb51a08b 100755 --- a/core/python3Action/lib/prelauncher.py +++ b/core/python3Action/lib/prelauncher.py @@ -114,12 +114,17 @@ def get_remaining_time_in_millis(self): return delta_ms if delta_ms > 0 else 0 def fun(payload, env): + # Compatibility: Supporting "old" context-less functions that have no params + # to match other languages. + if main.__code__.co_argcount == 0: + return main() or {} + # Compatibility: Supports "old" context-less functions. if main.__code__.co_argcount == 1: - return main(payload) + return main(payload) or {} # Lambda-like "new-style" function. - return main(payload, Context(env)) + return main(payload, Context(env)) or {} # Acknowledge the initialization. write_result({"ok": True})