ih = IntelHex({0:0, 1:1, 2:2})
# The bug
print(ih[0:0].tobinarray()) # array('B', [0, 1, 2])
# Correct for other indices
print(ih[1:1].tobinarray()) # array('B', [])
# stdlib __getitem__ for reference
li = [1, 2, 3]
print(li[0:0]) # []
Looking at the source for _getitem_() this behavior happens because the endaddr 0 evaluates the same as None.
The fix should simply be:
# Current
start = addr.start or addresses[0]
stop = addr.stop or (addresses[-1]+1)
# Fixed
start = addr.start if addr.start is not None else addresses[0]
stop = addr.stop if addr.stop is not None else (addresses[-1]+1)
Consider the following.
Looking at the source for
_getitem_()
this behavior happens because the endaddr 0 evaluates the same as None.The fix should simply be: