8000 more @anntzer suggestions · matplotlib/matplotlib@90d0549 · GitHub
[go: up one dir, main page]

Skip to content

Commit 90d0549

Browse files
committed
more @anntzer suggestions
1 parent 26b9583 commit 90d0549

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

lib/matplotlib/tests/test_ticker.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,6 @@ class TestFuncFormatter:
10511051
("format 2 inputs",
10521052
("{}+{}!".format, [2, 3], "2+3!"))]
10531053
ids, data = zip(*tests)
1054-
10551054
@pytest.mark.parametrize("func, args, expected", data, ids=ids)
10561055
def test_arguments(self, func, args, expected):
10571056
assert expected == mticker.FuncFormatter(func)(*args)

lib/matplotlib/ticker.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@
171171
import math
172172
import string
173173
import types
174-
import warnings
175174
from numbers import Integral
176175

177176
import numpy as np
@@ -386,25 +385,23 @@ class FuncFormatter(Formatter):
386385
the corresponding tick label.
387386
"""
388387
def __init__(self, func):
388+
self.func = func
389+
389390
if not isinstance(func, types.BuiltinFunctionType):
390-
nargs = len(inspect.signature(func).parameters)
391-
elif (func.__name__ == 'format'):
391+
self.nargs = len(inspect.signature(func).parameters)
392+
elif (isinstance(getattr(func, "__self__"), str) and
393+
(getattr(func, "__name__", "") == "format")):
392394
#check if there's a format spec
393-
nargs = len([(_, _, fs, _) for (_, _, fs, _)
394-
in string.Formatter().parse(func.__self__)
395-
if fs is not None])
395+
self.nargs = len([(_, _, fs, _) for (_, _, fs, _)
396+
in string.Formatter().parse(func.__self__)
397+
if fs is not None])
396398
else:
397399
#finding argcount for other builtins is a mess
398-
nargs = 2
399-
raise warnings.warn(f"{func.__name__} is not supported "
400-
"and may not work as expected")
401-
402-
if nargs == 1:
403-
self.func = lambda x, pos: func(x)
404-
elif nargs == 2:
405-
self.func = func
406-
else:
407-
raise TypeError(f"{func.__name__} takes {nargs} arguments. "
400+
self.nargs = 2
401+
cbook._warn_external(f"{func.__name__} is not supported "
402+
"and may not work as expected")
403+
if self.nargs not in [1, 2]:
404+
raise TypeError(f"{func.__name__} takes {self.nargs} arguments. "
408405
"FuncFormatter functions take at most 2: "
409406
"x (required), pos (optional).")
410407

@@ -414,6 +411,7 @@ def __call__(self, x, pos=None):
414411
415412
*x* and *pos* are passed through as-is.
416413
"""
414+
if self.nargs == 1: return self.func(x)
417415
return self.func(x, pos)
418416

419417

0 commit comments

Comments
 (0)
0