|
1 | 1 | # AUTOGENERATED! DO NOT EDIT! File to edit: nbs/03_xtras.ipynb (unless otherwise specified).
|
2 | 2 |
|
| 3 | + |
| 4 | +from __future__ import annotations |
| 5 | + |
| 6 | + |
3 | 7 | __all__ = ['dict2obj', 'obj2dict', 'repr_dict', 'is_listy', 'shufflish', 'mapped', 'IterLen', 'ReindexCollection',
|
4 | 8 | 'walk', 'globtastic', 'maybe_open', 'image_size', 'bunzip', 'join_path_file', 'loads', 'loads_multi',
|
5 | 9 | 'untar_dir', 'repo_details', 'run', 'open_file', 'save_pickle', 'load_pickle', 'get_source_link', 'truncstr',
|
6 | 10 | 'spark_chars', 'sparkline', 'autostart', 'EventTimer', 'stringfmt_names', 'PartialFormatter',
|
7 |
| - 'partial_format', 'utc2local', 'local2utc', 'trace', 'round_multiple', 'modified_env', 'ContextManagers', |
8 |
| - 'str2bool'] |
| 11 | + 'partial_format', 'utc2local', 'local2utc', 'trace', 'modify_exception', 'round_multiple', 'modified_env', |
| 12 | + 'ContextManagers', 'str2bool'] |
| 13 | + |
| 14 | +# Cell |
| 15 | +#nbdev_comment from __future__ import annotations |
9 | 16 |
|
10 | 17 | # Cell
|
11 | 18 | from .imports import *
|
@@ -467,6 +474,16 @@ def _inner(*args,**kwargs):
|
467 | 474 | _inner._traced = True
|
468 | 475 | return _inner
|
469 | 476 |
|
| 477 | +# Cell |
| 478 | +def modify_exception( |
| 479 | + e:Exception, # An exception |
| 480 | + msg:str=None, # A custom message |
| 481 | + replace:bool=False, # Whether to replace e.args with [msg] |
| 482 | +) -> Exception: |
| 483 | + "Modifies `e` with a custom message attached" |
| 484 | + e.args = [f'{e.args[0]} {msg}'] if not replace and len(e.args) > 0 else [msg] |
| 485 | + return e |
| 486 | + |
470 | 487 | # Cell
|
471 | 488 | def round_multiple(x, mult, round_down=False):
|
472 | 489 | "Round `x` to nearest multiple of `mult`"
|
|
0 commit comments