![](/static/61a827a1/assets/icons/icon-96x96.png)
![](https://programming.dev/pictrs/image/1d99f7cb-50e7-4994-94c4-fd23f30209b7.png)
4·
1 year agoPython >= 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
Nice! It looks like the best solution out there.