Skip to content

Commit b9065f7

Browse files
authored
Merge pull request #21570 from QuLogic/spine-getattr
Raise correct exception out of Spines.__getattr__
2 parents 162c073 + a1d8b56 commit b9065f7

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

lib/matplotlib/spines.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ def __getattr__(self, name):
550550
try:
551551
return self._dict[name]
552552
except KeyError:
553-
raise ValueError(
553+
raise AttributeError(
554554
f"'Spines' object does not contain a '{name}' spine")
555555

556556
def __getitem__(self, key):

lib/matplotlib/tests/test_spines.py

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ def set_val(self, val):
3535
spines[:].set_val('y')
3636
assert all(spine.val == 'y' for spine in spines.values())
3737

38+
with pytest.raises(AttributeError, match='foo'):
39+
spines.foo
3840
with pytest.raises(KeyError, match='foo'):
3941
spines['foo']
4042
with pytest.raises(KeyError, match='foo, bar'):

0 commit comments

Comments
 (0)