Skip to content

Fix deprecated calls for Python 3.9 #53

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

Merged
merged 1 commit into from
Feb 15, 2020

Conversation

lubomir
Copy link
Contributor

@lubomir lubomir commented Jan 8, 2020

The array methods fromstring/tostring have been deprecated since Python 3.2. Python 3.9 removes them completely.

This was discovered when trying to build gitdb package for Fedora 33.
https://bugzilla.redhat.com/show_bug.cgi?id=1788660

gitdb/pack.py Outdated
@@ -410,7 +419,7 @@ def offsets(self):
if self._version == 2:
# read stream to array, convert to tuple
a = array.array('I') # 4 byte unsigned int, long are 8 byte on 64 bit it appears
a.fromstring(buffer(self._cursor.map(), self._pack_offset, self._pack_64_offset - self._pack_offset))
_frombytes(a, buffer(self._cursor.map(), self._pack_offset, self._pack_64_offset - self._pack_offset))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be simpler:

a = array.array('I', buffer(self._cursor.map(), self._pack_offset, self._pack_64_offset - self._pack_offset))

Or maybe even use memoryview(self._cursor.map())[self._pack_offset : self._pack_64_offset] instead of buffer(...) (not tested).

@Byron Byron self-assigned this Feb 8, 2020
Copy link
Member

@Byron Byron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for your contribution, it's very much appreciated.

I have left a few comments and will merge as soon as Python 2 compatibility is removed.

The array methods fromstring/tostring have been deprecated since Python
3.2. Python 3.9 removes them completely.

This was discovered when trying to build gitdb package for Fedora 33.
https://bugzilla.redhat.com/show_bug.cgi?id=1788660
@lubomir
Copy link
Contributor Author

lubomir commented Feb 13, 2020

I updated the code to drop Python 2 compatibility.

@Harmon758 Harmon758 linked an issue Feb 13, 2020 that may be closed by this pull request
@Byron Byron merged commit f891e24 into gitpython-developers:master Feb 15, 2020
@Byron
Copy link
Member

Byron commented Feb 15, 2020

Thanks a lot for your contribution! I will cut release v3.0 soon!

@lubomir lubomir deleted the py39-deprecations branch February 17, 2020 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

array.tostring and fromstring were removed in Python 3.9
3 participants