Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8422dee

Browse filesBrowse files
committed
Prefer log.warning("%s", ...) to log.warning("%s" % ...).
This is suggested by the stdlib docs to avoid paying the cost of the formatting if the message doesn't actually get emitted. It's marginally shorter too, especially when ... is surrounded by parentheses.
1 parent 9332a06 commit 8422dee
Copy full SHA for 8422dee

File tree

Expand file treeCollapse file tree

8 files changed

+40
-43
lines changed
Filter options
Expand file treeCollapse file tree

8 files changed

+40
-43
lines changed

‎lib/matplotlib/__init__.py

Copy file name to clipboardExpand all lines: lib/matplotlib/__init__.py
+20-20Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ def checkdep_ps_distiller(s):
489489
flag = False
490490
_log.warning('matplotlibrc ps.usedistiller option can not be used '
491491
'unless ghostscript 9.0 or later is installed on your '
492-
'system')
492+
'system.')
493493

494494
if s == 'xpdf':
495495
pdftops_req = '3.0'
@@ -502,9 +502,9 @@ def checkdep_ps_distiller(s):
502502
pass
503503
else:
504504
flag = False
505-
_log.warning(('matplotlibrc ps.usedistiller can not be set to '
506-
'xpdf unless xpdf-%s or later is installed on '
507-
'your system') % pdftops_req)
505+
_log.warning('matplotlibrc ps.usedistiller can not be set to xpdf '
506+
'unless xpdf-%s or later is installed on your '
507+
'system.', pdftops_req)
508508

509509
if flag:
510510
return s
@@ -523,21 +523,21 @@ def checkdep_usetex(s):
523523
if shutil.which("tex") is None:
524524
flag = False
525525
_log.warning('matplotlibrc text.usetex option can not be used unless '
526-
'TeX is installed on your system')
526+
'TeX is installed on your system.')
527527

528528
dvipng_v = checkdep_dvipng()
529529
if not compare_versions(dvipng_v, dvipng_req):
530530
flag = False
531531
_log.warning('matplotlibrc text.usetex can not be used with *Agg '
532532
'backend unless dvipng-%s or later is installed on '
533-
'your system' % dvipng_req)
533+
'your system.', dvipng_req)
534534

535535
gs_exec, gs_v = checkdep_ghostscript()
536536
if not compare_versions(gs_v, gs_req):
537537
flag = False
538538
_log.warning('matplotlibrc text.usetex can not be used unless '
539-
'ghostscript-%s or later is installed on your system'
540-
% gs_req)
539+
'ghostscript-%s or later is installed on your system.',
540+
gs_req)
541541

542542
return flag
543543

@@ -963,21 +963,21 @@ def _rc_params_in_file(fname, fail_on_error=False):
963963
tup = strippedline.split(':', 1)
964964
if len(tup) != 2:
965965
error_details = _error_details_fmt % (cnt, line, fname)
966-
_log.warning('Illegal %s' % error_details)
966+
_log.warning('Illegal %s', error_details)
967967
continue
968968
key, val = tup
969969
key = key.strip()
970970
val = val.strip()
971971
if key in rc_temp:
972-
_log.warning('Duplicate key in file "%s", line #%d' %
973-
(fname, cnt))
972+
_log.warning('Duplicate key in file %r line #%d.',
973+
fname, cnt)
974974
rc_temp[key] = (val, line, cnt)
975975
except UnicodeDecodeError:
976-
_log.warning(
977-
('Cannot decode configuration file %s with '
978-
'encoding %s, check LANG and LC_* variables')
979-
% (fname, locale.getpreferredencoding(do_setlocale=False) or
980-
'utf-8 (default)'))
976+
_log.warning('Cannot decode configuration file %s with encoding '
977+
'%s, check LANG and LC_* variables.',
978+
fname,
979+
locale.getpreferredencoding(do_setlocale=False)
980+
or 'utf-8 (default)')
981981
raise
982982

983983
config = RcParams()
@@ -992,8 +992,8 @@ def _rc_params_in_file(fname, fail_on_error=False):
992992
config[key] = val # try to convert to proper type or skip
993993
except Exception as msg:
994994
error_details = _error_details_fmt % (cnt, line, fname)
995-
_log.warning('Bad val "%s" on %s\n\t%s' %
996-
(val, error_details, msg))
995+
_log.warning('Bad val %r on %s\n\t%s',
996+
val, error_details, msg)
997997

