From b81ef60f6172e256c2c366df7d6c035783df0f14 Mon Sep 17 00:00:00 2001 From: Zaar Hai Date: Thu, 30 Nov 2023 16:54:25 +1100 Subject: [PATCH 1/3] Support for postponed annotations Fixes #291 --- src/functions_framework/_typed_event.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions_framework/_typed_event.py b/src/functions_framework/_typed_event.py index 40e715ae..05e36027 100644 --- a/src/functions_framework/_typed_event.py +++ b/src/functions_framework/_typed_event.py @@ -31,7 +31,7 @@ def register_typed_event(decorator_type, func): try: - sig = signature(func) + sig = signature(func, eval_str=True) annotation_type = list(sig.parameters.values())[0].annotation input_type = _select_input_type(decorator_type, annotation_type) _validate_input_type(input_type) From 88000e4593be89132aa3b221c1a63c55b83068ae Mon Sep 17 00:00:00 2001 From: Zaar Hai Date: Thu, 30 Nov 2023 22:23:07 +1100 Subject: [PATCH 2/3] Compatibility with Python < 3.10 --- src/functions_framework/_typed_event.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/functions_framework/_typed_event.py b/src/functions_framework/_typed_event.py index 05e36027..6b0b1db5 100644 --- a/src/functions_framework/_typed_event.py +++ b/src/functions_framework/_typed_event.py @@ -12,10 +12,17 @@ # See the License for the specific language governing permissions and # limitations under the License. +import sys import inspect -from inspect import signature +from inspect import signature as _signature +if sys.version_info.major == 3 and sys.version_info.minor < 10: + signature = _signature +else: + from functools import partial + signature = partial(_signature, eval_str=True) + from functions_framework import _function_registry from functions_framework.exceptions import FunctionsFrameworkException From 5e3e445bdcb057518cc995df5225c8ca353f4f43 Mon Sep 17 00:00:00 2001 From: Zaar Hai Date: Thu, 30 Nov 2023 22:33:34 +1100 Subject: [PATCH 3/3] call singature cleanup --- src/functions_framework/_typed_event.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions_framework/_typed_event.py b/src/functions_framework/_typed_event.py index 6b0b1db5..e47d8235 100644 --- a/src/functions_framework/_typed_event.py +++ b/src/functions_framework/_typed_event.py @@ -38,7 +38,7 @@ def register_typed_event(decorator_type, func): try: - sig = signature(func, eval_str=True) + sig = signature(func) annotation_type = list(sig.parameters.values())[0].annotation input_type = _select_input_type(decorator_type, annotation_type) _validate_input_type(input_type)