

4·
1 year agoNice! It looks like the best solution out there.
Nice! It looks like the best solution out there.
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
The difference is that with Protocol
you can define which method presence you want to ensure. Like i said: custom vs. generic.
From what i understand, Protocol
is for custom interfaces that you define (this object must have do_x()
method), while ABCs are generic (this object is iterable).
Disclosure: i work at Infomaniak.
I don’t think Google was saying “come get your ethical email”, more like “get your free email”. Infomaniak is making money by selling services. The free tier is just there as a loss leader. Google was already selling ads. So i don’t think it compares.
BTW, Infomaniak is already 30 years old :-)