dblume commited on 2025-11-13 23:36:14
Showing 1 changed files, with 14 additions and 0 deletions.
| ... | ... |
@@ -9,6 +9,7 @@ import sitesize.sitesize |
| 9 | 9 |
from typing import Callable |
| 10 | 10 |
from decorators import timeit, profile |
| 11 | 11 |
from pathlib import Path |
| 12 |
+import traceback |
|
| 12 | 13 |
try: |
| 13 | 14 |
import marshmallow |
| 14 | 15 |
marshmallow_imported = True |
| ... | ... |
@@ -35,6 +36,19 @@ def set_v_print(verbose: bool) -> None: |
| 35 | 36 |
v_print = print if verbose else lambda *a, **k: None |
| 36 | 37 |
|
| 37 | 38 |
|
| 39 |
+def filenum_excepthook(exc_type, exc_value, tb): |
|
| 40 |
+ """Print errors as: |
|
| 41 |
+ File path/file.py:## |
|
| 42 |
+ not: |
|
| 43 |
+ File path/file.py, line ##""" |
|
| 44 |
+ for line in traceback.format_exception(exc_type, exc_value, tb): |
|
| 45 |
+ if line.startswith(' File'):
|
|
| 46 |
+ print(line.replace(', line ', ':').rstrip(), file=sys.stderr)
|
|
| 47 |
+ else: |
|
| 48 |
+ print(line, end='', file=sys.stderr) |
|
| 49 |
+ |
|
| 50 |
+sys.excepthook = filenum_excepthook |
|
| 51 |
+ |
|
| 38 | 52 |
# This class demonstrates decorators. |
| 39 | 53 |
# |
| 40 | 54 |
# Consider these alternatives for data classes: |
| 41 | 55 |