Skip to content

Commit 0da46b4

Browse files
committed
Fix a number of Deprecated/Invalid escape sequences
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
1 parent f41ef96 commit 0da46b4

File tree

16 files changed

+66
-44
lines changed

16 files changed

+66
-44
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6713,7 +6713,7 @@ def csd(self, x, y, NFFT=None, Fs=None, Fc=None, detrend=None,
67136713
Notes
67146714
-----
67156715
For plotting, the power is plotted as
6716-
:math:`10\log_{10}(P_{xy})` for decibels, though `P_{xy}` itself
6716+
:math:`10\\log_{10}(P_{xy})` for decibels, though `P_{xy}` itself
67176717
is returned.
67186718
67196719
References

lib/matplotlib/backends/backend_ps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1568,7 +1568,7 @@ def xpdf_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False):
15681568
with io.open(outfile, 'rb') as fh:
15691569
if exit_status:
15701570
raise RuntimeError('ps2pdf was not able to process your \
1571-
image.\n\Here is the report generated by ghostscript:\n\n' + fh.read())
1571+
image.\nHere is the report generated by ghostscript:\n\n' + fh.read())
15721572
else:
15731573
verbose.report(fh.read(), 'debug')
15741574
os.remove(outfile)

lib/matplotlib/cbook/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ def disconnect(self, cid):
349349
return
350350

351351
def process(self, s, *args, **kwargs):
352-
"""
352+
r"""
353353
process signal *s*. All of the functions registered to receive
354354
callbacks on *s* will be called with *\*args* and *\*\*kwargs*
355355
"""
@@ -939,7 +939,7 @@ def wrap(prefix, text, cols):
939939
# A regular expression used to determine the amount of space to
940940
# remove. It looks for the first sequence of spaces immediately
941941
# following the first newline, or at the beginning of the string.
942-
_find_dedent_regex = re.compile("(?:(?:\n\r?)|^)( *)\S")
942+
_find_dedent_regex = re.compile(r"(?:(?:\n\r?)|^)( *)\S")
943943
# A cache to hold the regexs that actually remove the indent.
944944
_dedent_regex = {}
945945

@@ -1717,7 +1717,7 @@ def boxplot_stats(X, whis=1.5, bootstrap=None, labels=None,
17171717
17181718
.. math::
17191719
1720-
\mathrm{med} \pm 1.57 \\times \\frac{\mathrm{iqr}}{\sqrt{N}}
1720+
\\mathrm{med} \\pm 1.57 \\times \\frac{\\mathrm{iqr}}{\\sqrt{N}}
17211721
17221722
General approach from:
17231723
McGill, R., Tukey, J.W., and Larsen, W.A. (1978) "Variations of
@@ -2704,7 +2704,7 @@ def is_bounded_0_1(self):
27042704
def _get_key_params(self):
27052705
str_func = self._str_func
27062706
# Checking if it comes with parameters
2707-
regex = '\{(.*?)\}'
2707+
regex = r'\{(.*?)\}'
27082708
params = re.findall(regex, str_func)
27092709

27102710
for i, param in enumerate(params):

lib/matplotlib/collections.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ def set_hatch(self, hatch):
394394
*hatch* can be one of::
395395
396396
/ - diagonal hatching
397-
\ - back diagonal
397+
\\ - back diagonal
398398
| - vertical
399399
- - horizontal
400400
+ - crossed

lib/matplotlib/colors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ def to_hex(c, keep_alpha=False):
259259
### Backwards-compatible color-conversion API
260260

261261
cnames = CSS4_COLORS
262-
hexColorPattern = re.compile("\A#[a-fA-F0-9]{6}\Z")
262+
hexColorPattern = re.compile(r"\A#[a-fA-F0-9]{6}\Z")
263263

264264

265265
def rgb2hex(c):

lib/matplotlib/dviread.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ def _height_depth_of(self, char):
587587

588588
class Vf(Dvi):
589589
"""
590-
A virtual font (\*.vf file) containing subroutines for dvi files.
590+
A virtual font (\\*.vf file) containing subroutines for dvi files.
591591
592592
Usage::
593593
@@ -899,7 +899,7 @@ def _register(self, words):
899899

900900
class Encoding(object):
901901
"""
902-
Parses a \*.enc file referenced from a psfonts.map style file.
902+
Parses a \\*.enc file referenced from a psfonts.map style file.
903903
The format this class understands is a very limited subset of
904904
PostScript.
905905

lib/matplotlib/font_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def win32FontDirectory():
184184
Return the user-specified font directory for Win32. This is
185185
looked up from the registry key::
186186
187-
\\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Fonts
187+
\\\\HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\\Fonts
188188
189189
If the key is not found, $WINDIR/Fonts will be returned.
190190
"""

lib/matplotlib/mathtext.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def get_unicode_index(symbol, math=True):
6868
"""get_unicode_index(symbol, [bool]) -> integer
6969
7070
Return the integer index (from the Unicode table) of symbol. *symbol*
71-
can be a single unicode character, a TeX command (i.e. r'\pi'), or a
71+
can be a single unicode character, a TeX command (i.e. r'\\pi'), or a
7272
Type1 symbol name (i.e. 'phi').
7373
If math is False, the current symbol should be treated as a non-math symbol.
7474
"""
@@ -430,7 +430,7 @@ def get_kern(self, font1, fontclass1, sym1, fontsize1,
430430
431431
*fontclassX*: TODO
432432
433-
*symX*: a symbol in raw TeX form. e.g., '1', 'x' or '\sigma'
433+
*symX*: a symbol in raw TeX form. e.g., '1', 'x' or '\\sigma'
434434
435435
*fontsizeX*: the fontsize in points
436436
@@ -446,7 +446,7 @@ def get_metrics(self, font, font_class, sym, fontsize, dpi, math=True):
446446
447447
*font_class*: TODO
448448
449-
*sym*: a symbol in raw TeX form. e.g., '1', 'x' or '\sigma'
449+
*sym*: a symbol in raw TeX form. e.g., '1', 'x' or '\\sigma'
450450
451451
*fontsize*: font size in points
452452
@@ -749,12 +749,12 @@ def _get_glyph(self, fontname, font_class, sym, fontsize, math=True):
749749
r'>' : [('cal', 'i'), ('ex', 'E')]
750750
}
751751

752-
for alias, target in [('\leftparen', '('),
753-
('\rightparent', ')'),
754-
('\leftbrace', '{'),
755-
('\rightbrace', '}'),
756-
('\leftbracket', '['),
757-
('\rightbracket', ']'),
752+
for alias, target in [(r'\leftparen', '('),
753+
(r'\rightparent', ')'),
754+
(r'\leftbrace', '{'),
755+
(r'\rightbrace', '}'),
756+
(r'\leftbracket', '['),
757+
(r'\rightbracket', ']'),
758758
(r'\{', '{'),
759759
(r'\}', '}'),
760760
(r'\[', '['),
@@ -1034,7 +1034,7 @@ def _map_virtual_font(self, fontname, font_class, uniindex):
10341034

10351035
_size_alternatives = {}
10361036
def get_sized_alternatives_for_symbol(self, fontname, sym):
1037-
fixes = {'\{': '{', '\}': '}', '\[': '[', '\]': ']'}
1037+
fixes = {'\\{': '{', '\\}': '}', '\\[': '[', '\\]': ']'}
10381038
sym = fixes.get(sym, sym)
10391039

10401040
alternatives = self._size_alternatives.get(sym)
@@ -2425,20 +2425,20 @@ def __init__(self):
24252425
Suppress(Literal(r"\sqrt"))
24262426
- ((Optional(p.lbracket + p.int_literal + p.rbracket, default=None)
24272427
+ p.required_group)
2428-
| Error("Expected \sqrt{value}"))
2428+
| Error("Expected \\sqrt{value}"))
24292429
)
24302430

24312431
p.overline <<= Group(
24322432
Suppress(Literal(r"\overline"))
2433-
- (p.required_group | Error("Expected \overline{value}"))
2433+
- (p.required_group | Error("Expected \\overline{value}"))
24342434
)
24352435

24362436
p.unknown_symbol<<= Combine(p.bslash + Regex("[A-Za-z]*"))
24372437

24382438
p.operatorname <<= Group(
24392439
Suppress(Literal(r"\operatorname"))
24402440
- ((p.lbrace + ZeroOrMore(p.simple | p.unknown_symbol) + p.rbrace)
2441-
| Error("Expected \operatorname{value}"))
2441+
| Error("Expected \\operatorname{value}"))
24422442
)
24432443

24442444
p.placeable <<= ( p.snowflake # this needs to be before accent so named symbols
@@ -2693,7 +2693,7 @@ def unknown_symbol(self, s, loc, toks):
26932693
# The first 2 entires in the tuple are (font, char, sizescale) for
26942694
# the two symbols under and over. The third element is the space
26952695
# (in multiples of underline height)
2696-
r'AA' : ( ('it', 'A', 1.0), (None, '\circ', 0.5), 0.0),
2696+
r'AA': (('it', 'A', 1.0), (None, '\\circ', 0.5), 0.0),
26972697
}
26982698

26992699
def c_over_c(self, s, loc, toks):
@@ -2918,7 +2918,7 @@ def subsuper(self, s, loc, toks):
29182918
if super is None:
29192919
super = Hlist([])
29202920
for i in range(napostrophes):
2921-
super.children.extend(self.symbol(s, loc, ['\prime']))
2921+
super.children.extend(self.symbol(s, loc, ['\\prime']))
29222922
# kern() and hpack() needed to get the metrics right after extending
29232923
super.kern()
29242924
super.hpack()
@@ -3291,7 +3291,7 @@ def parse(self, s, dpi = 72, prop = None):
32913291
def to_mask(self, texstr, dpi=120, fontsize=14):
32923292
"""
32933293
*texstr*
3294-
A valid mathtext string, e.g., r'IQ: $\sigma_i=15$'
3294+
A valid mathtext string, e.g., r'IQ: $\\sigma_i=15$'
32953295
32963296
*dpi*
32973297
The dots-per-inch to render the text
@@ -3317,7 +3317,7 @@ def to_mask(self, texstr, dpi=120, fontsize=14):
33173317
def to_rgba(self, texstr, color='black', dpi=120, fontsize=14):
33183318
"""
33193319
*texstr*
3320-
A valid mathtext string, e.g., r'IQ: $\sigma_i=15$'
3320+
A valid mathtext string, e.g., r'IQ: $\\sigma_i=15$'
33213321
33223322
*color*
33233323
Any matplotlib color argument
@@ -3357,7 +3357,7 @@ def to_png(self, filename, texstr, color='black', dpi=120, fontsize=14):
33573357
A writable filename or fileobject
33583358
33593359
*texstr*
3360-
A valid mathtext string, e.g., r'IQ: $\sigma_i=15$'
3360+
A valid mathtext string, e.g., r'IQ: $\\sigma_i=15$'
33613361
33623362
*color*
33633363
A valid matplotlib color argument
@@ -3381,7 +3381,7 @@ def get_depth(self, texstr, dpi=120, fontsize=14):
33813381
image in pixels.
33823382
33833383
*texstr*
3384-
A valid mathtext string, e.g., r'IQ: $\sigma_i=15$'
3384+
A valid mathtext string, e.g., r'IQ: $\\sigma_i=15$'
33853385
33863386
*dpi*
33873387
The dots-per-inch to render the text

lib/matplotlib/mlab.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2191,7 +2191,7 @@ def identity(n, rank=2, dtype='l', typecode=None):
21912191
21922192
/ 1 if i0=i1=...=iR,
21932193
id[i0,i1,...,iR] = -|
2194-
\ 0 otherwise.
2194+
\\ 0 otherwise.
21952195
21962196
Optionally a *dtype* (or typecode) may be given (it defaults to 'l').
21972197
@@ -2869,7 +2869,7 @@ def get_converters(reader, comments):
28692869
break
28702870

28712871
# remove these chars
2872-
delete = set("""~!@#$%^&*()-=+~\|]}[{';: /?.>,<""")
2872+
delete = set(r"""~!@#$%^&*()-=+~\|]}[{';: /?.>,<""")
28732873
delete.add('"')
28742874

28752875
names = []

lib/matplotlib/patches.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ def set_hatch(self, hatch):
487487
*hatch* can be one of::
488488
489489
/ - diagonal hatching
490-
\ - back diagonal
490+
\\ - back diagonal
491491
| - vertical
492492
- - horizontal
493493
+ - crossed

0 commit comments

Comments
 (0)