There are some related questions about unpacking single-value tuples, but I'd like to know if there is a preferred method in terms of readability for sharing and maintaining code. I'm finding these to be a source of confusion or misreading among colleagues when they involve a long function chain such as an ORM query.
Is there some convention for this similar to the pep8 guidelines? If not, which is the clearest, most readable way to do it?
Below are the ways I've tried, and my thoughts on them.
Two common methods that are neat but easy to miss:
value, = long().chained().expression().that().returns().tuple()
value = long().chained().expression().that().returns().tuple()[0]
A function would be explicit, but non-standard:
value = unpack_tuple(long().chained().expression().that().returns().tuple())
Maybe always commenting would be the most clear?
# unpack single-value tuple
value, = long().chained().expression().that().returns().tuple()