Replacing deprecated alias tostring with tobytes
Tostring is now (python 3.9) a deprecated alias for tobytes. Since peframe requires python 3.6 (according to README) and tobytes has been introduced in python 3.2, there is no loss from removing the use of the alias in this project while upgrading python compatibility to 3.9 eventually.
Disclosure: I haven't fully tested it, you may want to build and run in a python 3.9 docker before merging, or set-up some automated tests using github actions. Can help on that if you want.
I had the same issue and was about to issue a pull request. It might be good to make it more universal by first checking if you have the tostring attribute, and if not, then calling tobytes:
if (hasattr('delta', 'tostring')):
return delta.tostring()[:-key_len]
return delta.tobytes()[:-key_len]
thanks @gleeda I'll look better
Just tested it as well and it works perfectly with python3.9, thanks for the fix! :)
Checking for tostring, as @gleeda suggested (no offense, nice suggestion imo), would be worth it if it was expected to be able to run for python version below 3.2. I'm not sure there wouldn't be any other compatibility issue, but that would help to avoid breaking some monkey patching in other projects or whatnot. Do you want the PR to be edited with that on my side @guelfoweb ?
Confirmed that it fixes AttributeError: 'array.array' object has no attribute 'tostring' in peframe/modules/features.py on python 3.10 as well.
I can confirm this fixes the AttributeError for Python 3.11.3. Also compatibility should be no problem since the rename to tobyte was in place since Python v3.2 and peframe README specifies python >= 3.6.6. See Python array doc. According to release notes, this will break starting Python 3.9 (removal of deprecated alias).