-
-
Notifications
You must be signed in to change notification settings - Fork 529
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add custom callback exception callable
- Loading branch information
Showing
4 changed files
with
101 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from param import Parameter | ||
|
||
|
||
class CallbackException(Parameter): | ||
""" | ||
A Parameter type to validate callback_exception options. Supports | ||
"raise", "summary", "verbose", "traceback", "ignore", or a callable. | ||
""" | ||
|
||
def __init__(self, default="summary", **params): | ||
super().__init__(default=default, **params) | ||
self._validate(default) | ||
|
||
def _validate(self, val): | ||
self._validate_value(val, self.allow_None) | ||
|
||
def _validate_value(self, val, allow_None, valid=("raise", "summary", "verbose", "traceback", "ignore")): | ||
if ((val is None and allow_None) or val in valid or callable(val)): | ||
return | ||
raise ValueError( | ||
f"Callback exception mode {val} not recognized. " | ||
f"Valid options are {valid} or a callable." | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters