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

Conversation

terwilliger42
Copy link

Fixes #302; calls appropriate array.tobytes / array.tostring depending on Python version.

@terwilliger42
Copy link
Author

Not sure why this fails Travis for Python 2.6, but don't think it has anything to do with my change.


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

@michcio1234
Copy link

Would be awesome if someone merged it. My logs are rather unreadable because of tons of deprecation warnings. :/

@terwilliger42
Copy link
Author

terwilliger42 commented Aug 25, 2017

@michcio1234 FYI: You can use Python's 'warnings' module to suppress these messages. Here's what we've done in the interim. This disables this specific warning only within the context manager.

import warnings

with warnings.catch_warnings():
    # Filter out Thriftpy deprecation warnings
    warnings.filterwarnings(action='ignore', message=r'tostring\(\) is deprecated. Use tobytes\(\) instead.', module='thriftpy.protocol.compact',
                            category=DeprecationWarning)
    <thrift code here>

@ethe
Copy link
Member

ethe commented Sep 26, 2018

Thriftpy was not supported any more, and it already be resolved in thriftpy2, thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants