Skip to content
This repository has been archived by the owner on Dec 10, 2018. It is now read-only.

Fixes #302 -- deprecation warnings when array.tostring() is called on Python 3.3+ #303

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion thriftpy/protocol/compact.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ def write_varint(trans, n):
else:
out.append((n & 0xff) | 0x80)
n = n >> 7
data = array.array('B', out).tostring()

# 3.2+ uses tobytes(). Thriftpy doesn't support Python 3 pre-3.3
a = array.array('B', out)
data = a.tobytes() if PY3 else a.tostring()

Choose a reason for hiding this comment

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

I'd recommend doing the check once at the top of the file instead of once per call:

if PY3:
  tobytes = array.tobytes
else:
  tobytes = array.tostring

...
  data = tobytes(a)
...

That said, I don't have merge writes - so take suggestions with a grain of salt =u)

Copy link
Author

Choose a reason for hiding this comment

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

That's a good idea, thanks @wvonnegut. If one of the maintainers would prefer it that way, I'd be happy to change it, just let me know.


if PY3:
trans.write(data)
Expand Down