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

Fix a number of Deprecated/Invalid escape sequences #7925

Merged
merged 2 commits into from
Feb 2, 2017

Conversation

Carreau
Copy link
Contributor

@Carreau Carreau commented Jan 23, 2017

And turn python 3.6 DeprecationWarnings into error during tests.

Python 3.6 deprecate invalid escape sequences, as they are (most of the
time) mistakes from the author. This introduce extra \ when necessary,
or make strings raw.

See #7924

@@ -5,6 +5,7 @@
from __future__ import (absolute_import, division, print_function,
unicode_literals)


Copy link
Member

Choose a reason for hiding this comment

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

Unnecessary change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, autopep8 script doing more than asked.

@@ -1543,7 +1544,6 @@ def gs_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False):
else:
pstoeps(tmpfile)


Copy link
Member

Choose a reason for hiding this comment

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

Should not be changed.

@@ -184,7 +184,7 @@ def win32FontDirectory():
Return the user-specified font directory for Win32. This is
looked up from the registry key::

\\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Fonts
\\HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\\Fonts
Copy link
Member

Choose a reason for hiding this comment

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

The first one is supposed to be doubled, so it should be 4 when escaped, but maybe it'd be simpler to make it a raw string instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh.. ok, I did not remembered \\ was a thing on windows.

