Consider main.py:
from __future__ importannotationsimportfunctions_frameworkimportflaskclassHelloRequest:
name: strdef__init__(self, name: str) ->None:
self.name=name@classmethoddeffrom_dict(cls, d: dict) ->HellowRequest:
returncls(**d)
defto_dict(self) ->dict:
returnself.__dict__@functions_framework.typeddefhello(hr: HelloRequest) ->flask.typing.ResponseReturnValue:
returnf"Hello, {hr.name}"Running import main yields:
input_type=HelloRequest, type(input_type)=<class 'str'>
Traceback (most recent call last):
File "/home/....venv/lib/python3.11/site-packages/functions_framework/_typed_event.py", line 37, in register_typed_event
_validate_input_type(input_type)
File "/home/.../.venv/lib/python3.11/site-packages/functions_framework/_typed_event.py", line 103, in _validate_input_type
raise AttributeError(
AttributeError: The type HelloRequest does not have the required method called 'from_dict'.
The culprit is from __future__ import annotations, which is required to annotate from_dict properly.
The issue is here where inspect.signature will return annotations as strings (by default) if they are postponed.
The suggested solution is to pass eval_str=True when calling inspect.signature.
Consider
main.py:Running
import mainyields:The culprit is
from __future__ import annotations, which is required to annotatefrom_dictproperly.The issue is here where
inspect.signaturewill return annotations as strings (by default) if they are postponed.The suggested solution is to pass
eval_str=Truewhen callinginspect.signature.