8000 Raise correct exception out of Spines.__getattr__ · QuLogic/matplotlib@a1d8b56 · GitHub
[go: up one dir, main page]

Skip to content

Commit a1d8b56

Browse files
committed
Raise correct exception out of Spines.__getattr__
If the name does not exist, then `__getattr__` should raise `AttributeError`, not `ValueError`. Fixes matplotlib#21554
1 parent f0632c0 commit a1d8b56

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

lib/matplotlib/spines.py

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 0 deletions
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)
0