-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add helper function to check that an argument is in a list of strings. #12232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Changed exceptions | ||
`````````````````` | ||
|
||
- `mpl_toolkits.axes_grid1.axes_size.GetExtentHelper` now raises `ValueError` | ||
for invalid directions instead of `KeyError`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1083,8 +1083,7 @@ def set_drawstyle(self, drawstyle): | |
""" | ||
if drawstyle is None: | ||
drawstyle = 'default' | ||
if drawstyle not in self.drawStyles: | ||
raise ValueError('Unrecognized drawstyle {!r}'.format(drawstyle)) | ||
cbook._check_in_list(self.drawStyles, drawstyle=drawstyle) | ||
if self._drawstyle != drawstyle: | ||
self.stale = True | ||
# invalidate to trigger a recache of the path | ||
|
@@ -1181,13 +1180,9 @@ def set_linestyle(self, ls): | |
if ls in [' ', '', 'none']: | ||
ls = 'None' | ||
|
||
cbook._check_in_list([*self._lineStyles, *ls_mapper_r], ls=ls) | ||
if ls not in self._lineStyles: | ||
try: | ||
ls = ls_mapper_r[ls] | ||
except KeyError: | ||
raise ValueError("Invalid linestyle {!r}; see docs of " | ||
"Line2D.set_linestyle for valid values" | ||
.format(ls)) | ||
ls = ls_mapper_r[ls] | ||
self._linestyle = ls | ||
else: | ||
self._linestyle = '--' | ||
|
@@ -1362,9 +1357,7 @@ def set_dash_joinstyle(self, s): | |
For examples see :doc:`/gallery/lines_bars_and_markers/joinstyle`. | ||
""" | ||
s = s.lower() | ||
if s not in self.validJoin: | ||
raise ValueError('set_dash_joinstyle passed "%s";\n' % (s,) | ||
+ 'valid joinstyles are %s' % (self.validJoin,)) | ||
cbook._check_in_list(self.validJoin, s=s) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In cases below you don't use the parameter name but the function name, e.g.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I decided to always go with the parameter name. (Neither solution is always great, but heh, you can see the function name in the traceback anyways.) |
||
if self._dashjoinstyle != s: | ||
self.stale = True | ||
self._dashjoinstyle = s | ||
|
@@ -1379,10 +1372,7 @@ def set_solid_joinstyle(self, s): | |
For examples see :doc:`/gallery/lines_bars_and_markers/joinstyle`. | ||
""" | ||
s = s.lower() | ||
if s not in self.validJoin: | ||
raise ValueError('set_solid_joinstyle passed "%s";\n' % (s,) | ||
+ 'valid joinstyles are %s' % (self.validJoin,)) | ||
|
||
cbook._check_in_list(self.validJoin, s=s) | ||
if self._solidjoinstyle != s: | ||
self.stale = True | ||
self._solidjoinstyle = s | ||
|
@@ -1412,9 +1402,7 @@ def set_dash_capstyle(self, s): | |
s : {'butt', 'round', 'projecting'} | ||
""" | ||
s = s.lower() | ||
if s not in self.validCap: | ||
raise ValueError('set_dash_capstyle passed "%s";\n' % (s,) | ||
+ 'valid capstyles are %s' % (self.validCap,)) | ||
cbook._check_in_list(self.validCap, s=s) | ||
if self._dashcapstyle != s: | ||
self.stale = True | ||
self._dashcapstyle = s | ||
|
@@ -1428,9 +1416,7 @@ def set_solid_capstyle(self, s): | |
s : {'butt', 'round', 'projecting'} | ||
""" | ||
s = s.lower() | ||
if s not in self.validCap: | ||
raise ValueError('set_solid_capstyle passed "%s";\n' % (s,) | ||
+ 'valid capstyles are %s' % (self.validCap,)) | ||
cbook._check_in_list(self.validCap, s=s) | ||
if self._solidcapstyle != s: | ||
self.stale = True | ||
self._solidcapstyle = s | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though this is just internal, I would like an explanatory example in the docstring because the kwarg usage is a bit special. Maybe even with a note that you'll usually do
_check_in_list(values, param=param)
.