diff --git a/lib/matplotlib/axis.py b/lib/matplotlib/axis.py index 223eb5e7a34f..9a47eb1169ca 100644 --- a/lib/matplotlib/axis.py +++ b/lib/matplotlib/axis.py @@ -2227,11 +2227,10 @@ def set_ticklabels(self, labels, *, minor=False, fontdict=None, **kwargs): labels = [t.get_text() if hasattr(t, 'get_text') else t for t in labels] except TypeError: - raise TypeError(f"{labels:=} must be a sequence") from None + raise TypeError(f"{labels=!r} must be a sequence") from None locator = (self.get_minor_locator() if minor else self.get_major_locator()) if not labels: - # eg labels=[]: formatter = mticker.NullFormatter() elif (isinstance(locator, mticker.FixedLocator) or (hasattr(locator, 'base') and diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 43babac20897..eedd803a3914 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -7032,6 +7032,8 @@ def test_xticks_bad_args(): ax = plt.figure().add_subplot() with pytest.raises(TypeError, match='must be a sequence'): ax.set_xticks([2, 9], 3.1) + with pytest.raises(TypeError, match='must be a sequence'): + ax.set_xticks([2, 9], ax) with pytest.raises(ValueError, match='must be 1D'): plt.xticks(np.arange(4).reshape((-1, 1))) with pytest.raises(ValueError, match='must be 1D'):