Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a05b084

Browse files
committed
Add more explicit error message for [r,theta]grids
mypy was unhappy because the first parameter in each case (angles/radii) is optional for the pyplot wrapper but required for the set_[r,theta]grids axes methods. The variable is optional because the pyplot version acts as both the getter and the setter, but the type is not sufficiently narrowed for mypy. If passed None, the underlying setters would error, though deeper in the stack either in numpy or upon setting ticks. Just be a bit more explicit and fail early with a targetted error message
1 parent 73a73f9 commit a05b084

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

lib/matplotlib/pyplot.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2117,6 +2117,8 @@ def rgrids(
21172117
if all(p is None for p in [radii, labels, angle, fmt]) and not kwargs:
21182118
lines_out: list[Line2D] = ax.yaxis.get_gridlines()
21192119
labels_out: list[Text] = ax.yaxis.get_ticklabels()
2120+
elif radii is None:
2121+
raise TypeError("'radii' cannot be None when other parameters are passed")
21202122
else:
21212123
lines_out, labels_out = ax.set_rgrids(
21222124
radii, labels=labels, angle=angle, fmt=fmt, **kwargs)
@@ -2190,6 +2192,8 @@ def thetagrids(
21902192
if all(param is None for param in [angles, labels, fmt]) and not kwargs:
21912193
lines_out: list[Line2D] = ax.xaxis.get_ticklines()
21922194
labels_out: list[Text] = ax.xaxis.get_ticklabels()
2195+
elif angles is None:
2196+
raise TypeError("'angles' cannot be None when other parameters are passed")
21932197
else:
21942198
lines_out, labels_out = ax.set_thetagrids(angles,
21952199
labels=labels, fmt=fmt,

0 commit comments

Comments
 (0)