Skip to content

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

Open
terwilliger42 wants to merge 1 commit into
Thriftpy:developfrom
terwilliger42:issue302
Open

Fixes #302 -- deprecation warnings when array.tostring() is called on Python 3.3+#303
terwilliger42 wants to merge 1 commit into
Thriftpy:developfrom
terwilliger42:issue302

Conversation

@terwilliger42

Copy link
Copy Markdown

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

@terwilliger42

Copy link
Copy Markdown
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()

Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown

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

@terwilliger42

terwilliger42 commented Aug 25, 2017

Copy link
Copy Markdown
Author

@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

ethe commented Sep 26, 2018

Copy link
Copy Markdown
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants