I find this surprising. Anyone doing len(chunk) probably wants the length of its data member, not the fact that it's a two-tuple. I propose implementing Chunk like so:
class Chunk(namedtuple("Chunk", ["address", "data"])): # Or _Chunk, depending on outcome of #35
def __len___(self):
return len(self.data)
While this would technically change the API, I argue that it is extremely unlikely to break anything; anyone doing len(chunk) almost certainly means len(chunk.data).
I find this surprising. Anyone doing
len(chunk)
probably wants the length of itsdata
member, not the fact that it's a two-tuple. I propose implementingChunk
like so:While this would technically change the API, I argue that it is extremely unlikely to break anything; anyone doing
len(chunk)
almost certainly meanslen(chunk.data)
.