Skip to content
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

backend_qt5.py Don't use six.u #3357

Merged
merged 1 commit into from Aug 10, 2014
Merged

Conversation

jenshnielsen
Copy link
Member

This code already does from __future__ import unicode_literal.
Thus '+' will be a unicode string even in python 2 and there is no
need for converting it into a unicode string. In fact this results in
a TypeError because six.u assumes the input string to be ASCII only.
See http://pythonhosted.org/six/#six.u

This fixes test failures with rc3 on python 2

ERROR: matplotlib.tests.test_backend_qt4.test_shift
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/usr/local/lib/python2.7/site-packages/matplotlib/testing/decorators.py", line 110, in wrapped_function
    func(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/matplotlib/testing/decorators.py", line 51, in failer
    result = f(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/matplotlib/tests/test_backend_qt4.py", line 80, in test_shift
    'A')
  File "/usr/local/lib/python2.7/site-packages/matplotlib/tests/test_backend_qt4.py", line 72, in assert_correct_key
    qt_canvas.keyPressEvent(event)
  File "/usr/local/lib/python2.7/site-packages/matplotlib/backends/backend_qt5.py", line 312, in keyPressEvent
    key = self._get_key(event)
  File "/usr/local/lib/python2.7/site-packages/matplotlib/backends/backend_qt5.py", line 384, in _get_key
    return six.u('+').join(mods + [key])
  File "/usr/local/lib/python2.7/site-packages/six.py", line 589, in u
    return unicode(s.replace(r'\\', r'\\\\'), "unicode_escape")
TypeError: decoding Unicode is not supported

An alternative solution would be to get rid of the use of from __future__ import unicode_literal but this seems less intrusive at this late stage.

@cgohlke you changed this code the last time to ensure python 3.2 compatibility. Can you please check that you are ok with this change.

This code already does from __future__ import unicode_literal.
Thus '+' will be a unicode string even in python 2 and there is no
need for converting it into a unicode string. Infact this results in
a TypeError because six.u assumes the input string to be ASCII only.
See http://pythonhosted.org/six/#six.u
@jenshnielsen jenshnielsen added this to the v1.4.0 milestone Aug 10, 2014
@jenshnielsen
Copy link
Member Author

Simple example of reproducing the error outside matplotlib is:

from __future__ import unicode_literals
import six
six.u('+')

Getting rid of either the from future or the six.u removes the error and gives the expected result

jenshnielsen added a commit to jenshnielsen/matplotlib that referenced this pull request Aug 10, 2014
This is an alternative to matplotlib#3357. In short using unicode_lieterals with
six.u does not work and results in TypeErrors in python 2. This fixes
is by not using unicode_literals rather than getting rid of six.u
tacaswell added a commit that referenced this pull request Aug 10, 2014
@tacaswell tacaswell merged commit 5cefa83 into matplotlib:v1.4.x Aug 10, 2014
@jenshnielsen jenshnielsen deleted the qt4_unicode branch August 28, 2014 11:59
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.

None yet

3 participants