('\rightbrace', '}'),
('\leftbracket', '['),
('\rightbracket', ']'),
for alias, target in [('\\leftparen', '('),
Copy link
Member

Choose a reason for hiding this comment

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

The last ones are raw strings; better to do that for consistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure. Done.

@@ -1803,7 +1803,7 @@ def _pprint_styles(_styles):
(stylename : styleclass), return a formatted string listing all the
styles. Used to update the documentation.
"""
names, attrss, clss = [], [], []
ddnames, attrss, clss = [], [], []
Copy link
Member

Choose a reason for hiding this comment

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

Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hum.. vim, probably though I was typing in another window.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

though these 3 attributes are not use at all in the function...

@@ -111,7 +111,7 @@ def test_exceptions():
# the point of this test is to ensure that this raises.
with warnings.catch_warnings():
warnings.filterwarnings('ignore',
message='.*sharex\ argument\ to\ subplots',
message=r'.*sharex\ argument\ to\ subplots',
Copy link
Member

Choose a reason for hiding this comment

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

What is \ ? I don't think this escape even means anything in a regular expression.

@@ -30,7 +30,7 @@ def find_matplotlib_font(**kw):
from matplotlib.font_manager import FontProperties, findfont
warnings.filterwarnings(
'ignore',
('findfont: Font family \[u?\'Foo\'\] not found. Falling back to .'),
r'findfont: Font family \[u?\'Foo\'\] not found. Falling back to .',
Copy link
Member

Choose a reason for hiding this comment

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

I think the internal quotes no longer need to be escaped here now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Use double quotes instead?

Copy link
Member

Choose a reason for hiding this comment

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

Err, actually, I don't know what I was thinking here, but the internal quotes still need to be escaped unless using double quotes as @anntzer suggested.

Copy link
Contributor

Choose a reason for hiding this comment

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

@Carreau As mentioned just above, can you switch to double quotes and remove the backslashes in the inner single quotes here?

tests.py Outdated

# Python 3.6 deprecate invalid character-pairs \A, \* ... in non raw-strings
# and other things. Let's not re-introduce them
warnings.filterwarnings('error', category=DeprecationWarning)
Copy link
Member

Choose a reason for hiding this comment

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

Though I prefer not to introduce any deprecations either, this seems a bit broad for this PR.

@codecov-io
Copy link

codecov-io commented Jan 23, 2017

Current coverage is 62.18% (diff: 100%)

Merging #7925 into master will not change coverage

@@             master      #7925   diff @@
==========================================
  Files           175        175          
  Lines         56125      56125          
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
  Hits          34901      34901          
  Misses        21224      21224          
  Partials          0          0          

Powered by Codecov. Last update c93142f...582d771

tests.py Outdated

# The warnings need to be before any of matplotlib imports, but after
# setuptools (if present) which has syntax error with the warnings enabled.
# Filtering by module does not work as this will be raise by Python itself.
Copy link
Contributor

Choose a reason for hiding this comment

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

typo: raised

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@Carreau Carreau force-pushed the deprecations branch 2 times, most recently from c24f837 to ff6afaf Compare January 25, 2017 00:21
@Carreau
Copy link
Contributor Author

Carreau commented Jan 25, 2017

Rebased to remove conflicts.

@Carreau
Copy link
Contributor Author

Carreau commented Jan 27, 2017

Rebased again and use backtick

Copy link
Member

@NelleV NelleV left a comment

Choose a reason for hiding this comment

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

LGTM 👍
Thanks @Carreau

@NelleV NelleV changed the title Fix a number of Deprecated/Invalid escape sequences [MRG+1] Fix a number of Deprecated/Invalid escape sequences Jan 29, 2017
'default',
'.*inspect.getargspec\(\) is deprecated.*',
category=DeprecationWarning)

Copy link
Member

Choose a reason for hiding this comment

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

This only gets executed when running tests.py, and I think most tests have been migrated to pytest now. Is there a way to make pytest execute these filterwarnings calls?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. It's supposed to get folded into Pytest itself at some point.

@@ -394,7 +394,7 @@ def set_hatch(self, hatch):
*hatch* can be one of::

/ - diagonal hatching
\ - back diagonal
\\ - back diagonal
Copy link
Member

Choose a reason for hiding this comment

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

This one worries me as it is something I would expect to be read either on the web or in the terminal. Probably better to make this a r''' string?

Copy link
Member

Choose a reason for hiding this comment

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

and I may be wrong here, escaping always ties me in knots....

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. I can't rebuild matplotlib today apparently, so can't test the html versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I managed to build the docs, and the \ in Accept below needed to be escaped more.
That should be fixed.

And turn python 3.6 DeprecationWarnings into error during tests.

Python 3.6 deprecate invalid escape sequences, as they are (most of the
time) mistakes from the author. This introduce extra `\` when necessary,
or make strings `raw`.

See matplotlib#7924
@@ -415,7 +415,7 @@ def set_hatch(self, hatch):
can only be specified for the collection as a whole, not separately
for each member.

ACCEPTS: [ '/' | '\\\\' | '|' | '-' | '+' | 'x' | 'o' | 'O' | '.' | '*' ]
ACCEPTS: [ '/' | '\\' | '|' | '-' | '+' | 'x' | 'o' | 'O' | '.' | '*' ]
Copy link
Member

Choose a reason for hiding this comment

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

It appears that this line is under 79 characters and this file now passes PEP8, so it needs to be removed from lib/matplotlib/tests/test_coding_standards.py because the build is failing.

Copy link
Member

Choose a reason for hiding this comment

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

Also, since you're going to have to push an update, I cancelled the OSX build which has been waiting for a while because we've got a long backlog.

Copy link
Contributor

@anntzer anntzer left a comment

Choose a reason for hiding this comment

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

Minor nitpick.

@@ -30,7 +30,7 @@ def find_matplotlib_font(**kw):
from matplotlib.font_manager import FontProperties, findfont
warnings.filterwarnings(
'ignore',
('findfont: Font family \[u?\'Foo\'\] not found. Falling back to .'),
r'findfont: Font family \[u?\'Foo\'\] not found. Falling back to .',
Copy link
Contributor

Choose a reason for hiding this comment

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

@Carreau As mentioned just above, can you switch to double quotes and remove the backslashes in the inner single quotes here?

@NelleV
Copy link
Member

NelleV commented Feb 2, 2017

Thanks @Carreau
4 core dev validating your PR: I believe this is a new record :)

@NelleV NelleV merged commit 924d913 into matplotlib:master Feb 2, 2017
@Carreau
Copy link
Contributor Author

Carreau commented Feb 2, 2017 via email

@QuLogic QuLogic changed the title [MRG+1] Fix a number of Deprecated/Invalid escape sequences Fix a number of Deprecated/Invalid escape sequences Feb 2, 2017
@QuLogic QuLogic added this to the 2.1 (next point release) milestone Feb 2, 2017
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

7 participants