Uh oh!
There was an error while loading. Please reload this page.
feat: Support strongly typed functions signature - #208
Conversation
anniefu
commented
Nov 30, 2022
Could you add a description to the PR explaining the new feature and a code snippet sample of how to use it? I would define the typed class with the to_dict and from_dict functions in the code snippet to for illustrative purposes. |
anniefu
left a comment
There was a problem hiding this comment.
Whew, pretty big one! Nice work getting this done!
I think I reviewed everything except tests. But gonna get these comments out for now.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
anniefu
commented
Dec 7, 2022
Oh btw, for the lint check, you can copy the commands executed here to reproduce locally: https://github.com/GoogleCloudPlatform/functions-framework-python/blob/master/.github/workflows/lint.yml |
anniefu
left a comment
There was a problem hiding this comment.
Just nits and a existential-ish question
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| return wrapper | ||
| def typed(*args): |
There was a problem hiding this comment.
Hmm I've been pondering for a while whether there's a way for us to provide typing here where like someone could hover over the definition of @typed and see that it's supposed to just take one, optional input type parameter instead of this kind of ambiguous *args situation.
I'm not sure it's possible though unless we enforce a named parameter like @typed(input_type=MyType)...
Can you think of anything?
There was a problem hiding this comment.
I believe that is the only way to get type hints for a function. Also, it's not very useful for generics also.
if I do something like this-def typed(input_type=T) , the type hints are input_type: Any
We can leave it as is right now, I added documentation for this decorator so it should be a little better.
haizaar
commented
Nov 29, 2023
Good day, Does it supersede essentially replace ? Will it work on Google Cloud Functions? |
Answering to myself:
from __future__ importannotationsfrompydanticimportBaseModelclassHelloRequest(BaseModel):
name: str@classmethoddeffrom_dict(cls, d: dict[str, Any]) ->HelloRequest:
returncls(**d)
defto_dict(self) ->dict[str, Any]:
returnself.model_dump()
@functions_framework.typeddefhello(hr: HelloRequest):
returnf"Hello, {hr.name}"Well done guys! |
HKWinterhalter
commented
Dec 2, 2023
@haizaar Thanks for trying it out and sharing an example! As you may have found, 'typed' is in additional feature and does not deprecate 'http'. |
red8888
commented
Jan 30, 2026
Please explain what this means. How is it an "additional feature"? Maybe I can rephrase, "If I want type hints do I just use @functions_framework.typed instead of @functions_framework.http and it will work the exact same?" Because its not working for me: Been years and this is still totally undocumented. |

Add a new signature in functions framework that will support strongly typed objects. This signature will take a strong type T as an input and can return a strong type T, built in types supported by flask or None as an output.
Sample declarations:
The new signature will only support types abiding by the below contract to convert a python object to and from json:
Here is sample python object: