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

Skip to content

Commit cf37d54

Browse files
committed
Simplified escape function to a single path
1 parent 6e02a3b commit cf37d54

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

lib/matplotlib/fontconfig_pattern.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from functools import lru_cache
1616
import re
17-
17+
import numpy as np
1818
from pyparsing import (Literal, ZeroOrMore, Optional, Regex, StringEnd,
1919
ParseException, Suppress)
2020

@@ -183,14 +183,11 @@ def _escape_val(val, escape_func):
183183
the input escape function to make the values into legal font config
184184
strings. The result is returned as a string.
185185
"""
186-
if isinstance(val, list):
187-
val = [escape_func(r'\\\1', str(x)) for x in val
188-
if x is not None]
189-
val = ','.join(val)
190-
else:
191-
val = escape_func(r'\\\1', str(val))
186+
if not np.iterable(val) or isinstance(val, str):
187+
val = [val]
192188

193-
return val
189+
return ','.join(escape_func(r'\\\1', str(x)) for x in val
190+
if x is not None)
194191

195192

196193
def generate_fontconfig_pattern(d):
@@ -208,6 +205,7 @@ def generate_fontconfig_pattern(d):
208205
# The other keys are added as key=value
209206
for key in ['style', 'variant', 'weight', 'stretch', 'file', 'size']:
210207
val = getattr(d, 'get_' + key)()
208+
# Don't use 'if not val' because 0 is a valid input.
211209
if val is not None and val != []:
212210
props.append(":%s=%s" % (key, _escape_val(val, value_escape)))
213211

0 commit comments

Comments
 (0)