bobjacobsen / python-openlcb

MIT License
2 stars 1 forks source link

Ensure Python-like range is used (exclusive end) #5

Closed Poikilos closed 4 months ago

Poikilos commented 5 months ago

This may be incorrect in snip.py:

    def returnStrings(self):
        # copy out until the 6th zero byte
        stop = self.findString(6)
        retval = [0]*stop
        if (stop == 0):
            return retval
        for i in range(0, stop-1):
            retval[i] = self.data[i]
        return retval

Maybe check through other range calls as well, ensuring range being exclusive (not iterating the last value) in Python is considered.

Poikilos commented 5 months ago

Did you see what I'm saying here? If you want to do everything before stop, you only need to use stop not stop-1, because the range function already excludes stop. I don't know the goal here well enough to be sure, but I'd expect the code to be like:

for i in range(0, stop):

Or (same effect):

for i in range(stop):
bobjacobsen commented 5 months ago

Thanks for checking on this. I think it's correct, as the goal is to copy through the end of the string. self.findString(6) finds the index of string 6 (0-based), which is one past the index of the last zero which terminates the previous string.

The testReturnStrings test in tests/test_snip.py covers this and seems to indicate it's doing the right thing.