Use Union to allow a variable to be one of given types or values.

Python 3.10

TYPE | TYPE | TYPE

# e.g.
float | int | str

Python 3.8

Union[TYPE, TYPE, ...]

# e.g.
Union[float, int, str]

Example

Here we allow return value as integer or string.

def bar(bazz: bool) -> int | str:
    if bazz:
        return 'Yes'

    return 12