peframe icon indicating copy to clipboard operation
peframe copied to clipboard

Replacing deprecated alias tostring with tobytes

Open guzmud opened this issue 4 years ago • 6 comments

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.

guzmud avatar Sep 06 '21 13:09 guzmud

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]

gleeda avatar Nov 02 '21 15:11 gleeda

thanks @gleeda I'll look better

guelfoweb avatar Nov 04 '21 21:11 guelfoweb

Just tested it as well and it works perfectly with python3.9, thanks for the fix! :)

fr0gger avatar Nov 15 '21 08:11 fr0gger

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 ?

guzmud avatar Jan 17 '22 14:01 guzmud

Confirmed that it fixes AttributeError: 'array.array' object has no attribute 'tostring' in peframe/modules/features.py on python 3.10 as well.

twpZero avatar May 10 '22 09:05 twpZero

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).

fabian-z avatar Jun 19 '23 20:06 fabian-z