998998
for key, (val, line, cnt) in rc_temp.items():
999999
if key in defaultParams:
@@ -1004,8 +1004,8 @@ def _rc_params_in_file(fname, fail_on_error=False):
10041004
config[key] = val # try to convert to proper type or skip
10051005
except Exception as msg:
10061006
error_details = _error_details_fmt % (cnt, line, fname)
1007-
_log.warning('Bad val "%s" on %s\n\t%s' %
1008-
(val, error_details, msg))
1007+
_log.warning('Bad val %r on %s\n\t%s',
1008+
val, error_details, msg)
10091009
elif key in _deprecated_ignore_map:
10101010
version, alt_key = _deprecated_ignore_map[key]
10111011
cbook.warn_deprecated(

‎lib/matplotlib/artist.py

Copy file name to clipboardExpand all lines: lib/matplotlib/artist.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ def contains(self, mouseevent):
403403
"""
404404
if callable(self._contains):
405405
return self._contains(self, mouseevent)
406-
_log.warning("'%s' needs 'contains' method" % self.__class__.__name__)
406+
_log.warning("%r needs 'contains' method", self.__class__.__name__)
407407
return False, {}
408408

409409
def set_contains(self, picker):

‎lib/matplotlib/backends/backend_wx.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_wx.py
+6-8Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,10 +1575,9 @@ def save_figure(self, *args):
15751575
if ext in ('svg', 'pdf', 'ps', 'eps', 'png') and format != ext:
15761576
# looks like they forgot to set the image type drop
15771577
# down, going with the extension.
1578-
_log.warning(
1579-
'extension %s did not match the selected '
1580-
'image type %s; going with %s' %
1581-
(ext, format, ext))
1578+
_log.warning('extension %s did not match the selected '
1579+
'image type %s; going with %s',
1580+
ext, format, ext)
15821581
format = ext
15831582
try:
15841583
self.canvas.figure.savefig(
@@ -1839,10 +1838,9 @@ def trigger(self, *args):
18391838
if ext in ('svg', 'pdf', 'ps', 'eps', 'png') and format != ext:
18401839
# looks like they forgot to set the image type drop
18411840
# down, going with the extension.
1842-
_log.warning(
1843-
'extension %s did not match the selected '
1844-
'image type %s; going with %s' %
1845-
(ext, format, ext))
1841+
_log.warning('extension %s did not match the selected '
1842+
'image type %s; going with %s',
1843+
ext, format, ext)
18461844
format = ext
18471845
if default_dir != "":
18481846
matplotlib.rcParams['savefig.directory'] = dirname

‎lib/matplotlib/backends/qt_editor/formlayout.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/qt_editor/formlayout.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,8 @@ def setup(self):
266266
selindex = keys.index(selindex)
267267
elif not isinstance(selindex, Integral):
268268
_log.warning(
269-
"index '%s' is invalid (label: %s, value: %s)" %
270-
(selindex, label, value))
269+
"index '%s' is invalid (label: %s, value: %s)",
270+
selindex, label, value)
271271
selindex = 0
272272
field.setCurrentIndex(selindex)
273273
elif isinstance(value, bool):

‎lib/matplotlib/font_manager.py

Copy file name to clipboardExpand all lines: lib/matplotlib/font_manager.py
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,16 +1216,16 @@ def _findfont_cached(self, prop, fontext, directory, fallback_to_default,
12161216
if best_font is None or best_score >= 10.0:
12171217
if fallback_to_default:
12181218
_log.warning(
1219-
'findfont: Font family %s not found. Falling back to %s.' %
1220-
(prop.get_family(), self.defaultFamily[fontext]))
1219+
'findfont: Font family %s not found. Falling back to %s.',
1220+
prop.get_family(), self.defaultFamily[fontext])
12211221
default_prop = prop.copy()
12221222
default_prop.set_family(self.defaultFamily[fontext])
12231223
return self.findfont(default_prop, fontext, directory, False)
12241224
else:
12251225
# This is a hard fail -- we can't find anything reasonable,
12261226
# so just return the DejuVuSans.ttf
1227-
_log.warning('findfont: Could not match %s. Returning %s.' %
1228-
(prop, self.defaultFont[fontext]))
1227+
_log.warning('findfont: Could not match %s. Returning %s.',
1228+
prop, self.defaultFont[fontext])
12291229
result = self.defaultFont[fontext]
12301230
else:
12311231
_log.debug('findfont: Matching %s to %s (%r) with score of %f.',

‎lib/matplotlib/mathtext.py

Copy file name to clipboardExpand all lines: lib/matplotlib/mathtext.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,8 +1591,8 @@ def _set_glue(self, x, sign, totals, error_type):
15911591
self.glue_ratio = 0.
15921592
if o == 0:
15931593
if len(self.children):
1594-
_log.warning(
1595-
"%s %s: %r" % (error_type, self.__class__.__name__, self))
1594+
_log.warning("%s %s: %r",
1595+
error_type, self.__class__.__name__, self)
15961596

15971597
def shrink(self):
15981598
for child in self.children:

‎lib/matplotlib/sankey.py

Copy file name to clipboardExpand all lines: lib/matplotlib/sankey.py
+3-4Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -518,10 +518,9 @@ def add(self, patchlabel='', flows=None, orientations=None, labels='',
518518
are_inputs[i] = False
519519
else:
520520
_log.info(
521-
"The magnitude of flow %d (%f) is below the "
522-
"tolerance (%f).\nIt will not be shown, and it "
523-
"cannot be used in a connection."
524-
% (i, flow, self.tolerance))
521+
"The magnitude of flow %d (%f) is below the tolerance "
522+
"(%f).\nIt will not be shown, and it cannot be used in a "
523+
"connection.", i, flow, self.tolerance)
525524

526525
# Determine the angles of the arrows (before rotation).
527526
angles = [None] * n

‎lib/matplotlib/textpath.py

Copy file name to clipboardExpand all lines: lib/matplotlib/textpath.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ def get_glyphs_tex(self, prop, s, glyph_map=None,
347347
else:
348348
_log.warning("The glyph (%d) of font (%s) cannot be "
349349
"converted with the encoding. Glyph may "
350-
"be wrong" % (glyph, font.fname))
350+
"be wrong.", glyph, font.fname)
351351

352352
glyph0 = font.load_char(glyph, flags=ft2font_flag)
353353

@@ -394,7 +394,7 @@ def _get_ps_font_and_encoding(texname):
394394
break
395395
else:
396396
charmap_name = ""
397-
_log.warning("No supported encoding in font (%s)." %
397+
_log.warning("No supported encoding in font (%s).",
398398
font_bunch.filename)
399399

400400
if charmap_name == "ADOBE_STANDARD" and font_bunch.encoding:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.