Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to fix Python 3.9 compatibility issue with array.array tostring/fromstring methods #1054

Merged
merged 3 commits into from Apr 19, 2021

Conversation

martingalloar
Copy link
Contributor

@martingalloar martingalloar commented Apr 14, 2021

Python 3.9 removed the array.array tostring and fromstring methods (see https://docs.python.org/3/whatsnew/3.9.html#removed).
Note that the tostring and fromstring methods were already deprecated since Python 3.2, but aliases to the new tobytes and frombytes were provided (see https://docs.python.org/3/library/array.html#array.array.tobytes).

This PR:

  • Adds helper function to use tostring and fromstring in Python <3.2 versions and tobytes and frombytes in Python>=3.2.
  • Replaces uses of tostring and fromstring with the new helper function.

This should help close #1032. Based on #992, should close also duplicated #946 with the exception of the remaining change for isAlive.

…ng method

Python 3.2 removed the `array.array` `tostring` method (see https://docs.python.org/3/whatsnew/3.9.html#removed).
Note that the `tostring` method was already deprecated since Python 3.2, but an alias to the new `tobytes` was provided (see https://docs.python.org/3/library/array.html#array.array.tobytes).

This PR:
- Adds helper function to use `tostring` in Python <3.2 versions and `tobytes` in Python>=3.2.
- Replaces uses of `tostring` with the new helper function.
@martingalloar martingalloar self-assigned this Apr 14, 2021
@martingalloar martingalloar added the enhancement Implemented features can be improved or revised label Apr 14, 2021
@martingalloar
Copy link
Contributor Author

This is using a slightly different approach from #946 to try to avoid code duplication and runtime checks, and closer to (and based on) #992.

@martingalloar martingalloar changed the title Attempt to fix Python 3.9 compatibility issue with array.array tostring method Attempt to fix Python 3.9 compatibility issue with array.array tostring/fromstring methods Apr 14, 2021
@martingalloar martingalloar merged commit 976d39a into master Apr 19, 2021
martingalloar added a commit that referenced this pull request Apr 19, 2021
While reviewing #1054, we found that ping examples where using old strings instead of bytes as payloads, and this is breaking in Python >2.
martingalloar added a commit that referenced this pull request Apr 19, 2021
Small change for properly use the array_tobytes function.
martingalloar added a commit that referenced this pull request Apr 19, 2021
After working on #1054 and moving to use frombytes/tobytes we found a Python 3 compat issue with bytes/string in PacketBuffer __validate_index. This fixes a wrong use of a string instead of bytes.
martingalloar added a commit that referenced this pull request Apr 19, 2021
After working on #1054 and moving to use frombytes/tobytes we found a Python 3 compat issue with bytes/string in PacketBuffer __validate_index. This fixes a wrong use of a string instead of bytes.
@martingalloar martingalloar deleted the python3.9-array-tostring branch April 19, 2021 19:15
martingalloar added a commit that referenced this pull request Apr 19, 2021
While reviewing #1054, we found that ping examples where using old strings instead of bytes as payloads, and this is breaking in Python >2.
martingalloar added a commit that referenced this pull request Apr 20, 2021
As mentioned in #946 and #1054, one unit test of the ImpactPacket suite was using the isAlive method which was already depracated in Python 3.8, and removed in Python 3.9. This changes its use to is_alive, introduced back in Python 2.7!
martingalloar added a commit that referenced this pull request Apr 21, 2021
…1061)

As mentioned in #946 and #1054, one unit test of the `ImpactPacket` suite was using the `isAlive` method which was already deprecated in Python 3.8, and removed in Python 3.9. This changes its use to `is_alive`, introduced back in Python 2.6!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Implemented features can be improved or revised
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Python 3.9 - 'array.array' object has no attribute 'tostring'
2 participants