How to specify multiple return types using type-hints
I have a function in python that can either return a bool or a list . Is there a way to specify the return types using type hints. For example, Is this the correct way to do it? def foo(id) -> list or bool: ... Bhargav Rao From the documentation class typing.Union Union type; Union[X, Y] means either X or Y. Hence the proper way to represent more than one return data type is from typing import Union def foo(client_id: str) -> Union[list,bool] But do note that typing is not enforced. Python continues to remain a dynamically-typed language. The annotation syntax has been developed to help during