How to specify multiple return types using type-hints

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 … Read more

How do I type hint a method with the type of the enclosing class?

TL;DR: As of today (2019), in Python 3.7+ you must turn this feature on using a “future” statement, from __future__ import annotations. (The behaviour enabled by from __future__ import annotations might become the default in future versions of Python, and was going to be made the default in Python 3.10. However, the change in 3.10 … Read more