Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Replace use of str() with six.text_type() for Py2&3 compatibility [backport to color_overhaul] #4278

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
Mar 26, 2015
Merged

Conversation

mfitzp
Copy link
Member

@mfitzp mfitzp commented Mar 25, 2015

Version 1 of the PyQt APIs return QVariant types that must be
cast to Python strings before use. To catch this get_window_title()
in backend_qt5.py wrapped the call to self.window.windowTitle()
with str(). This fails on Python 2 if the window title contains
unicode characters.

This is replaced with six.text_type for Py2&3 compatibility with
unicode types.

A number of other locations in the same file were also using str()
for potentially unicode data. These are also fixed in this commit.

Fixes #4275.

Version 1 of the PyQt APIs return QVariant types that must be
cast to Python strings before use. To catch this `get_window_title()`
in `backend_qt5.py` wrapped the call to `self.window.windowTitle()`
with `str()`. This fails on Python 2 if the window title contains
unicode characters.

This is replaced with `six.text_type` for Py2&3 compatibility with
unicode types.

A number of other locations in the same file were also using `str()`
for potentially unicode data. These are also fixed in this commit.

Fixes #4275.
@mfitzp
Copy link
Member Author

mfitzp commented Mar 25, 2015

Line 140 qApp = QtWidgets.QApplication([six.text_type(" ")]) seems a bit redundant, but str() was around the " " so I added the conversion to unicode to keep things consistent through the file.

@mdboom
Copy link
Member

mdboom commented Mar 25, 2015

👍

@tacaswell tacaswell added this to the next point release milestone Mar 25, 2015
@tacaswell tacaswell changed the title Replace use of str() with six.text_type() for Py2&3 compatibility Replace use of str() with six.text_type() for Py2&3 compatibility [backport to color_overhaul] Mar 25, 2015
@tacaswell
Copy link
Member

This should be back-ported to color_overhaul which is turning into a bugfix branch

tacaswell added a commit that referenced this pull request Mar 26, 2015
MNT : Replace use of str() with six.text_type() for Py2&3 compatibility
@tacaswell tacaswell merged commit 6962aac into matplotlib:master Mar 26, 2015
tacaswell added a commit that referenced this pull request Mar 26, 2015
MNT : Replace use of str() with six.text_type() for Py2&3 compatibility
@tacaswell
Copy link
Member

backported as 016f568

@mfitzp mfitzp deleted the pyqt4-api1-py3-compat branch March 26, 2015 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UnicodeEncodeError when trying to save a figure
3 participants