4 ms·
Honestly, for this specific case, I prefer one_or_none() to return an iterable with zero or one items, and then just doing: for foo in one_or_none(): do_
by dragonwriter 4y ago
Honestly, for this specific case, I prefer one_or_none() to return an iterable with zero or one items, and then just doing:
for foo in one_or_none():
do_stuff(foo)
If you don't control one_or_none, but it returns an Optional, you can wrap it with something like:
def optional_to_tuple(opt_val: Optional[T]) -> Tuple[]|Tuple[T]:
return (opt_val,) if opt_val is not None else ()