• 1 Post
  • 5 Comments
Joined 1 year ago
cake
Cake day: August 29th, 2023

help-circle


  • Python >= 3.10 version:

    def foo(return_more: bool) -> DataType | tuple[DataType, MoreDataType]: ...
    

    But i would definitely avoid to do that if possible. I would maybe do something like this instead:

    def foo(return_more: bool) -> tuple[DataType, MoreDataType | None]:
        ...
        if return_more:
            return data, more_data
       return data, None
    

    Or if data is a dict, just update it with more_data:

    def foo(return_more: bool) -> dict[str, Any]:
        ...
        if return_more:
            return data.update(more_data)
       return data