Search code examples
pythonfunctionpep8docstring

PEP8 best docstring practice when function has multiple different return


I have the following function:

def eg_fun(eg:int):
    """example function
    """
   
    if eg > 2:
        return 2, 4
    else:
        return 'no', None

In the function definition how I can put different returning Tuple?

If I would have a single return type I writing: def eg_fun(eg:int) -> Tuple[int, int]:

But in this case I have two different return type, the first one is Tuple[int, int] while the second one is Tuple[str, None]


Solution

  • If you are running python 3.10 -> Tuple[int, int] | Tuple [str, None] should work