X Tutup
Skip to content

FIX: always decode bytes as utf-8 in AFM headers#8021

Merged
tacaswell merged 7 commits intomatplotlib:v2.0.xfrom
tacaswell:fix_nonascii_afm
Mar 20, 2017
Merged

FIX: always decode bytes as utf-8 in AFM headers#8021
tacaswell merged 7 commits intomatplotlib:v2.0.xfrom
tacaswell:fix_nonascii_afm

Conversation

@tacaswell
Copy link
Copy Markdown
Member

closes #3517

@tacaswell tacaswell added this to the 2.0.1 (next bug fix release) milestone Feb 4, 2017
@tacaswell tacaswell added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Feb 5, 2017
@tacaswell
Copy link
Copy Markdown
Member Author

This is a 'can-not-import-bug', but has been here a long time, the critical flag is to make sure we talk about it.

To test this I think we need to find a debian font which has a non-ascii font family name.

@NelleV
Copy link
Copy Markdown
Member

NelleV commented Feb 16, 2017

I think just checking that afm._to_str works on non ascii path is enough.

@NelleV
Copy link
Copy Markdown
Member

NelleV commented Mar 12, 2017

Can I still review this PR? (cause it looks very fine to me 👍 for merging!)

@@ -0,0 +1,13 @@
import matplotlib.afm as afm
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This file is missing our standard __future__ imports.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

But the future import is useless for this file.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

actually, it might be harmful due to the 'unicode_literals'...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In the future, if anyone adds new tests here, then they won't have to worry about adding in these imports if necessary. Easy consistency is important for tests.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is the kind of practices that break static checkers such as pyflakes with very little benefit considering a forgotten import should break the test.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I've never seen a static checker complain about __future__ imports; how would they even know if you used, e.g., division with types that were integers?

This is about consistent Python 2/3 behaviour, not some random import.

unicode_literals)

import matplotlib.afm as afm
import six
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It appears that other changes mean this can be removed?


def test_nonascii_str():
# This tests that we also decode bytes as utf-8 properly.
# Else, font files with non ascii caracters fail to load.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

caracters -> characters

@NelleV NelleV changed the title FIX: always decode bytes as utf-8 in AFM headers [MRG+1] FIX: always decode bytes as utf-8 in AFM headers Mar 19, 2017
Copy link
Copy Markdown
Member

@dstansby dstansby left a comment

Choose a reason for hiding this comment

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

👍 since @NelleV made some changes I will leave this for @tacaswell to merge if he's happy with them

@dstansby dstansby changed the title [MRG+1] FIX: always decode bytes as utf-8 in AFM headers [MRG+2] FIX: always decode bytes as utf-8 in AFM headers Mar 19, 2017
@@ -0,0 +1,14 @@
from __future__ import (absolute_import, division, print_function,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Needs an encoding comment; this fails on Python 2.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fixed!

@tacaswell tacaswell dismissed QuLogic’s stale review March 20, 2017 19:09

It now imports on py2

@tacaswell tacaswell merged commit 47eb989 into matplotlib:v2.0.x Mar 20, 2017
@tacaswell tacaswell deleted the fix_nonascii_afm branch March 20, 2017 19:09
@QuLogic QuLogic changed the title [MRG+2] FIX: always decode bytes as utf-8 in AFM headers FIX: always decode bytes as utf-8 in AFM headers Mar 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

X Tutup