vpelletier / python-libusb1

Python ctype-based wrapper around libusb1
GNU Lesser General Public License v2.1
168 stars 65 forks source link

getSupportedLanguageList does not work on Python 3.5 #18

Closed l0ud closed 7 years ago

l0ud commented 7 years ago

Hi. I just encountered a small issue in your library. In getSupportedLanguageList, this line gives error about incompatible types (int and float): for offset in xrange(1, length / 2):

Using binary shift instead, should solve this problem: for offset in xrange(1, length >> 1):

vpelletier commented 7 years ago

Hello. Could you paste the traceback (only with the lines in python-libusb1, which should contain the error) ? If the error is TypeError: 'float' object cannot be interpreted as an integer I can guess where it comes from (int / int becomes float, and range does not like floats) and hence how to fix it (int // int stays int). But the error you report seems to be a different one, so I'm not sure if that is the right bug.

l0ud commented 7 years ago

It's exactly the error you mentioned. I wrote that from memory so it could be misleading, sorry about that.

To be honest, I didn't know about floordiv operator in Python! It's much more readable than the byte shift, so I can only agree to fix it that way. Thanks!

vpelletier commented 7 years ago

This should be fixed as of 0428e7e6972b3681219fcb3c8e41219915f632de .

Thanks to this bug I also realised this method accidentally returned ctype objects, which was not intended. I think they should behave like regular integers, so I'm not too worried about breaking compatibility (...and I must admit I did not actually expect this method to be really used, as I think multi-language devices are rare - but I may be mistaken on the actual uses of this part of the USB specs).

vpelletier commented 7 years ago

Thanks for confirming the fix. Released on pypi as 1.5.1 .