Skip to content
Advertisement

type hints in a Python Google Cloud Function?

In a Python Google Cloud Function with a lot of sub-functions in the “main.py”, I added type hints (= return value annotation as part of function annotation) in pep8 style like this:

JavaScript

Union is taken from here, it is needed if there is more than one type hint.

The function cannot get deployed, there is no log about what is wrong, just an orange error log entry that has the same text as the start item above it.

JavaScript

And when I replace the -> with : # -> so that all type strings are commented out, it works, therefore, the type hints seem to disturb the Google Cloud Function.

Are type hints supported at all? How can I get type hints to work in a Google Cloud Function?

Advertisement

Answer

From the comments follows that the error was in another code snippet that went as follows:

JavaScript

That code was corrected to include Tuple (Union also worked but is not the default for many types in one type hint):

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement